Recent Interview Questions
- 3of 3 votes
AnswersThere are N floors and N persons each one is tagged with some random unique number between 1 to N(represents floor number).
- bharat May 31, 2013 in India
We have a lift which can accommodate one person at a time. Every person is in some random floor.
Initially lift is at floor 1 and all floors have single person. Problem here is.. we have to move the persons to their corresponding floor with minimum travelled distance of lift.
Restriction : Lift can have at most one person at a time.
One more thing we have to think of is .. At a time, we can keep more than one person in a floor.. means, we don't necessarily need to take the person out from the floor if we keep another person on the same floor.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 3 votes
AnswersImplement LookAndSay function. For example, first, let user input a number, say 1. Then, the function will generate the next 10 numbers which satisfy this condition:
- Kevin February 22, 2013 in United States
1, 11,21,1211,111221,312211...
explanation: first number 1, second number is one 1, so 11. Third number is two 1(previous number), so 21. next number one 2 one 1, so 1211 and so on...| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 3of 3 votes
Answers# take an array and print non over lapping in order pairs. example:
- thegeek21 June 05, 2016 in United States# [1,2,3,4] => input # output below is in order combination # (1234) # (1)(234) # (1)(23)(4) # (1)(2)(34) # (12)(34) # (12)(3)(4) # (123)(4) # (1)(2)(3)(4)
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 3 votes
AnswersYou're given a dictionary of strings, and a key. Check if the key is composed of an arbitrary number of concatenations of strings from the dictionary. For example:
- davelee71047 October 25, 2014 in United States
dictionary: "world", "hello", "super", "hell"
key: "helloworld" --> return true
key: "superman" --> return false
key: "hellohello" --> return true| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 3of 3 votes
Answers/**
- g April 23, 2014 in United States
* Implement a function OneEditApart with the following signature:
* bool OneEditApart(string s1, string s2)
*
* OneEditApart("cat", "dog") = false
* OneEditApart("cat", "cats") = true
* OneEditApart("cat", "cut") = true
* OneEditApart("cat", "cast") = true
* OneEditApart("cat", "at") = true
* OneEditApart("cat", "acts") = false
* Edit is: insertion, removal, replacement
*/| Report Duplicate | Flag | PURGE
Facebook Algorithm - 3of 3 votes
AnswersRound 3 :
- sonesh January 03, 2013 in India
Q 5 : You are given a binary search tree, and a value(data item), you need to tell the left most right cousin in as minimum time and as minimum space ?(need to minimize actual time complexity, he need minimum order of complexity as well as number of node access should be minimum)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Data Structures Trees and Graphs - 3of 3 votes
AnswersFind if a given binary tree has duplicate sub trees or not.
- neer.1304 December 25, 2015 in United States
(Two leaf nodes of a parent do not count as subtree)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersWrite a program to find pattern.
- pritishshah.it November 20, 2014 in United States
0: 1
1: 11
2: 21
3: 1211
4: 111221
5: 312211
Iterate over the previous number, and find count for same number number. Append that count before number.
e.g.,
public String pattern(int input){}
If input = 4, function should return 111221.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 3of 3 votes
AnswersSuppose we are given an array A[1 .. n] with the special property that A[1] ≥ A[2] and
- Anonymous March 24, 2011
A[n − 1] ≤ A[n]. We say that an element A[x] is a local minimum if it is less than or equal
to both its neighbors, or more formally, if A[x − 1] ≥ A[x] and A[x] ≤ A[x + 1]. For example,
there are five local minima in the following array:
9 7 7 2 1 3 7 5 4 7 3 3 4 8 6 9
We can obviously find a local minimum in O(n) time by scanning through the array. Describe
and analyze an algorithm that finds a local minimum in O(log n) time.| Report Duplicate | Flag | PURGE
Google Algorithm - 3of 3 votes
AnswersGiven n light bulbs, write two methods.
- cup August 19, 2015 in United States
isOn(i) to determine if a light bulb is on
toggle(start, end) to toggle all the light bulbs in the range
One caveat, write toggle so that it is less than O(n) complexity| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 3of 3 votes
AnswersGiven an array of integer, find the maximum drop between two array elements, given that second element comes after the first one.
- diwash.timilsina August 04, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 3of 3 votes
AnswersGiven an array, with positive and negative integers, arrange it in such a way that, positive numbers occupy even positions and negative numbers occupy odd position. All the remaining extra positive or negative integers should be stored at the end of the array. Remember, the elements of the array should remain in the same order.
- technical_123 August 11, 2013 in India
EG: Input array {1,-2,3,-4,-5,-6,-7,8,9,4,10,11,12}
output array {1,-2,3,-4,8,-5,9,-6,4,-7,10,11,12}| Report Duplicate | Flag | PURGE
Amazon Software Analyst - 3of 3 votes
AnswersFind popular item in sorted array of natural numbers.
- dreamchaser1984 February 25, 2015 in United States
An item is popular is if its repeated n/4 times or more.
For Ex:
Input: 123444445678
Popular item is 4.
Liner scan is O(n), but solution needs to be in O(logN) complexity and O(1) space complexity.| Report Duplicate | Flag | PURGE
Google Principal Software Engineer Algorithm - 3of 3 votes
AnswersCode for computing a^b and optimize it.
- AlgoAlgae April 25, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 3of 3 votes
AnswersYou have a lists with integers. Find all the pairs of numbers that sum less than or equal to to a particular number k. The list contains minimum 5 Million number.
- hirajhil February 05, 2014 in United States
(I provided a n^2logn solution but they may be looking forward to having a better answer).| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm - 3of 3 votes
AnswersHow do you remove repeated values from a INT array, returning the resultant array in the same order as original ?
- Mauricio.Malf February 20, 2013 in Netherlands| Report Duplicate | Flag | PURGE
Booking.com Software Engineer / Developer Algorithm - 3of 3 votes
AnswersWrite a program to sort an array of strings so that all anagrams are next to each other
- Neo March 07, 2013 in United States for Web Service
ex
input {god, dog, abc, cab, man}
output {abc, cab, dog, god, man}| Report Duplicate | Flag | PURGE
Amazon Intern C++ Java - 3of 3 votes
AnswersGiven a string e.g. ABCDAABCD. Shuffle he string so that no two smilar letters together.
- rajnikant12345 March 13, 2016 in India for Office
E.g. AABC can be shuffled as ABAC.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 String Manipulation - 3of 3 votes
AnswersQuestion: You are given a CSV file with 3 columns -- all integers:
- nicolasvin1982 December 05, 2013 in United States
id,parent,weight
10,30,1
30,0,10
20,30,2
50,40,3
40,30,4
0 is the assumed root node with weight 0
which describes a tree-like structure -- each line is a node, 'parent' refers to 'id' of another node.
Print out, for each node, the total weight of a subtree below this node (by convention, the weight of a subtree for node X includes the own weight of X).
You may assume that the input comes pre-parsed as a sequence of Node objects
(substitute the appropriate syntax for java/python/c++):
Node {
int id;
int parent;
int weight;
// ... you can add other fields right here, if necessary
}
implement the following:
public void printSubTreeWeight(List<Node> nodes) {
....}| Report Duplicate | Flag | PURGE
Google Senior Software Development Engineer - 3of 3 votes
AnswersImplement stairs(N) that (collect the solutions in a list) prints all the ways to climb up a N-step-stairs
- pk March 14, 2015 in United States
where one can either take a single step or double step.
We'll use 1 to represent a single step, and 2 to represent a double step.
stairs(3)
111
12
21| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 3of 3 votes
AnswersI need to store countries, its states and cities in a data structure.
- krupaljpatel July 24, 2013 in United States for Risk
The following queries might be used to fetch details
1) find list of states for a country.
2) find list of cities for a state.
3) find the name of the country and state for a city.
eg:
1) India -> Gujarat, UP, MP
MP -> bhopal,indore
Gujarat-> Surat,Ahmedabad, Baroda
2) USA -> Texas, California.. and so on.
Which is the best data structure that can be used to store these details.| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Data Structures - 3of 3 votes
AnswersFind the largest and smallest number in a list. The list is stored as two sections, one in ascending order and the other in descending order.
- uno September 29, 2016 in United States
input [ 2 3 4 5 6 7 10 9 8 7]
smallest : 2
Largest 10| Report Duplicate | Flag | PURGE
Google Software Engineer - 3of 3 votes
AnswersPrint the level of friendship.
- AnonD June 24, 2015 in United States
Given a person and list of his friends, print all his friends by level of association.
The text file will be like one below
A: B,C,D
D: B,E,F
E: C,F,G
If the input is A, the out put should be:
Level 1 - B,C,D
Level 2 - E,F
Level 3 - G| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 3of 3 votes
AnswersCode a function that gets two strings representing binary numbers (so the only possible characters are '1' and '0', and returns a third string representing the sum of the input. The input strings don't necessarily have of the same length.
- diegum June 06, 2014 in United States for iOS
Tell the complexity of the solution.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer String Manipulation - 3of 3 votes
AnswersGiven a set of intervals like 5-10, 5-10, 8-12, 9-15
- blackfever April 03, 2014 in India
Find the ith smallest number in these intervals.
for eg:-
Suppose we have intervals like 5-10, 8-12.
Then total numbers in these two intervals would be: {5,6,7,8,8,9,9,10,10,11,12}
So, 1st smallest number: 5
4th smallest number: 8
5th smallest number: 8 (here is the
change since now we have duplicate elements also) and so on.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 3 votes
AnswersSuppose you are supplied with a file containing a list of words like ABC, BCD , CAB ( say each word in new line ). now you have to suggest algorithm for this problem -
- ajitpec November 21, 2013 in India
When a user type some character, we have to suggest him next character and basis of suggestion is that the character you are going to suggest should have maximum occurrence at that position among all these words.
For example , Let's say words are
ABC
BCD
CBA
Now if user types 'A' we have to suggest him 'B' as next character because if you see at second position in all words 'B' is occurring most number of times ( 2 times ).
similarly if he types 'AB' then we need to suggest him third character as 'C' as in third index all words have same occurrence but 'C' comes first.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Data Structures - 3of 3 votes
AnswersThere are exactly N advertising boards on the highway. Now a company want to advertise on some of these advertising boards (each advertising board costs some money).
- Naveen Reddy Mandadi May 24, 2013 in United States
Company strategy is that, they want at least 'K' advertisement should be there among M consecutive advertising boards. But at the same time Company want to pay minimum for its advertisement.
Now, what is the total number of ways Company can advertise meeting its minimum cost strategy.
Also 1 <= K <= M <= 50 and M <= N <= 10^9
As for Example: N = 3, M = 2, K = 1 ==> there is only one way for minimum cost, ie. 0C0 , where '0' denotes No company advertisement, and 'C' denotes company advertisement board.
Similarly, for N = 4, M = 2, K = 1 ==> there are 3 possible ways, ie. C0C0, 0C0C, 0CC0.| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm - 3of 3 votes
AnswersTwo sorted array. Find kth smallest element
- pkn May 19, 2012 in India
O(logK)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 3of 3 votes
AnswersI had two interviews with Google
- sameer November 17, 2015 in India
first) one with US person...he asked decent question with lot of hints...experience : positive
and
then second) interview with person from India...I prepared for one month but he asked me very tough one graph/tree question...never gave single hint and based on that one question he judged my seven years of experience in Software Development (I never experienced what they say...Google looks for approach and not final answer)
Q.1 : Arrange array in wave form A1 > a2 < a3 > a4 ...
O(n.log-n) (Note: its not A1 >= A2)
Q.2 : Given Graph with Tree characteristics, find one node as root so that height of tree will be minimum| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm