Algorithm Interview Questions
- 2of 2 votes
AnswersGiven a list of n points in 2D space. Lets call them (X1,Y1), (X2,Y2) .... (Xn,Yn). Find the optimal way to retrieve the result of following query.
- Amm Sokun May 22, 2013 in India
SELECT min(X) FROM (2D Points) WHERE Y between Ymin and Ymax.| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 2of 2 votes
AnswersGiven a 2D array of size m X n, containing either 1 or 0. As we traverse through, where ever we encounter 0, we need to convert the whole corresponding row and column to 0, where the original value may or may not be 0. Now devise an algorithm to solve the problem minimizing the time and space complexity.
- mrinalkamboj December 18, 2012 in India for Bing| Report Duplicate | Flag | PURGE
Microsoft Tech Lead Algorithm - 2of 2 votes
AnswersYou are given N blocks of height 1…N. In how many ways can you arrange these blocks in a row such that when viewed from left you see only L blocks (rest are hidden by taller blocks) and when seen from right you see only R blocks? Example given N=3, L=2, R=1 there is only one arrangement {2, 1, 3} while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.
- game January 21, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou know result of a soccer match, print all the possible ways that this game ends up with this result.
- u-11i24223 December 01, 2015 in United States
Example: final score 1 - 1:
0 - 0
0 - 1
1 - 1
0 - 0
1 - 0
1 - 1
Another example if the final score is 2 - 3 there are many possibilities for reaching to that score:
2 - 3
0 - 0
1 - 0
2 - 0
2 - 1
2 - 2
2 - 3
0 - 0
1 - 0
1 - 1
1 - 2
2 - 2
2 - 3
0 - 0
0 - 1
0 - 2
0 - 3
...| Report Duplicate | Flag | PURGE
unknown Software Engineer Algorithm - 2of 2 votes
AnswersWe have an iterator class as below:
class CIterator { int Next(); //Returns the value of the next element in the iteration by advancing the iterator bool HasNext() const; //check whether any next element for the current iterator };
We need a CPeekIterator class which is having below functionalities
Class CPeekIterator { int Next (); //Same as CIterator does bool HasNext() const; //same as CIterator does int Peek(); // Returns the next element in the iteration without advancing the iterator };
Write the CPeekIterator class
- johnsvakel November 24, 2015 in United States for GFS| 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
Answerswrite a function that detects conflicts in given meeting schedules
- bazinga March 24, 2015 in United States
input: a list of intervals, [(s1, e1), (s2, e2), ]
output: return True if there's any conflict, False otherwise| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
AnswersPrint a BST such that it looks like a tree (with new lines and indentation, the way we see it in algorithms books).
- Ray December 22, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 2of 2 votes
AnswersGiven an array of type:-
- anupjunagadecat November 25, 2014 in India for 11
1. Increasing
2. Decreasing.
3. Increase-Decrease
4. Decrease-Increase
Find:- 1. Type of array in minimum steps ?
2. Maximum element from array in min steps?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a binary tree print it in inward spiral order i.e first print level 1, then level n, then level 2, then n-1 and so on.
- neer.1304 December 10, 2015 in United States
For Ex -
1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Print- 1 15 14 13 12 11 10 9 8 2 3 7 6 5 4
Follow up question - Extend the algorithm to n-ary tree.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersYou are given a function: List<TimeSlot> getTimeSlots (String friend)
- h3ssam March 15, 2015 in United States
Assume getTimeSlots() returns available times for a friend, sorted in order, with no overlap.
Assume TimeSlot has comparable function
You want to schedule a meeting among all of your friends, such that all can attend.
Implement a function to get the first 3 common TimeSlots among all your friends:
List<TimeSlot> get3CommonTimeSlots (List<String> friends)
user1 1-2pm, 3-4pm, 7-8pm
user2 1-2pm, 5-6pm| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm - 2of 2 votes
AnswersGiven a normal binary tree, write a function to serialize the tree into a string representation (returning the string), and also a function to deserialize a serialized string into the original binary tree.
- Microwish February 25, 2014 in China| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a snake and ladder game, write a function that returns the minimum number of jumps to take top or destination position.
- Vin August 17, 2013 in India
You can assume the die you throws results in always favor of you.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
Answers'K' number of char arrays of different length are given, find Cartesian product of them in optimal way & give complexity. I used divide & conquer.
- ameyabap February 23, 2013 in India for AppeX| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou are designing a system the records website visits. The interface for this system is:
- taylor.halliday April 26, 2016 in United States
void recordHit();
long getCount();
`getCount()` returns the amount of hits to the site for only the last 5 minutes.
Your task is to code `recordHit()` and `getCount()`| Report Duplicate | Flag | PURGE
Dropbox Software Engineer Algorithm - 2of 2 votes
AnswersGiven a number (integer) as a string turn in into a number:
- tamashionuth January 02, 2016 in United States
E.g. "One million two hundreds thousands fifty seven" => shoud return 1200057.
How to model it and how to test it? What data structures would you use. Deep testing (corner cases)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 2of 2 votes
AnswersYou have N points on a 2D surface. List K points at a shortest distance to the point (0, 0).
- tested.candidate March 22, 2015 in UK| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersK largest elements from a big file or array.
- karthikkamal666 July 27, 2014 in India| Report Duplicate | Flag | PURGE
Algorithm - 2of 2 votes
AnswersGiven a list of 2d points, if any two points have distance(straight line) <= k , group them together. For example. [P1,P2,P3], P1 to P2 <=k, P2 to p3<=k, p1 to p3>k. they are still in the same group. (distance relationship is chainable ) ask how many groups can you find ? I can think of N^2 time complexity with union and find. but how to do better than that? maybe NlogN or O(N)?
- laoen November 30, 2019 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersBrace Expansion
- neer.1304 April 21, 2019 in United States
Given a string, perfrom the brace expansion
For example,
Input: s = "a{d,c,b}e"
output: {ade , ace , abe}| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersFind the indices of all anagrams of a given word in a another word.
- aonecoding October 09, 2017 in United States
For example: Find the indices of all the anagrams of AB in ABCDBACDAB (Answer: 0, 4, 8)| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 2of 2 votes
AnswersFind the pair of numbers that sums to an integer k from an linked list.
- dke.ade January 14, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern Algorithm - 2of 2 votes
AnswersGiven a n (large number) lists of customers who visited n webpages on n (large number) days, design a data structure to get customers who have visited the website on exactly “k” days and should have visited at least “m” distinct pages altogether.
- blackfever September 03, 2013 in India
Was then asked to improvise the solution as much as possible| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersGiven a function getRandom that returns a random double in [0,1). Write a function getRandomPermutation(int n) that takes a positive integer n as argument and returns a random permutation of first n natural numbers.
- AlgoBaba November 15, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou want to design a Cab system which will show you nearest 5 taxis.
- Shanky.Q3 July 04, 2016 in United States
Each taxi will continuously emit (x,y) coordinates.
You need to print the nearest 5 taxis from (p,q).| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 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 - 2of 2 votes
AnswersHow will you serialize the binary tree ?
- algeek July 08, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 2of 2 votes
AnswersConstructing Bridges:
- R@M3$H.N December 25, 2014 in India
A River that cuts through a set of cities above and below it. Each city above the river is matched with a city below the river.
Construct as many Non-Crossing Bridges as possible.
Input:
Above Bank >> 7 4 3 6 2 1 5
Below Bank >> 5 3 2 4 6 1 7
are given in pairs: (7,5) (4,3) (3,2) (6,4) (2,6) (1,1) (5,7)
Output:
(1,1) (3,2) (4,3) (6,4) (7,5)| Report Duplicate | Flag | PURGE
StartUp SDE-2 Algorithm Data Structures