Algorithm Interview Questions
- 2of 2 votes
AnswersConvert a number to English representation.
- coder145 August 09, 2016 in United States
Ex: Input : 100
Output : One Hundred.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
AnswersThere are n+1 loading docks. a permutation of boxes 1->n is placed on the first n. there is a fork that can move one box to an empty location at a time. Give an algorithm to sort then boxes with minimum number of moves.
- ad09 August 05, 2016 in United States
Follow up: minimum distance| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 2of 2 votes
AnswersYou are given printouts from an algorithm which ran over an unsorted binary tree. One printout is from an in-order run and another from a pre-order run. Can you reconstruct the tree? If so, then write an algorithm.
- tested.candidate March 22, 2015 in UK| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersFind the largest sum contiguous sub array. The length of the returned sub array must be at least of length 2.
- phoenix September 19, 2014 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 2of 2 votes
AnswersFind the largest k numbers in an enormous array of numbers. You cannot sort the array. Give the run time of the algorithm.
- jielei.wang.0316 October 25, 2013 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Application Engineer Algorithm - 2of 2 votes
Answersinput:
- S.Abakumoff February 25, 2013 in United States
sum - the integer amount
n - the number of coins
d - the array contains the coins denominations
WAP that prints all the possible non-repeated combinations of n coins of denominations from d that sum up to n.
Sample of input:
d={1,5,10,15}
sum = 30
n = 6
The expected output:
1,1,1,1,1,25
5,5,5,5,5,5| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersDesign an LRU cache with all the operations including getting the least recently used item to be O(1).
- Anonymous November 06, 2009| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersAlgorithm: You have 50,000 html files, some of which contain phone numbers. How would you create a list of all the files which contain phone numbers?
- Gayle L McDowell April 04, 2005| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design Algorithm - 2of 2 votes
AnswersYou have a string of numbers, i.e. 123. You can insert a + or - sign in front of ever number, or you can leave it empty. Find all of the different possibilities, make the calculation and return the sum.
- twinmind March 03, 2017 in United States
For example;
+1+2+3 = 6
+12+3 = 15
+123 = 123
+1+23 = 24
...
-1-2-3 = 6
...
Return the sum of all the results.| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 2of 2 votes
Answersfor given array
s[] = {5,1,0,4,2,3}
1) length of array is not given.
- idforbc November 24, 2015 in United States
2) If length of array is 5 content is guaranteed to be between 0 to 5. There is no repetition of numbers. Sample example for length(s, 3)
- a[3] = 4 , a[4] = 2, a[2] = 0, a[0] = 5, a[5] =3
returns length of 4 .
For given condition write subroutine
int length (s, 3)
- to find the number of steps it takes to find given value - It's a function api - that I was asked to write with the conditions - I cannot change parameters of the function - I have to make sure return value is correct
Additional Condition:
You cannot use any loop statements like for, while and so on -
You cannot use any global or static variables.
You cannot call other routines inside this routine
You cannot modify given function parameters - it stays length (s, n) only
You cannot change original array too| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 2of 2 votes
AnswersWrite a function to test if the given set of brackets are balanced or not. e.g. {{}}{)([][]
- Qasim November 12, 2015 in Netherlands| Report Duplicate | Flag | PURGE
Booking.com Software Developer Algorithm - 2of 2 votes
AnswersYou are given two arrays - A & B. The length of the arrays is the same - N. The values in the arrays are integers from 0 to N - 1 in random order and no number is repeated. You need to list a sequence of two-element swaps required to reorder the array A into the order of the array B. Additionally, at each step of the sequence you are allowed to swap two elements only if one of them is 0.
- tested.candidate March 21, 2015 in UK| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersGiven a 4 X 4 game slot that has random alphabets in all the slots
- JSDUDE January 16, 2015 in United States
Write a function that takes the keyboard and the word as input and returns true if the word can be formed
False otherwise.
A word can be formed on the board by connecting alphabets adjacent to each other (horizontal, vertical and diagonally)
Same alphabet should not be reused.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a large array of unsigned ints, quickly find two who's sum is 10
- JSDUDE November 22, 2014 in United States for Software Developer, Infrastructure Planning, Analysis and Optimization
Then the interviewer asked me to write test cases.
Followed by how to implement this on a distributed system, where multiple systems can read/write simultaneously on a shared cache (HINT: It is ok if you do not return the first instance)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays - 2of 2 votes
AnswersGiven N sets of integers, remove some sets so that the remaining all sets are disjoint with one another. Find the optimal solution so that the number of sets remaining at the end is maximum
- Rahul Sharma July 12, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersMapping
- Thiago January 13, 2014 in United States
'1' = 'A','B','C'
'2' = 'D','E','F'
...
'9' =
input: 112
output :ouput = [AAD, BBD, CCD, AAE, AAF, BBE, BBF, CCE, CCF]| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersConsider a system of n nodes numbered 1 to n. Each node has its id(1 to n) and a value associated with it say val. Now Every node has a send method send(int to , int val) and receive method int receive(int from).
- sowmya February 20, 2013 in United States
So if node 1 wants to send value , it does like this . send(1,val).
Using these two methods, write a distributed algorithm. Such that when the algorithm finishes, every node in the system knows the sum of the values of all the nodes in the system.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven 2 strings representing very large numbers (these are not representable as a BigInteger or other various type) write a method for adding the two numbers and returning their sum.
- Scott.T.Rogers July 06, 2018 in United States| Report Duplicate | Flag | PURGE
Facebook Senior Software Development Engineer Algorithm - 2of 2 votes
AnswersGIven a string "str" and pair of "N" swapping indices, generate a lexicographically largest string. Swapping indices can be reused any number times.
- uvm March 15, 2016 in United States
Eg 1)
String = "abdc"
Indices:
(1,4)
(3,4)
Answer:
cdba, cbad, dbac,dbca
you should print only "dbca" which is lexicographically largest.| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 2of 2 votes
AnswersGiven a dictionary containing a list of words, a starting word, and an ending word, return the minimum number of steps to transform the starting word into the ending word.
- ixnay October 28, 2015 in United States
A step involves changing one letter at a time to a valid word that is present in the dictionary.
Return null if it is impossible to transform the starting word into the ending word using the dictionary.
Example:
Starting word: cat
Ending word: dog
cat -> cot -> cog -> dog ('cot' and 'cog' are in the dictionary)
return 3| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
AnswersRound 6
- sonesh July 12, 2015 in United States
Question 3 : You are given a word document, you have to print the words with frequencies. Now print the kth rank word in terms of frequency. Print top k words as well by frequencies| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Arrays Coding Sorting - 2of 2 votes
AnswersWrite a program to swap kth node from first and kth node from last in a linked list .
- Coder April 18, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven an integer array, return the combinations of 4 array values whose sum is x
- Guest SVM April 12, 2013 in United States for AWS
Eg:
Input int array = {1,2,3,5,0,-2}
Return all possible combinations such that
a+b+c+d = 1
Like: -2 , 0 , -2 , 5
2 , -2 , 0 , 1, etc...| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 2of 2 votes
Answersgiven a stream of quotes for a stock from the last trading day. Assume its already time sorted. Find the maximum amount of money you could have made on this stock by making at most N transactions. A buy and a sell is counted as one transaction. For parts N = 1, N = 2 and N = Inf and the generic solution for N = some number (open ended)
- Steve September 11, 2012 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven points on a plane like (0,0), (1,0), (0,1), (1,1), (0,2), (2,2), (1,2). How many rectangles can be formed ?
- solveIt December 26, 2016 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven an array of task and k wait time for which a repeated task needs to wait k time to execute again. return overall unit time it will take to complete all the task.
- hm September 14, 2015 in United States
Example:
1. A B C D and k = 3
ans: 4 (execute order A B C D)
2. A B A D and k = 3
ans: 6 (execute order A B . . A D)
3. A A A A and k =3
ans: 13 (A . . . A . . . A . . . A)
4. A B C A C B D A and k = 4
ans: 11 (A B C . . A .C B D A )| Report Duplicate | Flag | PURGE
Twitter Software Engineer Algorithm - 2of 2 votes
Answersgiven an expression like 3*4 + 8-9 (only +, - , * operators) as a string evaluate it strictly from left to right
- boomla March 17, 2015 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 2of 2 votes
Answerswrite code to validate if the input string has redundant braces?
- nnb November 03, 2014 in India
((a+b)) - Has redundant braces.
(a+(b+c)) - This doesn't has redundant braces.| Report Duplicate | Flag | PURGE
Algorithm - 2of 2 votes
AnswersTraverse a given 2D matrix from given source to destination in such way that every cell should be visited exactly one time (we have to cover all cells of matrix exactly once and have to reach at destination).
- Rahul Sharma July 12, 2014 in India| Report Duplicate | Flag | PURGE
Oracle SDE-2 Algorithm