Algorithm Interview Questions
- 2of 2 votes
AnswersWhat is the fastest way to compute cube root?
- Ray November 14, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a character limit and a message, split the message up into annotated chunks without cutting words as, for example when sending the SMS "Hi Sivasrinivas, your Uber is arriving now!" with char limit 25, you should get
- sivasrinivas November 14, 2015 in United States
["Hi Sivasrinivas,(1/3)", "your Uber is arriving(2/3)", "now!(3/3)"]| Report Duplicate | Flag | PURGE
Uber Software Engineer Algorithm - 0of 0 votes
AnswersThe idea is their are "ticket stalls" with a certain number of tickets, say 9. Any ticket they sell is priced at the number of tickets that remain, so first ticket would be $9, second $8 etc...
- gdasara1@asu.edu November 13, 2015 in United States
You're given two lines of data, say:
2 4
1 5
The first row contains two numbers:
The number of stalls
How many tickets are sold
The second line contains a list of how many tickets each stall has initially, so in this case stall 1 has 1 ticket, stall 5 has 5 tickets.
The problem: what is the maximum amount of money you can make selling the given number of tickets?
In this case, you sell four tickets from stall two for a price of 5 + 4 + 3 + 2 = $14| Report Duplicate | Flag | PURGE
Citrix System Inc 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 - 0of 2 votes
AnswersThe "Island Count" Problem
- rasmiranjanbabu November 10, 2015 in United States
Given a 2D matrix M, filled with either 0s or 1s, count the number of islands of 1s in M.
An island is a group of adjacent values that are all 1s. Every cell in M can be adjacent to the 4 cells that are next to it on the same row or column.
Explain and code the most efficient solution possible and analyze its runtime complexity.
Example: the matrix below has 6 islands:
0 1 0 1 0
0 0 1 1 1
1 0 0 1 0
0 1 1 0 0
1 0 1 0 1| Report Duplicate | Flag | PURGE
unknown xyz Algorithm - 0of 0 votes
Answerswrite a program to parse a prefix expression and calculate it's result. Example: *-6 5 7 = 7.
- Johnybegood November 09, 2015 in United States| Report Duplicate | Flag | PURGE
Qumulo Member Technical Staff Algorithm - 0of 0 votes
AnswersYou're given a maze (that is not necessarily square shaped). The maze is composed of square rooms. In one of these rooms there is a flag. You have a robot that you can control using the following APIs:
- Johnybegood November 09, 2015 in United States
1. void Go() - drives the robot straight.
2. void Turn(int degrees) - turns the robot x degrees to the right (x has to be a multiple of 90).
3. bool IsWall() - returns true if the robot is facing a wall (you can't move from one room to the other).
4. bool IsFlag - returns true if the room has the flag in it.
5. void PutBreadCrumb() - throws a single breadcrumb in the room.
6. bool HasBreadCrumb()- returns true if the room contains a breadcrumb.
Using these Apis only, write a program to navigate the robot through the maze until it finds the flag.| Report Duplicate | Flag | PURGE
Qumulo Member Technical Staff Algorithm - 1of 1 vote
AnswersCheck given Number is same after 180 degree rotation?
- R@M3$H.N November 09, 2015 in United States
i/p: 69
o/p: True
i/p: 916
o/p: True
i/p: 123
o/p: False| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 0of 0 votes
AnswersGive a Barrel a position say X.
- sudhiaithal November 07, 2015 in United States
Barrel can pushed left or right with equal probability.
A single push to left side will place the barrel to left of X and push to right will place the barrel to right of X.
After 10 pushes (either left or right with equal probability) what is the probability that barrel will be back to the same position X ?
Write a code or derive mathematically.| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 2of 2 votes
AnswerHow do we achieve (google news) personalization.
- sati November 05, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 3 votes
AnswersGiven a random string S and another string T with unique elements, find the minimum consecutive sub-string of S such that it contains all the elements in T.
- Saghar H November 05, 2015 in United States
example:
S='adobecodebanc'
T='abc'
answer='banc'| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 5of 5 votes
AnswersGiven an infinite stream of characters and a list L of strings, create a function that calls an external API when a word in L is recognized during the processing of the stream.
- ragmo2223 November 05, 2015 in United States
Example:
L = ["ok","test","one","try","trying"]
stream = a,b,c,o,k,d,e,f,t,r,y,i,n,g.............
the call to external API (let's call it some function callAPI()) would be called when the 'k' is encountered, again when the 'y' is encountered, and again at 'g'.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven a large that consists of millions of lines, retrieve only the first and last lines.
- adelabarra24 November 05, 2015 in United States| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 2of 2 votes
AnswersThere is a circular train (the head is connected to the tail) where each car of the train contains a light bulb. Initially, the bulbs are randomly switched on/off.
- pavel.em November 04, 2015 in Germany
You need to determine the size of the train (the number of cars)
by going from one car to another and switching the light bulbs| Report Duplicate | Flag | PURGE
Yandex Software Engineer / Developer Algorithm - -2of 2 votes
AnswersCadbury bar size of 5*3 can be distributed to 4 children.
- Deep November 04, 2015 in India
5*4 can be distributed to 5 children.
6*3 can be distributed to 2 children.
6*4 can be distributed to 3 children. so the whole carton can be distributed among 14 children
Program output shall be 14.
Input/Output Specification: M,N,P,Q are the integer type (M,N values are the ranges for the length of cadburybar P,Q values are the ranges for breadth of Cadbury bar)
Output: Number of children who will receive cadbury bar from the carton.| Report Duplicate | Flag | PURGE
Cisco Systems SDE-2 Algorithm - 1of 3 votes
AnswersDesign a library to map a string of [a-zA-Z]+ to a positive integer value.
- madhurjf November 03, 2015 in India
For the strings, there could be:
An exact match. Eg: "get" will match only "get"
A prefix match. Eg: "com" will match anything that begins with "com"
The conditions are:
An exact match takes preference over prefix match.
In cases of multiple matches, the longest match takes preference.| Report Duplicate | Flag | PURGE
Algorithm - 5of 5 votes
AnswersGiven a prime set, we call "prime expressible" if a number can be factorized only using given prime numbers. Find n-th big expressible number.
- pandacoder October 30, 2015 in United States
E.g., prime set = {2, 3}
expressible number = {1,2,3,4,6,8, 9, 12...}
non-expressible number = {5, 10... }
The primes in the prime set are ordered in an increasing order, and can include a prime < 10^4 (don't remember the exact range), and n can also be as large as 1-10^6.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven an array of both positive and negative integers , find all pairs whose sum is equal to zero.
- sudhiaithal October 30, 2015 in United States| Report Duplicate | Flag | PURGE
xyz Software Engineer Algorithm Arrays - 0of 0 votes
AnswersGiven an array A [0, 1, 3, 4,9,5,7,6] and number N.
- nonameno October 29, 2015 in England
This means that the array consists of the numbers from 0 ... N. However, as you see, 8 is missing in A. Print the missing number.
Think about the case N = 10^6| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Intern Algorithm - 1of 1 vote
AnswersGiven an array of positive integers (excluding zero) and a target number. Detect whether there is a set of consecutive elements in the array that add up to the target.
- m.mirzamo October 28, 2015 in United States
Example: a = {1, 3, 5, 7, 9}
target = 8
output = true ({3, 5})
or target = 15
output = true : {3, 5, 8}
but if target = 6, output would be false. since 1 and 5 are not next to each other.| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 0of 0 votes
AnswersGiven an array of integers. Modify the array by moving all the zeros to the end (right side). The order of the other elements doesn't matter.
- m.mirzamo October 28, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm Data Structures - 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
AnswersWrite a function to detect the number of cycles in a directed graph. The graph is passed as an adjacency matrix.
- Anand Barnwal October 27, 2015 in India| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 6of 6 votes
AnswersGiven an array of elements, return an array of values pertaining to how many elements are greater than that element remaining in the array.
- PradeepN October 27, 2015 in United States
Brute force is obvious, but must be done faster than O(n^2)
Ex. [3,4,5,9,2,1, 3]
Return [3, 2, 1, 0, 1, 1, 0]
First element is 3 because 3<4,5,9. Second element is 2 because 4< 5,9 etc| Report Duplicate | Flag | PURGE
Google Algorithm - 1of 1 vote
AnswersGiven a set of values 0-9, return all permutations of that set of length n. Example: n=2, set ={2,3,4} Return: {2,2}, {3,3}, {4,4}, {2,3}, {3,2}, {3,4}, {4,3}, {2,4}, {4,2}
- PradeepN October 27, 2015 in United States| Report Duplicate | Flag | PURGE
Google Algorithm - 1of 1 vote
AnswersGiven a pattern and a string, return a boolean of whether the string matches the pattern.
- exist October 26, 2015 in United States
Each character in pattern represents one of more characters in string.
Method: is_match(pattern, string)
Sample Testcases
is_match('abba', 'dogfishfishdog') -> True
is_match('aba', 'dogfishdog') -> True
is_match('a', 'acdefghijk') -> True
is_match('ab', 'acdefghijk') -> True
is_match('aba', 'dogfishfish') -> False
is_match('aba', 'dogfishhorse') -> False
Preferable use Python, and say the Big O runtime and space.| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersC program to accept two strings and print characters which are not present in first string.
- genny October 26, 2015 in India
Example: 1 string: apple
2 string: aeroplane
output: ro| Report Duplicate | Flag | PURGE
Adobe Software Engineer 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