Recent Interview Questions
- 3of 11 votes
AnswersGiven a binary representation of an integer say 15 as 1111, find the maximum longest continous sequence of 0s. The twist is it needs to be done in log N. I could think of O(N) solution. but couldn't go for log(N).
- TapeRecordia October 24, 2013 in United States
For example. 10000101
the answer should be 4, because there are 4 continouos zeroes.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 7 votes
AnswersConsider the statement
- gjp February 24, 2014 in United States
result = a ? b : c;
Implement the above statement without using any conditional statements.| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Bit Manipulation C - 3of 7 votes
Answersgiven an input array of integers where each integer represent the maximum amount of jump a frog can take.Frog has to reach the end of the array in minimum number of jumps.
- aka[1] August 05, 2013 in United States
Example:[1 5 4 6 9 3 0 0 1 3] answer is 3 for this.
[2 8 3 6 9 3 0 0 1 3] answer is 2 for this.
Any DP solution for this?| Report Duplicate | Flag | PURGE
Amazon Applications Developer Algorithm - 3of 7 votes
AnswersConsider a hotel where the guest is checked in and check out. Find a day when the maximum number of guests stay in a hotel.
- itsvks February 01, 2017 in Netherlands
example:
Input :
[
{check-in : 1, check-out 4},
{check-in : 2, check-out 5},
{check-in : 10, check-out 12},
{check-in : 5, check-out 9},
{check-in : 5, check-out 12}
]
Output : 5| Report Duplicate | Flag | PURGE
Booking.com Software Engineer / Developer Algorithm - 3of 5 votes
AnswersGiven two singly linked list, find if they are intersecting. Do this in single iteration. Also find the intersecting node in O(n) time and O(1) space. By intersection I mean intersection by reference not by value
- dm December 05, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Microsoft Software Engineer / Developer Linked Lists - 3of 5 votes
AnswersYou're given an array of integers(eg [3,4,7,1,2,9,8]) Find the index of values that satisfy A+B = C + D, where A,B,C & D are integers values in the array.
- omair.ahmed08 October 09, 2014 in United States
Eg: Given [3,4,7,1,2,9,8] array
The following
3+7 = 1+ 9 satisfies A+B=C+D
so print (0,2,3,5)| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Arrays Data Structures - 3of 5 votes
AnswersPrint all palindromes of size greater than equal to 3 of a given string. (DP)
- amnesiac February 15, 2014 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 3of 5 votes
AnswersGiven a set of busy time intervals of two people as in a calendar, find the free time intervals of both the people so as to arrange a new meeting
- Phoenix December 02, 2014 in United States
input: increasing sequence of pair of numbers
per1: (1,5) (10, 14) (19,20) (27,30)
per2: (3,5) (12,15) (18, 21) (23, 24)
ouput: (6,9) (16,17) (22,22) (25,26)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 5 votes
AnswersA string is called sstring if it consists of lowercase english letters and no two of its consecutive characters are the same.
- priteshpathak15 July 29, 2013 in India
You are given string s of length n. Calculate the number of sstrings of length that are not lexicographically greater than s.
Input format
The only line of input contains the string s. It's length is not greater than 100.
All characters of input are lowercase english letters.
Output format:
Print the answer of test modulo 1009 to the only line of output.
Sample input:
bcd
Sample output:
653| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Front-end Software Engineer Algorithm - 3of 5 votes
AnswersThere are N(0 to N-1) players each having at Max 'M' (0 to M-1) number of followers. You have to select minimum number of players so that the total followers must be equal to a given number 'K'.
I/P would be like,
first line contain N, M, K followed by N lines containing string of 0 or 1 s.t. for i'th line if j'th char is 1 it means j'th person follows player 'i'
For. eg.
- P3A July 18, 2013 in India3 6 5 111100 000100 000010 ans=2 ( select 0th and 2nd )
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 5 votes
AnswersThere are many sorted arrays. Find a minimum range, so that in each array there's at least one integer within this range.
- edcent February 25, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern Algorithm - 3of 5 votes
AnswersA robot has to move in a grid which is in the form of a matrix. It can go to
- thisandthat March 09, 2015 in United States
1.) A(i,j)--> A(i+j,j) (Down)
2.) A(i,j)--> A(i,i+j) (Right)
Given it starts at (1,1) and it has to go to A(m,n), find the minimum number of STEPS it has to take to get to (m,n) and write
public static int minSteps(int m,int n)
For instance to go from (1,1) to m=3 and n=2 it has to take (1, 1) -> (1, 2) -> (3, 2) i.e. 2 steps| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 3of 5 votes
AnswersThere is a village in which parent prefer to have at least 1 boy. So they keep doing child until they get their first boy and then they stop doing children. What is ratio of girl/boy in such town after infinite years.
- shivam.s.kalra March 13, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Automata - 3of 5 votes
AnswersProblem Statement
- nirajkantsinha March 13, 2015 in United States
Diameter
The diameter of a graph is the maximum shortest path between any two nodes.
At the beginning, there is a simple grpah contains exactly 1 node. Then we add new nodes one by one to the graph. Each time when we add a new node to the graph, we also add exactly one edge to connect this node to another node which already exists.
We want to find the diameter of the graph each time we add a new node. Note that each edge cost 1.
Input Format:
First line of the input contains one integer N, indicating how many new nodes we will add.
Then following N lines. The ith line contains an integer X, which means we add the ith node and an edge connecting the Xth node and ith node.
The original node is the 0th node.
Output Format:
Output N lines. The ith line is an integer indicating the diameter of the graph after adding the ith node.
Constraints:
0 < N <= 100000
0 <= Xi < i
i is counting from 1
Sample Input:
5
0
0
1
1
1
Sample Output:
1
2
3
3
3
Explanation:
Firstly the graph contains only node 0. The first line of output is 1 because the diameter becomes 1 when node 1 is added and connected to node 0. Diameter becomes 2 after adding node 2 to node 0. Then adding node 3, 4, 5, all of them are connecting to node 1, caculate the shortest path of all pairs of nodes, the maximum shortest path is 3, so the last 3 lines of output are all 3.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 3of 5 votes
AnswersLook at the sequence below:
- amirtar May 05, 2015 in United States
1, 11, 21, 1211, 111221, 312211, ...
Write a code that receives n and returns the nth element of the sequence. If it gets 4 as input of the method it should return 1211.| Report Duplicate | Flag | PURGE
Google Software Engineer - 3of 5 votes
AnswersGiven a Binary Tree (balanced or not) write a method that transforms the tree in a degenerate tree (basically a data structure like a sorted linked list where each node has the left child null) and returns the new root. This must be made in place, no external memory usage is allowed.
- Ray February 23, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Trees and Graphs - 3of 5 votes
AnswersGiven an n X n matrix, find all elements which are zero, when found set all the elements in that row and column to zero.
- akula.maheshk September 24, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 3of 5 votes
AnswersI was asked to design a meeting scheduler, just like in the Microsoft outlook calendar or the gmail calendar. I proposed that I will create an array of 48 for each day. Every 30 min representing the array entry.
- Bevan March 01, 2013 in United States for AWS
I have to make sure that the next appointment does not collide with a previous meeting.
My solution works fine but it wastes too much memory.
Can anyone please tell me how do I find a better solution to detect collision for meetings.
I don't know all the meetings at the beginning. They will be added randomly later.
Thanks,| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design - 3of 5 votes
AnswersThere are several people sitting in the cinema, some of them are couples, some are not, they decide to swap their seats so that the couples can seat together, please calculate the minimal swap numbers.
- xblwyc October 07, 2015 in United States
1. the swap can happen between any two position.
2. E.g. AABCCDB -> AADCCBB, ans is 1| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 5 votes
Answersgiven a dictionary of wrods,find the pair of word with following property:
- haozyname November 19, 2013 in china
1,the two word don't have same letter.
2,the multiple of the two word's length is maximum.
i give a simple O(n*n*k)(k is the average length of word) method.but i think there will be better one .| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 5 votes
AnswersA professor wants to see if two students have cheated when writing a paper. Design a function : hasCheated(String s1,String s2, int N) that evaluates to true if two strings have a common substring of length N. Additional question after implementation. Assume you don't have the possibility of using String.contains() and String.substring(). How would you implement this?
- dke.ade February 25, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Java - 3of 5 votes
AnswersPhone screen Q: String encoding and decoding: Design a method that converts a list of strings into a single string which can be later converted back to the list.
- aonecoding January 15, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Programming Skills - 3of 5 votes
AnswersGenerate all possible sorted arrays from alternate elements of two given sorted arrays.
- vishgupta92 July 28, 2015 in United States
Given two sorted arrays A and B, generate all possible arrays such that once first element is taken from A then from B then from A and so on in increasing order till the arrays exhausted. Then first element is taken from B then From A, and do same as above.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 3of 5 votes
AnswersYou're given a machine (Let's say a sprinkler). The machine is controlled with a software component that has UI. The user can set different parameters in the UI. for example : 'speed' : 120 'pressure' : 30
- GeorgyBoy December 30, 2013 in Israel
Change the system so it will accept an arithmetical expression in the UI. The expression can contain constants, parameters (e.g 'speed') and operators.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Object Oriented Design - 3of 5 votes
AnswersQ: Find the absolute paths to all directories with image files, given a file system that looks like this. The subdirectory is one indent over.
- aonecoding January 15, 2017 in United States/usr /local profile.jpg /bin config.txt dest.png /rbin image.gif /sys /re /tmp pic.jpg ..... ……
| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 5 votes
AnswersGiven a binary tree, find out the maximum sum of value from root to each leaf.
- jielei.wang.0316 October 25, 2013 in United Statesfind_Max(Node *root){ if (root==null) return 0; else return max((find_Max(root->left), find_Max(root->right))+root->value; }
| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Application Engineer - 3of 5 votes
AnswersGiven two sorted linked lists, how can you combine them into one big sorted list? Do not create additional nodes.
- kredible November 12, 2017 in Singapore| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java - 3of 3 votes
AnswersATM has x currency notes of 100 rupee,y currency notes of 500 rupee,and z currency notes of 1000 rupee notes.
- rajat sadh January 10, 2016 in India
Customer wants to withdraw n amount at any given time. as per bank rules,Customer can not withdraw more than INR.40000/-per transaction.
If ATM is running out of cash it should throw a message that insufficient Balance, Kindly enter multiple of m value of currency note.where m>=4000 and m<=total number of cash available in ATM.
An intelligent banker has found in customer survey that customer prefers to receive more than 5 currency notes 100 rupee,more than 2 currency noes of 500 rupee and rest of the currency notes is of 1000 rupee where ever possible.
If amount is less than 500,customer will receive 100 rupee currency notes. Bankers goal is to tender the minimum number of currency notes to save customer waiting time and increase customer satisfaction by following customer survey.Banker has hired you to program ATM dissaptch function.
FOR Example: Lets ATM has 200 currency notes of 100 rupees,90 currency notes of 500 rupee and 50 currency notes of 1000 rupee.Customer has placed a withdrawal request of Rs 22,200.00. Dispatch function has given him 7 currency notes of 100,3 currency notes of 500 and 20 currency notes of 1000 rupee| Report Duplicate | Flag | PURGE
Adobe SDE1 Algorithm