Recent Interview Questions
- 2of 2 votes
AnswersWrite a function that finds out if any two numbers within that array add up to a target.
- Bheesham March 27, 2013 in United Statesbool addsUp(Array<int> input, int target);
| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm Problem Solving - 2of 2 votes
AnswersGiven a function, take a number and the bit position and return true if that bit is set to 1 and false otherwise.
- An April 04, 2012 in United States
It took me a few minutes to think something like this, pasted code is after he corrected me on 2 silly mistakes.
bool ret_result(int number, int pos) {
int k=1;
for(int i=0;i<pos;i++) {
k=k<<1;
}
if(number&k==1) {
return true;
}
else {
return false;
}
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersGiven a rectangle with top-left(a,b) and bottom-right(c,d) coordinates. Also given some coordinates (m,n) of sensors inside the rectangle. All sensors can sense in a circular region of radius r about their centre (m,n). Total N sensors are given. A player has to reach from left side of rectangle to its right side (i.e. he can start his journey from any point whose y coordinate is b and x coordinate is a<=x<=c. He has to end his journey to any point whose y coordinate is d and x coordinate is a<=x<=c).
- ankit3600 June 14, 2016 in India
Write an algorithm to find path (possibly shortest but not necessary) from start to end as described above.
Note: all coordinates are real numbers
(a,b)
|----------------------------------------------|
|.......................................................|end
|.......................................................|
|start................................................|
|.......................................................|
|----------------------------------------------|(c,d)
Edit: You have to avoid sensors.
Also u can move in any direction any time.| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm - 2of 2 votes
AnswersThere's a function that concatenates two strings and returns the length of the resultant string. When called upon a series of strings how do we minimize the cost of using this function. Let's say we have 3 strings, A= "abc", B="def", C = "gh".
- Spectral July 07, 2015 in United States
Now cost of merging AB = 6 and cost of merging the resultant string with C is 8. Thus the total cost is 6 + 8 = 14. However, if we merge A and C, then the cost is 5 and then merge B with this, the cost is 8, so the total cost is 13.
Find an algorithm that minimizes the cost of adding such a series of strings.| Report Duplicate | Flag | PURGE
Bloomberg LP SDET Algorithm - 2of 2 votes
AnswersWrite a function which gives the length of the largest palindrome found within a string.
- grekogecko October 01, 2014 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 2of 2 votes
AnswersFind out the no of times the statement will get executed for the below code snippet.
- Bharat June 04, 2013 in India
int temp = 1;
for(int i =0; i <n; i++) {
for(int j = 0; j<= i; j++) {
for(int k= 0; k <= j; k++) {
temp++;
}
}
}
System.out.prinln(temp); // Or what will be the value of the temp?.| Report Duplicate | Flag | PURGE
GE (General Electric) Senior Software Development Engineer - 2of 2 votes
AnswersGiven two string S1 and S2. S1 contains from A-Z and S2 contains A-Z, * and ?
- darklight December 28, 2012 in India
Where * means any character 0 or any number of times
Where ? means any character 0 or 1 number of times
Write a program to determine whether S2 matches S1| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersI have 10 million 10-bit integers to sort, how would you sort them and what's the time complexity?
- chriscareercup November 12, 2012 in United States
Follow-on question: Instead of sorting integers, I now have 10 million pairs to sort. Each pair consists of a 10-bit integer and an object, the sort order is determined by the 10-bit integer. Will your original sort algorithm hold or do you need sort it differently?
(A word of advice: Ask as many questions as you want during the interview, but you MUST be quick. Also, don't mention anything until you've thought it through clearly, otherwise you're just inviting more questions. Time is of essence, you're too slow if this question takes you more than 15 minutes to come up with the optimal solution, because remember, you have to leave time for explanations and other questions)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Sorting - 2of 2 votes
Answersgiven two integers and two bit positions. Set the first integer between the two bit positions to be that of the second integer.
- Lively May 06, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersInput : Two large singly linked lists representing numbers with most significant digit as head and least significant as last node.
- Abhay Srivastava July 01, 2010
Output: Difference between the numbers as a third linked list with Most significant digit as the head.
Eg:
---
Input:
A = 5->4->2->0->0->9->0->0
B = 1->9->9
Output:
C = 5->4->2->0->0->7->0->1
Required complexity :
O(n)
Constraint:
Reversing linked list is NOT allowed| Report Duplicate | Flag | PURGE
National Instruments Software Engineer in Test - 2of 2 votes
AnswersThere are N countries, each country has Ai players. You need to form teams of size K such that each player in the team is from a different country.
- crowdx February 12, 2019 in India
Given N and number of players from each country and size K. Find the maximum number of teams you can form.| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 2of 2 votes
AnswersWe have N gas stations, and we are given all the distances between each pair of station. So we have nC2 distances provided to us. For example if I have 3 stations namely A, B, C the distances provided will be AB, AC, BC. We have to find the exact position of each gas station provided with these nC2 distances.
- logan9 August 05, 2017 in United States
eg. we have 5 stations so 5C2 distances are given in random order - 10, 20, 70, 80, 30, 20, 100, 70, 50, 90
Output the exact positions of gas stations A, B, C, D, E
i.e
A - 0
B - 10
C - 30
D - 80
E - 100
refer this image for more clarity
https://drive.google.com/open?id=0BxPkptdH01OBZzEwX29iRGI4cEU| Report Duplicate | Flag | PURGE
Google Software Engineer Problem Solving - 2of 2 votes
AnswersGiven a string "2-4a0r7-4k", there are two dashes which we can split into 3 groups of length 1, 5, 2.
- J@sper October 20, 2016 in United States
If we want each group to be length 4, then we get "24A0-R74k"
Given a String A and an int K, return a correctly formatted string.
IF A is "2-4A0r7-4k" and B is 4, string is "24A0-R74K"
IF K is 3, string is "24-A0R-74K" as the first grp could be shorter.| Report Duplicate | Flag | PURGE
Google Algorithm - 2of 2 votes
AnswersWrite a function that takes the following inputs and gives the following outputs.
- forfron December 19, 2014 in United States
Input: A list of points in 2-dimensional space, and an integer k
Output: The k input points closest to (5, 5), using Euclidean distance
Example:
Input: {(-2, -4), (0, 0), (10, 15), (5, 6), (7, 8), (-10, -30)}, k = 2
Output: {(5, 6), (7, 8)}| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 2of 2 votes
AnswersAn efficient way to sort patient files in an array of just 3 types 'High-importance', 'Mid-importance', 'Low-importance' which are in an arbitrary order (unsorted).
- Ipalibo December 19, 2014 in United States
The output preference should start with the highest.
1. High-importance
2. Mid-importance
3. Low-importance
[high,low,low,med,high,low]
ps I was told to take advantage of the fact that they are just only 3 types.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Sorting - 2of 2 votes
AnswersGiven an n x n matrix A(i,j) of integers, find maximum value A(c,d) - A(a,b) over all choices of indexes such that both c > a and d > b.
- vik October 07, 2013 in United States
Required complexity: O(n^2)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays Data Structures Ideas Matrix - 2of 2 votes
AnswersRound 1 :
- sonesh January 03, 2013 in India
Q 2 : longest palindrome in a string ? (Need to tell in O(n) time complexity + O(1) space complexity)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Coding Dynamic Programming String Manipulation - 2of 2 votes
AnswersCount the number of set bits for an 32 bits integer. How to improve the process for the second time use if the memory is unlimited?
- Andy2000 September 04, 2012 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
Answers
- Aalekh Neema July 02, 2017 in IndiaLazy Bartender : There are N number of possible drinks.(n1,n2..) Has C number of fixed customers. Every customer has fixed favourite set of drinks. Bartender has to create least possible number of drinks to suffice need of all the customers Example: Cust1: n3,n7,n5,n2,n9 Cust2: n5 Cust3: n2,n3 Cust4: n4 Cust5: n3,n4,n3,n5,n7,n4 Output: 3(n3,n4,n5)
| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 2of 2 votes
AnswersPrint the longest path from root to leaf in a Binary tree (Basically the nodes that lie on the height path).
- abhinavg.stack January 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer Data Structures - 2of 2 votes
Answersfind first not-repeating character by iterating through the length of the string only once and by using constant space.
- Raj October 28, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon SDET Algorithm - 2of 2 votes
Answers[redacted]
- tohhubeta September 02, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 2of 2 votes
AnswersSwap the elements in Kth position from the start and end of a link list.
- Aussie July 27, 2016 in United States
ex:
input: list: 1,2,4,5,7,8 & K=2
output: 1,7,4,5,2,8| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 2of 2 votes
Answers|X XX | | X X | | X | | |
X = land.
- HumbleLearner February 20, 2016 in United States
Empty space = Water.
Find the number of islands present. (Upto you how you want to represent land and water in the array above)
Answer for the above example: 3
I wish I could draw the diagram better!
Explanation: 3 because:
The three islands are:
X
X
X
XX
X| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern Algorithm - 2of 2 votes
AnswersFind the longest common prefix in a list of phrases. For instance; "i love all dogs", "i love cats" should return "i love".
- tamaracmike July 08, 2015 in United States| Report Duplicate | Flag | PURGE
Google Algorithm - 2of 2 votes
Answersn mice are playing in the desert, when one of them notices some hawks flying in the sky. It alerts the other mice who now realize that the hawks are going to attack them very soon. They are scared and want to get inside holes to ensure their safety.
- chhipababa September 27, 2014 in United States
Mice and holes are placed on a straight line. There are m holes on this line. Each hole can accommodate only 1 mouse. A mouse can either stay at its position, or move one step right from x to x+1, or move one step left from x to x-1. Any of these movements takes 1 minute.
Assign mice to holes so that the time required for all the mice to move inside the holes is minimized.
Input Format
The first line contains an integer T, the number of test cases. This is followed by T blocks of input:
First line contains 2 positive integers n and m separated by a single space.
Next line contains n space separated integers, denoting the positions of the mice.
Next line contains m space separated integers, denoting the positions of the holes.
Note: No two holes have the same position.
Output Format
For each testcase, print the minimum time taken by all the mice to reach inside the holes.
Constraints
1 ≤ T ≤ 17
1 ≤ n ≤ 131072
1 ≤ m ≤ 131072
n ≤ m
-108 ≤ mouse[i] ≤ 108
-108 ≤ hole[j] ≤ 108
Sample Input
1
3 4
2 0 -4
3 1 2 -1
Sample Output
3
Explanation
One possible solution is :
Assign mouse at position x=-4 to hole at position x=-1 -> 3 minutes
Assign mouse at postion x=2 to hole at position x=2 -> 0 minutes
Assign mouse at postion x=0 to hole at postion x=3 -> 3 minutes
So the answer is 3, after 3 minutes all of the mice are in the holes.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
Answers(To write in Objective-C; I will write the EXACT question)
- matteogobbi.jobs August 26, 2014 in United States
Given a dictionary of words, return an array of the words whose match. (i.e. pattern "c.t" match with "cat", "cut", etc. because the dot notation stand for ANY character).
SUGGEST: use suffix tree, for(for()) is not a good solution.| Report Duplicate | Flag | PURGE
Facebook iOS Developer Algorithm - 2of 2 votes
AnswersGiven a String with print all the possible combinations of the all the characters in the string as a string for Example
- Anirudh July 05, 2014 in India
"abc" is the input the you should print the below:
abc
ab
ac
a
bc
b
c
There is one invisible string which is actually a blank string.| Report Duplicate | Flag | PURGE
Komli Media SDET Java