Algorithm Interview Questions
- -1of 1 vote
AnswersGiven a circular array of images, in LandScape and Portrait mode. Bidirectional movement in array is allowed.
- rajnikant12345 March 13, 2016 in India for Office
e.g.
LPPPLPPP
L-> Landscape
P-> Portrait
Cost of Viewing a Portrait image is Vp
Cost of Viewing a Landscape is (Rp(rotate) + Vp).
Cost of movement is -> m
once you visited the image viewing cost is zero if you revisit the image. Only movement cost is considered.
Jumps in array is not allowed.
Calculate the maximum number of images you can see with cost X.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 1of 1 vote
Answerswhat is the best sorting algorithm in terms of complexity and why?
- Rajesh Burla March 11, 2016 in India| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersGiven a series of number form a binary tree find the minimum weight binary tree. The weight of the node is depth * value of the element + weight of the left tree + weight of the right tree.
- neer.1304 March 11, 2016 in United States
Weight of the root node is the weight of the tree . Find the minimum weight binary tree out of all possible binary trees that are possible.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswerWhat is the best way to merge unsorted list and generate a single sorted list ?
- shin.subash March 10, 2016 in United States
I was giving an option of inserting into Binary tree from both list and retrieve it.what is the best solution| Report Duplicate | Flag | PURGE
Digital Insight Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersDesign an Algorithm for Amazon Advertisement Page
- suneel March 10, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -1of 1 vote
Answershttps://gist.github.com/acegreen/e16a2259a93dab880a7f
- aelalfy1989 March 09, 2016 in United States| Report Duplicate | Flag | PURGE
Groupon iOS Developer Algorithm - 0of 0 votes
Answershttps://gist.github.com/acegreen/1a9a63f27729278b0fa5
- aelalfy1989 March 09, 2016 in United States| Report Duplicate | Flag | PURGE
Groupon iOS Developer Algorithm - 0of 0 votes
AnswersGiven n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of values on each face when all the dice are thrown. 4+3 and 3+4 should be treated same. dont consider different permutations.
- nodustollens22 March 08, 2016 in United States| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven an arbitrary tree starting at “root” where each node contains a pair of values (x, y), write a boolean function find(Node root, int x, int y) that returns true iff
- Basu March 08, 2016 in United States
* x is equal to a value "x" of any node n1 in the tree
* and y is equal to a value "y" of any node n2 in the tree
* and both n1 and n2 are at the same level in the tree
boolean find(Node root, int x, int y)
Example:
(1,120)
/ | \
/ | \
/ | \
(5,15) (30,70) (80,110)
/ | \ |
/ | \ |
/ | \ |
(35, 40) (45,50) (55, 65) (90, 100)
boo == true
find(root, 45, 100) == true
find(root, 30, 100) == false
find(root, 30, 70) == true
find(root, 70, 30) == false| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersThere is a Deployment Window of fixed time T. There are multiple patches (independent of each other),
- LateRunner March 07, 2016 in India
that are to be deployed in the fixed time T. Find solution to deploy patches such that maximum time is
utilized in the window.
Test Case 1:
Input:
Window Size 4, List of Patches: [1,1,1,2,3]
Output:
[3,1] or [1,1,2]
Test Case 2:
Input:
Window Size 5, List of Patches: [1,2,3,6]
Output:
[2, 3]| Report Duplicate | Flag | PURGE
Computer Associates Principal Software Engineer Algorithm - 1of 1 vote
AnswersGiven a million list of co-ordinates in the form of longitude and latitude just as Google maps .How will you print closest k cities to a given location .
- neer.1304 March 06, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersThis was the 2nd round. Face to face. DS and Algo
- uday4friendz March 04, 2016 in India for Product Details Page
Q1) Given an array 'A' of size 'n' and a number 'm' such that 'm <= n'. For all subsets of 'A' of size 'm', return the difference between the number of non-increasing and non-decreasing sub-sequences.
He asked me to write the program on paper in any language.
This is how i approached it.
1) First i gave the brute force solution and explained it to him. He liked it.
2) Then he asked for the complexity of the solution. I gave right ans.
3) Then i told him that it can be optimized by 'xyz' approach.
4) Then he asked me if i can write the solution. I said i will first explain him how it can be solved. Then if he wants me to write the code, he will have to leave me alone for some time. He agreed. I explained.
5) There was a bug in my solution. He gave a test case that exposed it. Then i rectified the bug. He accepted.
6) He said that it. He does not need the full code.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersYou are given an array of variable length, which contains only following integers: -1, 0, 1.
- kishoredbn March 01, 2016 in United States
Example A[] = {0, 1, 0, 1, 1, -1, 1}
You are also given an integer S.
Write a program with O(n) time that can find out the length of the largest sub-array which sums up to S.
Example, if S = 2, then the length of the largest sub-array in the above array is 6.
If there is no such sub-array that can sum up to S, then output 0.| Report Duplicate | Flag | PURGE
Galatea Associates Software Developer Algorithm - 1of 1 vote
AnswersGiven a 2D matrix of integers, sort it such that:
- every row is sorted in ascending order from left to right
- every column is sorted in ascending order from top to down
- all items in the same row are unique
You may assume the input matrix is always valid, meaning that such a sort is always possible.
For example:
for input matrix1 3 5 3 2 4
the output could be any of the following:
valid output #1:1 3 4 2 3 5
valid output #2:
1 2 3 3 4 5
valid output #3:
1 3 4 2 3 5
One kinda trivial solution is to sort the 2D matrix column wise. For example, you can push all items into a heap and pop one after another, putting it into the matrix column after column. This would be a `O(n lg n)` time complexity where `n` is the number of items in the matrix, i.e., `n = rows*cols`. Can you design a more efficient algorithm?
- zhtt2009 February 29, 2016 in United States
Follow-up: What if all items in the same column are also required to be unique?| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven a series of parenthesis and bracket with the possible pairs of (), {}, [], write a method that will return true if the series is balanced, and false otherwise.
- Octavio Licea February 28, 2016 in United States
for example i.e.
"()" => true
"({})" => true
"([]()){}" => true
"([)]{}" => false, the square bracket '[' does not have a matching closing bracket ']'| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven a matrix of ‘O’ and ‘X’, find the largest sub rectangle surrounded by ‘X’
- vinay February 26, 2016 in United States
Example :
XXXXX
X0X0X
XXXXX
XXXXX
Output : largest rectangle size is 4 x 5| Report Duplicate | Flag | PURGE
unknown Developer Program Engineer Algorithm - 0of 0 votes
AnswersGiven an array and a number, add it in such a way where array is [0,0,1] and number is 4 output will be [0,0,5]
- Ipalibo February 25, 2016 in United Kingdom
Example 2 :
array is [1] and number is 9 output will be [1,0]| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 2 votes
AnswersGiven N ropes of lengths L1, L2, L3, L4, …, LN. I had to join every rope to get a final rope of length L1 + L2 + … + LN.
- ash.taunk3 February 24, 2016 in India
However, I can join only two ropes at a time and the cost of joining the two ropes is L1 + L2. I was supposed to join ropes in such a way that the cost is minimum.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersTHERE ARE SEVERAL LOG FILES COMING BY DATE WITH PRODUCT IDS AND I NEED TO REPORT THE TOP 10 (PRODUCT IDS) DURING A MOVING PERIOD OF 1 MONTH. DISCUSSED ABOUT THE DATA STRUCTURES NEEDED TO IMPLEMENT THE SOLUTION.
- bhardwaj.cs February 23, 2016 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersSSUME YOU HAVE A LARGE FILE WITH LINES OF TIMESTAMPS AND IP ADDRESSES . TIMESTAMPS ARE ORDERED, BUT MAY REPEAT AND MAY SKIP. HOW DO YOU DETERMINE WHETHER
- bhardwaj.cs February 23, 2016 in United States
THERE IS A TIME WINDOW THAT HAS A CERTAIN IP ADDRESS APPEARING MORE THAN K TIMES? HOW WOULD YOU SOLVE THIS IF INSTEAD YOU RECEIVED A STREAM.| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer Algorithm - 2of 2 votes
Answers|X XX | | X X | | X | | |
X = land.
- HumbleLearner February 20, 2016 in United States
Empty space = Water.
Find the number of islands present. (Upto you how you want to represent land and water in the array above)
Answer for the above example: 3
I wish I could draw the diagram better!
Explanation: 3 because:
The three islands are:
X
X
X
XX
X| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern Algorithm - 1of 1 vote
AnswersGiven a string where in each word letters were randomly shuffled and after that words were written without spaces (lets call it X). Also you have a dictionary. The task is to return all possible strings S that can be transformed into the string X and all words in S are from dictionary.
- golyjivan February 19, 2016 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven a specific type of DAG that forms a pyramid (the links have up-down direction), in which the node labels are integer, find the path that has the maximum sum of node values. what is the time/space complexity of the algorithm?
- a.asudeh February 18, 2016 in United States
e.g:
3
/ \
9 4
/ \ / \
1 8 2
/ \ / \ / \
4 5 8 2
answer: <3,9,8,8>, sum = 3+9+8+8=28| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm - -2of 2 votes
AnswersInput
- mail.smohanty February 18, 2016 in India
2 5
2000
5000
Output
1000
Question: A real estate company plans to open relief distribution in few cities of a state.
The input in the first Line N(number of cities...2 as per example)
and M(Number of distribution center...5 as per example).
The next lines have the number of population in N(2) cities. (2000 and 5000) as per example.
Only people from a specific city can go to the distribution center of that city.
WAP to find the number of max people those can be accommodated in a distribution center.
The answer is 1000 in this case. As there are 7 distribution center.
First City having 2000 population will have 2 distribution center and second city having 5000 population will have 5 centers.
Therefore Max person that can be accommodated in a center is 1000.| Report Duplicate | Flag | PURGE
Hewlett Packard Dev Lead Algorithm - 0of 0 votes
AnswersCircular Queue - what it is ? and write a program for this
- its3707 February 18, 2016 in India| Report Duplicate | Flag | PURGE
Microsoft SDET Algorithm - 0of 0 votes
AnswersCircular Queue - what it is ? and write a program for this
- its3707 February 18, 2016 in India| Report Duplicate | Flag | PURGE
Microsoft SDET Algorithm - -2of 2 votes
AnswersI have an array of integer. That provides data to one of the UI screen. That UI screen can show at a time only one data. For each iteration on the array 3 elements get picked up however only the highest number out of those usually shows up on the UI.
- its3707 February 18, 2016 in India
{1,4,5,2,3,4,5,6} means if 1,4,5 picked up only 5 will be shown up on the UI
in next iteration 4,5,2, should be picked up.
next iteration 5,2,3
write a solution for this.| Report Duplicate | Flag | PURGE
Microsoft SDET Algorithm - -2of 2 votes
AnswersI have an array of integer. That provides data to one of the UI screen. That UI screen can show at a time only one data. For each iteration on the array 3 elements get picked up however only the highest number out of those usually shows up on the UI.
- its3707 February 18, 2016 in India
{1,4,5,2,3,4,5,6} means if 1,4,5 picked up only 5 will be shown up on the UI
in next iteration 4,5,2, should be picked up.
next iteration 5,2,3
write a solution for this.| Report Duplicate | Flag | PURGE
Microsoft SDET Algorithm - 0of 0 votes
AnswersAssume you have a function isAccountHacked(String username) This function is called by a system whenever a there is a failed login by a particular username.
- sathipkr February 18, 2016 in United States
The function returns true if there have been "n" consecutive unsuccessful login attempts in the last 1hr/36,000 seconds.How will you write this method.I was asked this question in an interview and I came up with few solutions of logging last n timestamps in 1 hr.
He wanted a solution with space complexity of timestamps less than O(n).Let me know if you need any more details| Report Duplicate | Flag | PURGE
SDE-3 Algorithm - 0of 0 votes
AnswersGiven a stream of numbers write a program that computes sum of pair of numbers. There should be two methods store and IsNumberPresent. The store should store the numbers and IsNumberPresent should check if the number is present in the computed sums.
- anonymous February 16, 2016 in India| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Algorithm