Algorithm Interview Questions
- 1of 1 vote
AnswersGiven a pattern and a string - find if the string follows the same pattern Eg: Pattern : [a b b a], String : cat dog dog cat
- AlgoBaba December 02, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a string and two words which are present in the string, find the minimum distance between the words
- testsync012345 October 23, 2015 in United States
Eg: "the brown qucik frog quick the", "the" "quick" O/P -> 1
"the quick the brown quick brown the frog", "the" "the" O/P -> 2| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm - 1of 1 vote
AnswersYou have a binary search tree and you have to return the two nodes such that there sum i equal to ‘K’. Pseudo code is to be given.
- tihor January 26, 2015 in India
O(n)time & O(n) sppace is easy but challenge O(n) time & O(1) space.| Report Duplicate | Flag | PURGE
Amazon Java Developer Algorithm - 1of 1 vote
Answerswrite a function to determine if two strings are anagrams? what is the run-time (big O) of this? Is there a better way to do this?
- sarahschwanbeck October 20, 2013 in United States for Y! Suite| Report Duplicate | Flag | PURGE
Yahoo Software Development Manager Algorithm - 1of 1 vote
AnswersGiven an mxn matrix, design a function that will print out the contents of the matrix in spiral format.
Spiral format means for a 5x5 matrix given below:[ 1 2 3 4 5 ] [ 6 7 8 9 0 ] [ 1 2 3 4 5 ] [ 6 7 8 9 0 ] [ 1 2 3 4 5 ] path taken is: [ > > > > > ] [ > > > > v ] [ ^ ^ > v v ] [ ^ ^ < < v ] [ < < < < < ] where ">" is going right, "v" going down, "<" is going left, "^" is going up.
The output is:
- masrur.macece June 26, 2013 in United States for Windows Hyper-V1 2 3 4 5 0 5 0 5 4 3 2 1 6 1 6 7 8 9 4 9 8 7 2 3
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm - 1of 1 vote
AnswersProgram to rotate an array
- Putta June 22, 2013 in India| Report Duplicate | Flag | PURGE
Synopsys R&D Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersGiven an array which is sorted in ascending order upto kth element and then in descending order. Find the maximum element.
- rash September 08, 2011 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersPrint out all the subsets of an array
- rr November 22, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a list of machines where each machine has a hard disk limit and memory capacity and given a list of processes where each process requires certain hard disk space and memory, write an efficient algorithm to match processes to machines. (You may assume process to server mapping is 1:1).
- Metta September 20, 2010
(I gave a brute force solution but the interviewer wanted a more optimal solution)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersWhat's the algorithm to transform the sentence "the brown fox ran fast" in "eht nworb xof nar tsaf" (reverse any word)
- rignanese.leo November 02, 2017 in Europe| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a list of coin values, and quantity of each type of coin. Write a
- snakeonbasket November 18, 2016 in United States
program to return the set of all possible sums which can be made using those
coins.
ex. coins = [10, 50, 100, 500]
quantity = [5, 3, 2, 2]
sum could be 400 , 300 ,200 , 100| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersGiven an array of integer, find the number of un-ordered pairs in that array, say given {1, 3, 2}, the answer is 1 because {3, 2} is un-ordered, and for array {3, 2, 1}, the answer is 3 because {3, 2}, {3, 1}, {2, 1}.
- lsdtc1225 November 02, 2014 in United States
Obviously, this can be solved by brute force with O(n^2) running time, or permute all possible pairs then eliminate those invalid pairs.
My question is does any body have any better solution and how would you do it because it seems like a dynamic programming problem. A snippet of code would be helpful| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersImplement a sudoku solution verifier function. The rules for sudoku is this:
You have a 9 by 9 board. This board is divided into nine rows, nine columns, and nine 3x3 blocks. In a solved puzzle, every row, every column, and every 0 block has to contain each of the digits from 1 to 9. This is an example of a solved puzzle:
- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 05, 2014 in United States248|395|716 571|628|349 936|741|582 ---+---+--- 682|539|174 359|174|628 714|862|953 ---+---+--- 863|417|295 195|286|437 427|953|861
| Report Duplicate | Flag | PURGE
Google Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersThere is an array of characters, say A[ ] and there is another array of doubles of equal size say W[ ]. Need to design a method called randomChar( ) that will return a character, but the probability of returning a character at index i ie. A[i] will be W[i].
- nosyDeveloper November 22, 2013 in United States
eg. A = ['a', 'b', 'c']
W = [0.3, 0.5, 0.2]
Then randomChar() called around 100 times should return approx 30 times 'a', 50 times 'b' and 20 times 'c'.
My approach was calculating cumulative probability for the array, eg. W' = [0.3, 0.8, 1.0], then generating random number between 0 and 1 and finally looking up the cumulative array for the right range of the number using binary search. The main problem was the modifications to the normal binary search to check the correct range of generated random number.| Report Duplicate | Flag | PURGE
Yahoo Software Development Manager Algorithm - 1of 1 vote
AnswersFind number of palindromes in a string
- Omar.Enayet November 02, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersPrint all pairs(sets) of prime numbers (p,q) such that p*q <= n, where n is given number
- mail.kshitij.jain October 09, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven two sorted arrays of equal length, how do you find a pair of numbers, one from each array, such that the absolute difference between the two numbers is minimum.
- Murali Mohan July 22, 2013 in India for Bangalore| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 1 vote
AnswersFind the largest k elements from a large file?
- grave June 27, 2013 in India
You dont have RAM to store even k elements.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven an array of N positive integers, N being even, and a number K, find out if it is possible
- sam March 22, 2013 in India
to form pairs of the numbers present in the array such that the sum of numbers in each pair is
divisible by K.| Report Duplicate | Flag | PURGE
Directi Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou have gine n points with x and y cordinates (2 D), and you have to print how many of them are capable of forming a square and for each square print the points that are forming the square.
- pandu.vdp January 30, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Financial Software Developer Algorithm - 1of 1 vote
AnswersGiven a string containing only digits, restore it by returning all possible valid IP address combinations.
- grave September 07, 2012 in India
For example:
Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]{hint:recursion,backtrack}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a set of non overlapping intervals
- Dev March 12, 2012 in United States
Example 1 :(1,4) (6,10) (14, 19) and another interval (13, 17) merge them as (1,4) (6,10) (13,19)
Example 2: (1,5) (6, 15) (20, 21) (23, 26) (27, 30) (35, 40)
New interval (14, 33)
Output should be
(1,5) (6, 33) (35, 40)
This is because the new interval overlaps with (6, 15) (20, 21) (23, 26) (27, 30)| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Algorithm - 1of 1 vote
AnswersWrite a function to find the nearest link on a webpage given the mouse x,y coordinates.
- bjh August 14, 2010
If your algorithm just iterates through all the links, give an idea of how to make it faster.| Report Duplicate | Flag | PURGE
Google Front-end Software Engineer Algorithm - 1of 1 vote
AnswersCoding: Jig saw puzzle. What are the data structures? Assume you have some method which can tell you if two pieces fit together. How would you solve the puzzle, minimizing the number of times you have to call that function?
- Gayle L McDowell April 04, 2005| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
Answersgiven a stream of natural numbers ,
- salviaditya1986 December 08, 2016 in United States
and a array J contains integers in increasing orders
operations performed J = [2,3,4]
1 2 3 4 5 6 7 8 9 10…………..27....100...1111
first operation
J[0] = 2 => remove every 2nd integer
now the stream is
1 3 5 7 … 27
J[1] = 3
remove every 3rd
stream is now
1 3 7 …
3rd
given a natural number n , find if it will survive given J, or at what index it will
die.| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Algorithm - 1of 1 vote
AnswersInput argument of a method is a list of char array. The method have to print all the possible combination of input char(s)...For example if the input argument has ['A','B','C','D'] the output should be A,B,C,AB,AC,AD,BC,BD,CD,ABC,ACD,BCD,ABCD
- kumar October 19, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersGiven a string which may contain parenthesis. We must verify the validity of the string.
- teli.vaibhav October 02, 2015 in United States
ex-
1) "<ad675+-fkmfd>" is a valid string
2) "<[((kskfhdbh7)" is invalid
3) "[<<((shfs8))>>]" is valid
Extension to the question -
Suppose you had a hash table that told you how a parenthesis starts and how it ends as a key value pair, how would you then validate the string.
ex - <key,value> = < '(' , ')' > indicates '(' is a start parenthesis and ')' should be the end of that paranthesis.
<'A','&'> indicates that 'A' is a start parenthesis and '&' is the end parenthesis.
Note: Validity means a parenthesis that starts, must end.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm