Recent Interview Questions
- 2of 4 votes
AnswersYou are standing before two doors.One door leads to the heaven and the other leads to Hell but you don't know what hides behind the doors. There are two gatekeepers. You know one of them always tells the truth and the other always lies, but you don't know who is the honest one and who is the liar.
- Anand Barnwal April 30, 2015 in India
You can only ask one question to one of them in order to find the way to heaven. What is the question?| Report Duplicate | Flag | PURGE
Intuit Intern Puzzle - 2of 4 votes
AnswersWrite a method to return first five 10 digit prime numbers.
- saudip100 July 22, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 2of 4 votes
AnswersGiven a complete binary tree, Find a Max element
- sLion June 18, 2014 in United States| Report Duplicate | Flag | PURGE
Google SDE1 Data Structures - 2of 4 votes
AnswersIn Java: Write a function in language of your choice that takes in two strings, and returns true if they match. Constraints are as follows: String 1, the text to match to, will be alphabets and digits. String 2, the pattern, will be alphabets, digits, '.' and '*'. '.' means either alphabet or digit will be considered as a "match". "*" means the previous character is repeat 0 or more # of times. For example: Text: Facebook Pattern: F.cebo*k returns true.
- dke.ade February 13, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 2of 4 votes
AnswersGiven a sequence of numbers such that A[0] >= A[1] and A[N-1] >= A[N-2] find at-least one triplet such that A[n-1] >= A[n] <= A[n+1]. Better than linear time is expected.
- hsantosh71 June 15, 2013 in United States
Example: 9 8 5 4 3 2 6 7
Answer: 3 2 6| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 4 votes
AnswersSuppose u have a square matrix of 0s and 1s only ... find the longest path of 1s available in the matrix and return that .. you can only move right and down ... For e.g.
- Messiah January 20, 2013 in India
0 0 0 1 1
1 1 1 0 1
0 1 1 1 0
0 0 1 0 0
1 1 1 1 1| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Algorithm - 2of 4 votes
AnswersHaving a table Genre with two colums (Id, Genre) make an SQL Query that finds the Ids with the genre Action and Comedy. (those will have multiple lines for each Id)
Answer:
- mikeldi10 June 19, 2014 in UK for Amazon Instant Videoselect g.id from (select id from genre where genre = 'Action') x, genre as g where g.id = x.id and genre = 'Commedy'
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer SQL - 2of 4 votes
AnswersGiven two arrays were digits of one array represent a number,maxmise the number by replacing it with elements of second array.
- ritwik_pandey September 17, 2015 in United States
eg:
arr={3,1,4,5,6}
rep={1,9,5,2,3}
after replacement
arr={9,5,4,5,6}
one digit of rep can be used to replace only once.| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer - 2of 4 votes
AnswersAlex is standing on the top left cell (1,1) of a n*m table. The table has n rows and m columns. Initially, he is facing its right cell. He moves on the table in the following way:
- itzmevacho August 01, 2013 in United States
>He moves one step forward.
>He turns to his right
>While moving forward, if he would go out of the table or reach a visited cell, he turns to his right.
He moves in the table as much as he can. Can you find out the number of cells he visits before he stops?
For example, given a 9x9 grid, the following would be his moves. The number on each cell represents the step he would land on that particular cell.
1 2 55 54 51 50 47 46 45
4 3 56 53 52 49 48 43 44
5 6 57 58 79 78 77 42 41
8 7 60 59 80 75 76 39 40
9 10 61 62 81 74 73 38 37
12 11 64 63 68 69 72 35 36
13 14 65 66 67 70 71 34 33
16 15 20 21 24 25 28 29 32
17 18 19 22 23 26 27 30 31
Input:
The first line of the input contains two integer numbers n and m.
n and m are between 1 and 100.
Output:
Print an integer to the output being the answer of the test.
Sample input #00:
3 3
Sample output #00:
9
Sample input #01:
7 4
Sample output #01:
18| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer - 2of 4 votes
AnswersGiven a screen with all pixels having one of two colors. Now I will click on a random pixel.
- X July 04, 2013 in United States
Then that pixel & all the adjacent pixels with same color should change the color to the second color.
adjacent = vertically or horizontally above or blow.
Edit: Question seem to be not clear to some ppl. Giving an ex:
Given below & clicked on 2nd row, 2nd col
W B W W B W
B B W W B W
W B B B W B
W B W W B B
Covert to
W W W W B W
W W W W B W
W W W W W B
W W W W B B| Report Duplicate | Flag | PURGE
Google Applications Developer Algorithm - 2of 4 votes
AnswersGiven a Binary tree and a arbirary node of that tree , find all the nodes at a Distance of K from that Node .Nodes DON’T have parent pointers
- Rahul Sharma January 19, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 4 votes
AnswersFind the maximum depth of binary tree?
- skrish August 13, 2014 in United States
Once I wrote the code for this, interviewer asked me next question| Report Duplicate | Flag | PURGE
Facebook Senior Software Development Engineer Algorithm - 2of 4 votes
AnswersFind the minimum of every sub-array of size k in an array of size n.
- vgupta.2119 September 18, 2016 in India
O(n) solution required.| Report Duplicate | Flag | PURGE
Google Software Developer - 2of 4 votes
AnswersGiven two trees, find if tree 2 is the mirror image of tree 1.
- techpanja October 02, 2013 in United States| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Data Structures - 2of 4 votes
AnswersGiven a room with thief on left side of the room with finite number of sensors. He has to reach on right side missing the sensors. Each sensor is placed at any random point in the room and has its coverage in the radius r. Find out if the thief can reach to the right side without touching the range of any sensor.?
- shivamdurani220 September 15, 2018 in United States
please discuss approach first & then code it..| Report Duplicate | Flag | PURGE
Google SDE-2 - 2of 4 votes
AnswersDescription
- programming.kingdom June 07, 2015 in United States
A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate.
Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall.
For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall.
In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue.
Input
There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 <= n <= 12, which is the number of courses in this data set and m, 2 <= m <= 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered ('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 <= p <= 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above.
Output
The output contains one line for each data set, formatted as shown in the sample output.
Sample Input
4 6
cs123 mt42 cs456 cs789
mt42 F 0
cs123 S 0
cs456 S 2 cs123 mt42
cs789 B 1 cs456
3 6
math1 comp2 comp3
comp3 S 1 comp2
math1 S 0
comp2 F 1 math1
4 3
m10 m20 c33 c44
m10 B 0
m20 B 0
c33 B 0
c44 B 0
-1 -1
Sample Output
The minimum number of semesters required to graduate is 5.
The minimum number of semesters required to graduate is 4.
The minimum number of semesters required to graduate is 2.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 2of 4 votes
AnswersHow many squares are present in an NxN grid?
- Murali Mohan March 27, 2014 in India
In an MxN grid, how many squares are present and how many rectangles?| Report Duplicate | Flag | PURGE
Amazon Computer Scientist Math & Computation - 2of 4 votes
AnswersSearch in a row wise and column wise sorted matrix
- vinod January 24, 2014 in India| Report Duplicate | Flag | PURGE
Amazon Intern Matrix - 2of 4 votes
AnswersA teacher wanted 100 gems distributed in 7 purses such that number of gems in 7 purses should always sum up to 100. But his condition was that he can demand any number of gems between 1 to 100 and Shiva must be able to satisfy his demand without needing to open any purse. Also once Shiva packs the purses, he will not get another chance to rearrange the number of Gems in those 7 purses. So consider that these purses are sealed the moment Shiva puts appropriate number of Gems in it.
- chouhan.mayank August 14, 2013 in India
Out of affection, the teacher decided to step up the difficulty level so that Shiva can survive the turbulent world outside the Gurukul. The Guru added one more condition that out of 7 purses Guru will always fill one purse with any number of gems. Thus Shiva need to distribute remaining Gems in rest of the 6 purses.
As a new techie your task is to write a computer program to help Shiva in fulfilling his Guru's demand.| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Engineer / Developer Algorithm - 2of 4 votes
AnswersGiven two sorted arrays, find the median of each array. The length of the arrays are m and n and we should not use extra buffer. We should find the median and time complexity should be less than 0(M+N);
- alregith June 02, 2013 in India for Chennai| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Data Structures - 2of 4 votes
AnswersGiven number of digits of a phone number and number of disallowed digits as input, find all permutations of numbers which do not have two adjacent numbers the same, i.e. 1232 is allowed but not 1223. Disallowed digits can be upto 3, and can be included along with the phone number. Also the phone number should start with 4 if it contains the number 4.
- hpfan1 October 18, 2014 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer - 2of 4 votes
AnswersImplement HashTable in java , especially hash function that should take care of any type of keys. The key may be integer or String or Object. But based on that the hash function should find index in the hashArray
- sivaji8 November 15, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Data Structures - 2of 4 votes
AnswersRound3 Google
- aonecoding January 16, 2018 in United States
For N light bulbs , implement two methods
I. isOn(int i) - find if the ith bulb is on or off.
II. toggle(int i, int j) - i <= j. Switch state (switch on if it's off, turn off if it's on) of every bulb in range i to j.
All bulbs are off initially.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 4 votes
AnswersA frequent traveller collects all his travel tickets.
- rd22 September 24, 2016 in India
A ticket has only 2 attributes, Start Journey Location name and Destination Name. Example from Delhi to Mumbai.
At the end of the year, the traveller gets all his tickets together and tries to map his journey across the year. Print his travel route in a readable format. He does not remember his start location.
Edit: he can visit a location multiple times, and can also go back and forth a place several times.| Report Duplicate | Flag | PURGE
Amazon Algorithm - 2of 4 votes
AnswersFind all comments in the Java (it could be Python or any other language of your choice) codes that’s parsed in as a string.
- aonecoding January 27, 2017 in United States
You may assume the codes given is valid.
Input is a single string, e.g.
String codes =
“/* file created by aonecode.com\\n” +
“ welcome to the tech blog*/ \\n” +
“//main method\\n” +
“public static void main(String[] args) { \\n“ +
“ System.out.println(“//welcome”); //output\\n” +
“}”
Output is a list of strings
List<String> ret =
[
“ file created by anecode.com\n welcome to the tech blog”,
“main method”,
“output”
]| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 4 votes
AnswersImplement LRU cache.
- iamthe0ne August 16, 2013 in United States| Report Duplicate | Flag | PURGE
Twitter Software Engineer / Developer Algorithm - 2of 4 votes
AnswerCongrats to aonecode's member F.L.
- aonecoding November 03, 2017 in United States
Got offers from - Youtube(G), LinkedIn, Airbnb, Square, Wish, Blend and NextDoor!
Thanks for sharing the interview experience with us.
Youtube Interview
- Phone: Find anagrams of string A from string B (sliding window)
- Phone: Find if two frames in a screen are equal. Frames may overlap. (equal method)
Onsite:
- LC41 first missing positive
- LC499+LC505 The maze
- LC161 one edit distance
- Similar to hangman but make guesses based on a dictionary.
Assume a dictionary has words - {house, morse, jesus} and ‘morse’ is the answer. If your first guess is ‘house’, output will be ‘_o_se’, which indicates 3 letters are correct. (Here the arrangement of letters does not matter. Your guess can be ‘co’ and if answer is ‘ok’ then the output is gonna be ‘_o’ which indicates letter ‘o’ in answer. )
Try to get the answer with minimum guesses.
(Interviewer expects pre-processing the dictionary. Key: letter; Value: frequency. Begin with combinations of most frequent letters first)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 4 votes
Answerinterviewed by senior engineer
- aonecoding April 13, 2017 in United States
Question Given two strings s1 and s2, combine the characters in the strings and maintain the sequence of characters
Follow-up If s1 has a length of m and s2 has a length of n, how many ways the strings could be merged. Figure out the formula F(m, n) = ?| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersRound 1: Q2:
- Abee July 20, 2011
Puzzle
Given 25 horses, find the best 3 horses with minimum number of races. Each race can have only 5 horses. You don't have a timer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers Highbridge Capital Deshaw Inc - 2of 2 votes
Answersfind the longest palindrome in a string?
- handiaya November 09, 2009| Report Duplicate | Flag | PURGE
Microsoft Amazon Software Engineer / Developer Algorithm Arrays C++ Coding String Manipulation C