Software Engineer Interview Questions
- 1of 1 vote
AnswersGiven a number N, write all possible sums of consecutive numbers that add up to N.
- tamashionuth January 02, 2016 in United States
That is:
return all pairs (a, k) such that a+(a+1)+...+(a+k)=n
After that:
1. what if N is negative or a is negative;
2. what if N is real and the possible implications of this| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 0of 0 votes
AnswersHow would you convert a row number on Excel to a label? Rows are labeled alphabetically with letters added on once the alphabet has been fully used. (Ex. row # 5 is labeled E, row # 27 is labeled AA, row # 28 is AB, row # 53 is BA and so forth) What would the row label be for a large number, such as 1500?
- popeye123 January 02, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Problem Solving - 2of 2 votes
AnswersGiven an undirected graph and a node, modify the graph into a directed graph such that, any path leads to one particular node.
- neer.1304 December 25, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 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 - 1of 1 vote
Answerscreate palindrome in javascript, by appending a minimum set of characters at the end.. eg. test => testset
- codebind December 19, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersGiven an array of five integers that represents a poker hand e.g. [2,2,2,3,3] return the value of the hand, valid values are only "pair","two pairs","three of a kind","full house","four of a kind" we don't have to worry about straight, flush or straight flush.
- DanOG99 December 15, 2015 in United States
My approach was to have a fixed array of 13 elements (each element represents one possible value of the hand) this array will keep the occurrence of each value of our hand and after we have all the values we just iterate this array and multiply all the values by itself and adding them to get a unique result.
For example if we have [2,2,3,4,5] our fixed array will have a "2" and three "1" so our result will be "2*2+1*1+1*1+1*1",the result will be 7, so all the possible hands will have unique values, if we find a 7 as a result we will know it is a pair, a 9 will be two pairs, a 11 will be three of a kind, 13 will be a full house and 17 will be a four of a kind.
This algorithm is O(1) both in complexity and space but the interviewer didn't like it too much.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 1of 1 vote
AnswersGiven integer k and a subset S of set {0, 1, 2, ..., 2^k - 1}
- emb December 13, 2015 in United States
Return the count of pairs (a, b) where a and b are from S and (a < b) and (a & b == a)
& here is bit-wise and.
Do it faster than O((2^k)^2), assume k <= 16
Example:
0b111
0b101
0b010
Answer: 2
0b110
0b011
0b101
Answer: 0| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven an array of words (i.e. ["ABCW", "BAZ", "FOO", "BAR", "XTFN", "ABCDEF"]), find the max value of length(s) * length(t), where s and t are words from the array. The catch here is that the two words cannot share any characters.
- supatroopa December 13, 2015 in United States
Assume that there are many words in the array (N words) and average length of word is M.
Answer for the example above is "ABCW" and "XTFN" as the result is 4 * 4 = 12.
"ABCW" and "ABCDEF" do not work since they share similar characters.| Report Duplicate | Flag | PURGE
Google Software Engineer - 2of 2 votes
AnswersYou know result of a soccer match, print all the possible ways that this game ends up with this result.
- u-11i24223 December 01, 2015 in United States
Example: final score 1 - 1:
0 - 0
0 - 1
1 - 1
0 - 0
1 - 0
1 - 1
Another example if the final score is 2 - 3 there are many possibilities for reaching to that score:
2 - 3
0 - 0
1 - 0
2 - 0
2 - 1
2 - 2
2 - 3
0 - 0
1 - 0
1 - 1
1 - 2
2 - 2
2 - 3
0 - 0
0 - 1
0 - 2
0 - 3
...| Report Duplicate | Flag | PURGE
unknown Software Engineer Algorithm - 0of 0 votes
AnswersImagine you have a row of numbers like below(a traiangle) .By starting at the top of the triangle find the maximum number in each line and sum them up example below
- Avinash Paritala November 25, 2015 in India
5
9 6
4 6 8
8 7 15
Answer I.e. 5+9+8+7 = 29
writw a code to find the maximum total from top to bottom. Assume triangle can have at most 100000 rows.
Input Output specifications
Input Specification
A string of n numbers (where 0<=n<=10^10)
eg.5#9#6#4#6#8#0#7#1#5
Output Specification
A sum of the max numbers in each line (as string ) or Output invalid in case of invalid input/triangle
Examples
eg1.
Input :5#9#6#4#6#8#0#7#1#5
Output:29
eg 2 .
Input :5#9#6#4#6#8#0#7#1
Output:invalid
eg 2 .
Input :5#9##4#6#8#0#7#1
Output:invalid| Report Duplicate | Flag | PURGE
Google Software Engineer - 5of 5 votes
AnswersGiven N balloons, if you burst ith balloon you get Ai−1∗Ai∗Ai+1 coins and then (i-1)th and (i+1)th balloons become adjacent. Find maximum number of coins you can gather.
- dp November 25, 2015 in United States
Assume that we have extra 1 at left most and right most positions. (don't take in answer just for boundary positions)
Hence if we have left or right boundary positions we multiply 1.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersAt regular interval, we are receiving data (Price,Quantity). We need to find Most Sold Price(MSP). Need to design the solution to print the current MSP with total Qty of that price, every time a set of price and its quantity sold is provided as input.
Time Price Qty MSP(Total Qty) 11:01AM $10.01 100 $10.01(100) 11:03AM $11.01 200 $11.01(200) 11:04AM $12.81 150 $11.01(200) 11:06AM $10.01 210 $10.01(310) 11:07AM $10.01 180 $10.01(490) 11:08AM $12.81 400 $12.81(550) 11:09AM $11.01 200 $12.81(550)
In the interview, I wrote a solution using priority queue where each element of the priority queue is a tuple consisting of price and quantity. The priority queue arranges itself based on the quantity value of each tuple. When new value comes we access the tuple having the particular price, retrieve its quantity. Delete this tuple and insert a new tuple with the same price and updated quantity.
- Edd November 24, 2015 in United States
The interviewer was not satisfied with the solution and commented this is not how a large scale application will be build which is running throughout the day.| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersWrite a bitmap class where we don’t have fixed size for the bitmap. Calculate the changed bits from previous instance to new instance in least iteration.
- johnsvakel November 24, 2015 in India for GFS
Real-time usage : In file systems we will scan only those parts changed from last save to new edit. At that time this bitmap should be used to scan the changed/added/removed parts.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersBest Time To Sell Stock but with 1 restriction: after you sell your stock, you cannot buy stock on next day.
- Ray November 21, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersDesign a locking mechanism for a distributed system .
- Ray November 21, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Software Design - -1of 1 vote
AnswersTwo political parties are contesting in the elections in the N number of states in the country. Each party wins some seats every year in each state. After the current elections are over we have the result of both the parties with their number of seats won in each state.
- Avinash Paritala November 21, 2015 in India
The two parties are considered equal if they win the same number of seats in the N states in any order. Otherwise, they are considered unequal. Input/Output Specifications
INPUT: 1) It is an array of N integers depicting number of seats won by party one in each state. 2) It is an array of N integers depicting number of seats won by party two in each state. 3) An integer containing number of states (N).
OUTPUT: Equal/Unequal/Invalid
Equal: if political parties are equal Unequal: if political parties are unequal Invalid: if any party has invalid number of seats in any state
Examples
Example 1:
Two parties contested in seven states Seats won by party one in all the seven states: {12,11,5,2,7,5,-11} Seats won by party two in all the seven states: {5,12,5,7,11,2,11} The party two has an invalid number of winning seats(-11). So the output will be "Invalid".
Input :
1) {12,11,5,2,7,5,-11}
2) {5,12,5,7,11,2,11}
3) 7
Output: Invalid
Example 2:
Two parties contested in seven states Seats won by party one in all the seven states: {12,11,5,2,7,5,11} Seats won by party two in all the seven states: {5,12,5,7,11,2,11} Both the parties are equal because they have got 11(2 times each), 5(2 times each),7( 1 time each), 2(1 time each), 12( 1 time each other outputs (0 times each).
Input :
1) {12,11,5,2,7,5,11}
2) {5,12,5,7,11,2,11}
3) 7
Output: Equal
Example 3:
Input :
{12,11,5,2,7,5,11}
{5,0,5,7,11,2,11}
7
Output: Unequal| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 4 votes
AnswersGiven that you have a graph with an even number of points, how do you find two points that equally subdivide the graph?
- Ray November 21, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersRahul is playing a very interesting game. He has some N different type of match boxes. All match boxes may have different number of matchsticks (S1, S2, S3... Sn).
- Avinash Paritala November 19, 2015 in India
Rahul chooses two random numbers F and K. K should be less than N. The game is that Rahul wants to select any K match boxes out of N match boxes such that total number of matchsticks in these K selected match boxes should be multiple of F.
At the sametime Rahul wants that sum matchsticks of all the selected match boxes should be minimum possible.
Input Specifications:
1) Array S = {S1,S2,S3,...Sn} of size N corresponding to the number of match sticks in N matchboxes(0<=N<=1000}
2) F-Value (as explained above)
3) K-Value ( as explained above)
Output:
1 2 3 4 5 Here 3 is the number of matchsticks in matchbox I II III IV V minimum possible total number of matchsticks such that the conditioned explained in the problem statement is satisfied. Output -1 if it is not possible or invalid input.
For example, there are 5 match boxes i.e., N = 5
Let's say K is 3 (Rahul has to choose any 3 matchboxes)
Let's say F is 5(sum of matchsticks in 3 selected matchboxes should be multiple of 5).
Rahul can choose II, III and V matchboxes which would give the total sum of 10 which is multiple of F i.e., 5. And 10 is the minimum possible matchsticks possible in the above case.
So you have to answer the minimum possible matchstick(sum of the matchsticks in the selcted matchboxes) but the conditions given above should be satisfied.| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersYou have a memory location. It is actually a character array abc... upto z .
- ahmad.husain.khan November 17, 2015 in India
I have a integer pointer p pointing to a ie the first character of the array.
How do I print the character array using the integer pointer ?| Report Duplicate | Flag | PURGE
HCL Software Engineer C - 0of 0 votes
AnswersGiven an array of integers of unknown size, how to reverse the order of the positive integers?
- ur2cdanger November 16, 2015 in United States
Ex [4 3 8 9 -2 6 10 13 -1 2 3 .. ] =>
[ 9 8 3 4 -2 13 10 6 -1 3 2]| Report Duplicate | Flag | PURGE
unknown Software Engineer Algorithm - 0of 0 votes
AnswersGiven an active stream of sorted arrays, how would you merge them efficiently?
- Ray November 14, 2015 in Canada| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven a character limit and a message, split the message up into annotated chunks without cutting words as, for example when sending the SMS "Hi Sivasrinivas, your Uber is arriving now!" with char limit 25, you should get
- sivasrinivas November 14, 2015 in United States
["Hi Sivasrinivas,(1/3)", "your Uber is arriving(2/3)", "now!(3/3)"]| Report Duplicate | Flag | PURGE
Uber Software Engineer Algorithm - 1of 1 vote
AnswersGiven the two objects below, implement the methods defined in the Phonebook class. This is a simulated phonebook. You should expect LookupByName and LookupByPhoneNumber to be called much more often than AddPerson. Also, this is a multi-threaded simulation so your implementations of the functions other than the constructor should be threadsafe. Feel free to rewrite this in any language of your
choice.
- Surya November 10, 2015 in United States for Cloud servicespublic struct Person { string name; string phoneNumber; } public class Phonebook { public Phonebook (List<Person> people) { } public Person LookupByName(string name) { } public person LookupByphoneNumber(string phoneNumber) { } public void Addperson(person person) { } }
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Threads - 0of 0 votes
AnswersGive a Barrel a position say X.
- sudhiaithal November 07, 2015 in United States
Barrel can pushed left or right with equal probability.
A single push to left side will place the barrel to left of X and push to right will place the barrel to right of X.
After 10 pushes (either left or right with equal probability) what is the probability that barrel will be back to the same position X ?
Write a code or derive mathematically.| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 0of 2 votes
AnswersGiven a string of characters, find the longest legal word. A generic method to check word legality is given.
- tgerg2009@my.fit.edu November 06, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer - 5of 5 votes
AnswersGiven an infinite stream of characters and a list L of strings, create a function that calls an external API when a word in L is recognized during the processing of the stream.
- ragmo2223 November 05, 2015 in United States
Example:
L = ["ok","test","one","try","trying"]
stream = a,b,c,o,k,d,e,f,t,r,y,i,n,g.............
the call to external API (let's call it some function callAPI()) would be called when the 'k' is encountered, again when the 'y' is encountered, and again at 'g'.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 5of 5 votes
AnswersGiven a prime set, we call "prime expressible" if a number can be factorized only using given prime numbers. Find n-th big expressible number.
- pandacoder October 30, 2015 in United States
E.g., prime set = {2, 3}
expressible number = {1,2,3,4,6,8, 9, 12...}
non-expressible number = {5, 10... }
The primes in the prime set are ordered in an increasing order, and can include a prime < 10^4 (don't remember the exact range), and n can also be as large as 1-10^6.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven an array of both positive and negative integers , find all pairs whose sum is equal to zero.
- sudhiaithal October 30, 2015 in United States| Report Duplicate | Flag | PURGE
xyz Software Engineer Algorithm Arrays - 2of 2 votes
AnswersGiven a dictionary containing a list of words, a starting word, and an ending word, return the minimum number of steps to transform the starting word into the ending word.
- ixnay October 28, 2015 in United States
A step involves changing one letter at a time to a valid word that is present in the dictionary.
Return null if it is impossible to transform the starting word into the ending word using the dictionary.
Example:
Starting word: cat
Ending word: dog
cat -> cot -> cog -> dog ('cot' and 'cog' are in the dictionary)
return 3| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm