Recent Interview Questions
- 2of 2 votes
AnswersYou have a 3x3 grid. In each cell you can have two colors, white or black. At the beginning, the matrix has some cells painted white and others black.
- neer.1304 April 21, 2019 in United States
If you change a color cell, that is, grid [i] [j] the cells grid [i-1] [j], grid [i + 1] [j], grid [i] [j-1] and grid [ i] [j + 1] also change (if these positions do not leave the 3x3 grid), that is, if they were white, they change to black.
Return, the minimum number of cells you have to flip for the 3x3 grid to be totally white. If you cannot do this, return -1!
Sample input/output - ibb.co/3Y0WVNR| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm - 2of 2 votes
AnswersGet the sum of all prime numbers up to N. primeSum(N).
- aonecoding4 January 07, 2019 in United States
Follow-up: If primeSum(N) is frequently called, how to optimize it.| Report Duplicate | Flag | PURGE
Amazon - 2of 2 votes
AnswersWrite a program to shuffle a deck of card?
- MM October 30, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer - 2of 2 votes
AnswersRound3
- aonecoding August 09, 2017 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 start, int end)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersDesign a mall where there are 'm' entry gates and 'n' exit gates. There can be only 'x' number of people inside it. No more then 'x' people can be inside mall at any time.
- neer.1304 July 30, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Software Design - 2of 2 votes
AnswersPhone Interview, New Grad - Software Developer
Imagine you are given 10,000 files each containing 1 Million integers. I would you sum all of them and give the final result?
---> Interviewer wanted to test scalability, distributed concepts.
He has written the basic code and wanted to improve upon that.
Here's the basic code.public getSum(String[] file_names) { int sum = 0; for(String f: file_names) { sum = sum + sumOfFile(f); } return sum; }
Questions:
- confides123 March 25, 2017 in United States for Developer Tools
What's wrong with above code? Ans: Integer overflow
How would you implement sumOfFile?
What if 'sumOfFile' takes lot of time to finish computing?
How do you fasten the program?
Overall scalability etc| Report Duplicate | Flag | PURGE
Google Software Developer Distributed Computing - 2of 2 votes
AnswersIterate over a singly linked list backwards. Call print on each node.
Example: The list A->B->C should print as
"C B A"class Node { public Node next; public String value; }
There are 4 solutions
- Nerd March 16, 2017 in Europe
1) recursive
2) iterative with O(n) memory
3) iterative with O(1) memory and O(n²) runtime
4) iterative with O(1) memory and O(n) runtime (for this solution the initial list may be modified)
Explain all 4 solutions and write the code for solutions 3 and 4| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 2of 2 votes
AnswersGiven an array of numbers, find the maximum and minimum sum of sub sequences at a distance > m
- nitinsharma021 July 25, 2016 in India
Example –
arr = {3, 4, -2, 1, -2, 4, 6, -3, 5} & m = 2
Solution – max = 13 {4 + 4 + 5}, min = -5 {-2-3}| Report Duplicate | Flag | PURGE
Deshaw Inc Algorithm - 2of 2 votes
AnswersWrite a function to detect the number of cycles in a directed graph. The graph is passed as an adjacency matrix.
- Anand Barnwal October 27, 2015 in India| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 2of 2 votes
AnswersThere are 10 coin producing machines which produces a coin of weight x grams. Out of those, 2 machines are defective and produces coins of x-1 grams. How to find those two defective machines.
- himanshu September 11, 2015 in India
Then extend this question to a total of n machines and out of those m machines are defective.| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Puzzle - 2of 2 votes
AnswersDesign and Implement a Telephone database structure in which a Customer Entry has PhoneNum,Name,Address.
- R@M3$H.N December 31, 2014 in United States
a) Given any PhoneNum return all the Customer details
b) Given any Name list all the Entries (As Name can be duplicate, only PhoneNum is unique)
c) Also Name searching should support Prefix Based.| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Algorithm - 2of 2 votes
AnswersDesign an iterator for a given stream of integers, with next() and hasnext() being called in any sequence, but skipping any 0's in the stream.
- duskan March 20, 2014 in United States for Ad| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm - 2of 2 votes
AnswersTest Google advertisements.
- kiranpm86 February 24, 2014 in India
Basically the expectation is to get the requirement, assume certain things and come up with test strategies.
E.g : UI, Backend, Compatibility, Accessibility etc.
On the fly question were asked| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Testing - 2of 2 votes
AnswersCreate a data structure that has fast insertion, removal, membership testing, and random selection.
- / February 21, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a graph that where A->B indicates that node A should be processed before processing B. Design an parallel algorithm to process all the nodes
- IntwPrep.MS January 17, 2014 in United States for Bing| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer - 2of 2 votes
AnswersDesign the backend for a Gmail-like mail system
- Steve September 14, 2012 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Application / UI Design - 2of 2 votes
AnswersDoes it always happen that stack always grows downwards & heap grows upwards?
- Aashish June 22, 2012 in India
If its so, then how does OS keeps the heap area protected from the interference of the stack & vice-versa?
If its not, then what factors affect it? OS version ? Compiler? Anything else??| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Operating System - 2of 2 votes
AnswersNext Sunday is Ayan’s 4th birthday and a lot of guests are invited for his birthday celebration. All of them are getting gifts for Ayan and his y-1 number of siblings. There are x number of guests coming to the party and each of them presented each kid some integer number of gifts (possibly zero). The guests are numbered with integers from 1 to x and all kids are numbered with integers from 1 to y. For all 1 ≤i ≤x the minimum number of gifts, which i-th guest presented to some kid is equal to gi and for all 1 ≤j ≤y the maximum number of gifts, which j-th kid received from some guest is equal to kj.
- anoophky September 06, 2019 in United States
Let ai,j be the number of gifts which the i-th guest give to the j-th kid. Then gi is equal exactly to the minimum among values ai,1,ai,2,…,ai,y and kj is equal exactly to the maximum among values g1,j,g2,j,…,gx,j.
You are interested in the minimum total number of gifts that guests could present, so you need to minimize the sum of ai,j for all (i,j) such that 1 ≤i ≤x and 1 ≤j ≤y. You are given the numbers g1,…,gx and k1,…,ky, determine this number.
Input Format
The first line contains two integers x and y, separated with space — the number of guests and kids, respectively (2≤x,y≤100000). The second line contains x integers g1,…,gx, separated by spaces — gi is equal to the minimum number of gifts, which i-th guest presented to some kid (0≤gi≤1000). The third line contains y integers k1,…,ky, separated by spaces — kj is equal to the maximum number of gifts, which j-th kid received from some guest (0≤kj≤1000).
Output Format
If the described situation is impossible, print −1. In another case, print the minimum total number of gifts, which guests could have presented and all conditions could have satisfied.
Sample Input
3 2
1 2 1
3 4
Sample Output
12| Report Duplicate | Flag | PURGE
- 2of 2 votes
AnswersGive m balls and n bins. Find out how many ways to assign balls to bins. Notice the buckets has no order. Like (1,2,3) and (3,2,1) are considered the same.
- aonecoding June 24, 2018 in United States
eg, m = 3, n = 2, return 2. (1, 2) and (3, 0)| Report Duplicate | Flag | PURGE
Amazon Software Developer - 2of 2 votes
Answersgiven two strings a and b.
- ajay.raj December 14, 2017 in United States
print out the minimum number of flips of the characters in a such
that a is an anagram of b.| Report Duplicate | Flag | PURGE
Google SDE1 - 2of 2 votes
AnswersRound 3
- aonecoding August 03, 2017 in United States
Given a matrix of 0s and 1s where 0 is wall and 1 is pathway, print the shortest path from the first row to the last row.
Can walk to the left, top, right, bottom at any given spot.
Follow-up:
If every pathway takes a cost (positive integer) to get through, print the minimum cost path from the first row to the last row.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersApple Map Team
- aonecoding July 25, 2017 in United States
1. Given an array A and some queries, query(i, j) returns the result of Ai*...*Aj, in other words the multiplication from Ai to Aj.
The numbers in A are non-negative.
Implement query(i, j).
2. Flatten nested linked list
3. POI search design
4. LC238 & LC279| Report Duplicate | Flag | PURGE
Apple Software Engineer Algorithm - 2of 2 votes
AnswersGiven infinite supply of coins of denominations 25, 10, 5 and 1, find the distinct number of ways to use the coins to sum up to the given value
- rajansthapit October 10, 2016 in United States| Report Duplicate | Flag | PURGE
Adobe Software Engineer Algorithm - 2of 2 votes
AnswersDesign a logging system. The system contains multiple application servers which are logging the information to file system. In this scenario, we want to check and alarm in case an exception is thrown in any of the servers. We want a system that checks for appearance of specific words, "Error", "Exception", "Disk Full" etc. in the logs of any of the servers. How would you design this system?
- jay September 17, 2016 in India
What if we want to scale the system in future?| Report Duplicate | Flag | PURGE
Amazon SDE-2 System Design - 2of 2 votes
AnswersFind the minimum (index) distance sum of 3 words. For example: arr = {"2", "1", "0", "2", "0", "3", "0"}, input = "1","2","3". The result should be 8 since the 2nd "2" and "1", "3"'s distance are 3, 1, 5 and abs(3,1)+abs(3,5)+abs(5,1)=8.
- lifeGoGoGo April 01, 2016 in United States
Implement this in O(N)| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 2of 2 votes
AnswersGiven an array of integers find the element for which the sum of left = sum of right. example -1 100 1 98 1 should return index of 1 i.e 2
Answer: First told him about Brute Force approach and then told him if we can iterate once and get the total sum
- Mumbaiya_Chori January 19, 2015 in India for Machine learningint findIndex(A){ int sum =0; for(int i =0;i<A.lenght;i++) { sum+= A[i]; } int lSum=0; for(int i=0;i<A.length;i++) { int rsum = sum - lsum-A[i]; if(lsum==rsum) return i; lsum += A[i]; } return -1; }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersTo deploy a module inside kernel, what are the possible methods.? Mention actual difference among them.
- mayur_nandurkar January 12, 2015 in India| Report Duplicate | Flag | PURGE
Developer Program Engineer Linux Kernel - 2of 2 votes
AnswersGiven a set of entries, each containing a time index and a int count value,
- FrickenHamster September 26, 2014 in United States
ie
class Entry
{
time:int
count:int
}
write a function that will give the time interval with the highest count together,
ie,
if we had entries
100, 2
100, 1
110, 10
200, 4
1000, 3
1200, 8
and we ran something like
int highestInterval(int interval_range)
highestInterval( 50 )
it would return 100, because in 100-150, you have counts 2, 1, and 10.
I managed to get a O(n^2) solution for it, but I think theres a better solution. I think it might have to do with some preprocessing of the interval buckets, but I can't figure out the solution.| Report Duplicate | Flag | PURGE
N/A Software Engineer / Developer Algorithm - 2of 2 votes
AnswersHow would you implement virtual functions in C
- iwanna September 24, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C#