# Engineering Interview Questions

Engineering interview questions shared by candidates

## Top Interview Questions

### Software Engineer at Google was asked...

How many rotations does earth make on its axis while going around the sun for one year. 10 AnswersDepends on the Leap Year or non Leap Year 365 for Non Leap Year 366 for Leap Year The question is flawed. It should either ask how many days earth takes in one revolution around sun, or how many days are in a year. The leap year is something imaginary humans have concocted to make the calendars look good. You can't say once is 4 years earth takes an extra day to go around the sun. It's to get you thinking about casting... the calender is a double casted to an int! Show more responses 365.25 / yr I wouldn't say 365/ 366 leap year. Jain has a point.^ It's either 364.25 or 366.25 depending on whether the earth spins in the same direction as it goes around the sun or not (I don't remember which it is and can't deduce it from the information that's available to me without looking it up). Imagine if the Earth did not spin at all on its axis so it would seem as if a year was equivalent to one day. It will take the Earth rotating either 264.24 or 366.25 times depending on the direction to seem like the 365.25 days that it does take. Every year it takes 365.25 rotations but while making calendar we ignore that 0.25 for 3 years and add an extra day in 4th year. <b>365.25 is WRONG!!!</b> Actually <b>Anonymous</b> is right! Just think about this (lay it out on your desk): <ul> <li>How many days would there be if the earth would not revolve around its axis?</li> <li>How many days would there be if it turned once around it's axis?</li> <li>Now do again one, change the direction the earth revolves it's axis, but keep going the same direction around the sun ...</li> </ul> The concrete right answer is 366.25 Here you find details on the exact number (with other proof): :) All answers here are false and crap. To say a leap day is added to look good is a lie. To say 365.25 rotations is also a lie because it is 365.25 days not rotations. It takes 366.25 rotations making the 365.25 days, so that in 4 years 1461 days are made by 1465 rotations. If the Earth rotated the opposite direction then the 366.25 rotations would make 367.25 days and the 1465 rotations would make 1469 days. Simple math, but the idiots rule the world, while retarded ones worse than the idiots try to play smarter and CAN'T. Same as with Venus it takes 1.62509035863 orbits to make 0.62509035863 synod. Mathematical geometry that all cycles differ by exactly ONE. (Like the 366.2422 to produce 365.2422, and the 366.2425 to produce the 365.2425, and the 366.25 to produce the 365.25 and this is why Venus takes 1.62509035863 of 224.606267349 days to make 0.62509035863 of 583.924347116 so that if the math is not an exact balance then you have the wrong figures. 1+fractional A times one orbit = fractional A times one synod. And so 13 orbits around the sun appear from Earth as 5 times around the sun. Or more precisely when the math is checked to be exactly equal by this LAW that I discover, 13 orbits will appear as 5.00044481781 synods as seen from Earth, and 5 synods (superior conjunctions) will be 12.9988435764 orbits. This question makes no sense. It's other way around, only when earth complete one round, we call it a year. To make human calculations easy, we introduced leap yrs. |

out of 25 horses select the fastest three in minimum number of races where in each race there would be exactly five horses. 10 Answers6 races i think it could be 6 races... first five races taking 5 horses each,and then the 6th ace taking the 1st horse of each of the previous race,den select the fastest three among them. would be 5 races if a stop watch is given..... however solutions given before are wrong since the horse coming 2nd in the first race might be faster than the horses that come first in the subsequent race :) hence we have to assume that a timer is provided Show more responses umesh no timer has been provided and it would be 7 races :) 11 races First 5 races taking 5 horses in each race. Next 5 races taking in each race horses which have come first, horses which have come second, third, fourth and fifth....... Final 11th race out of 5 which have won in second set of races to find fastest 3 6 Race would be wrong answer. What if in one group all the 5 horses are fastest of all others. Then from first round of 5 races we might lose those 2nd and 3rd ones. My answer is also 11 Races. Round one - 5 Races -------------------- Including all 25 horses. 5 each race. Left with -> 15 horses [Take 1st,2nd & 3rd from each race. Which would be total of 5*3=15 horses.] Round two - 3 Races [ Grouping any 5 of 15 horses left] ------------------- Left with -> 9 horses [Take 1st,2nd & 3rd from each race. which would be total of 3*3=9 horses.] Round three - 1 Race. ---------------- Take any 5 horses of 9 horses left Left with -> 7 horses 3 (1st 2nd and 3rd) + 4 (remaining ones) = 7 horses Round four - 1 Race. ---------------- Take any 5 out of 7 Left with -> 5 Round Five - 1 Race ---------- Race of 5 horses left 7 races: Split the 25 into 5 groups and make them race, this would be 5 races. Take the fastest horse of each group and make them race (6th race). Let's label the initial group of the top 3 horses of the 6th as a, b, c. The possible candidate for the 3 fastest are: a[1], a[2], a[3], b[1], b[2], c[1] We just need one last race to determine the top, the race would be between a[2], a[3], b[1], b[2], c[1]. The final result is a[1] then the top 2 of the 7th race. Easy: Correct answer is 11 but much easier method: 1. One race among 5 horses to find the fastest 3. 20 horses left not raced yet. 2. Now keep the 3 fastest horses you found and add two other horses out of 20 horses left to the race, again select the fastest 3. 3. Keep doing this for all 20 horses by selecting 2 of the horses left to race against the fastest 3 always. 1 race (to find the fastest 3) + 10 races (20/2 races to test all other 20 horses) = 11 races Constant Time - 7 Races 5 Races among 5 each. 6th Race for all third place holders 7th Race for Winner of sixth race +two people who defeated him in 1st race + two people who defeated the second place winner in 6th race. Best Case - 6 Races (3 place winner of 1st race against other 20 and he wins all the time) Worst Case - 11 Races( Make the fastest 3 of each race run against the other 2 each time) |

### Senior Software Engineer at Amazon was asked...

You are given a fixed number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps. Now given an amount for sending a parcel, you should design an algorithm to come out with the minimum number of stamps that should be used for attaining that amount. For example, if the parcel costed 30 rupees, it could be attained using one 20 rupee stamp and one 10 rupee stamp OR using three 10 rupee stamps OR using one 20 rupee stamp and two 5 rupee stamps OR using one 10 rupee stamp and four 5 rupee stamps OR using two 10 rupee stamps and two 5 rupee stamps. However, the minimum number of stamps is the case of one 20 rupee stamp and one 10 rupee stamp where only two stamps are used. The case where no solution is possible should also be handled, for example, a parcel amount of exactly 33 rupees cannot be attained. 9 AnswersThe solution is attained using dynamic programming. The basic idea is that the minimum number of stamps used for attaining an amount x, is 1+minimum of (minimum number of stamps for attaining x-5, minimum number of stamps for attaining x-10, minimum number of stamps for attaining x-20,minimum number of stamps for attaining x-50). You can try to solve this first by assuming that an unlimited number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps are available. And then you can take into account that only a fixed number of these stamps are available. And what is the time involved to get this done? I really liked the question.Simple to read but involves good amount of logic. I ve written down the algorithm but i believe i took more time than i initially thought i would take. I understand what the interviewer is trying to test and I know how to solve it, but what about more realistic scenario where parcel postage cost would be beyond given values like 3 units of currency or 37 units of currency. Show more responses In this specific case, dynamic programming is overkill. There's a better optimal substructure here: The stamp with greatest value less than parcel cost minus stamp values already committed minimize the total of stamps. 1. find the stamp <= cost from highest stamp cost 2. num of found_stamp = found_stamp/cost, rem_stamp = found_stamp % cost 3. Do 1, then 2 until rem_stamp ==0 (done) or rem_stamp < least stamp available (not possible case) In the previous ans, after step 3 if rem_stamp !=0, go back to step 1, find next_stamp < cost (but smaller than value of found_stamp in previous iteration) i=0; boolean solPossible = false; do { if(cost % notes[i] == 0) solPossible = true; else i++; } while(!solPossible && (i void sendParsal(int cost) { int[] avlstm={50,20,10,5}; int i=0; while(cost>=5) { while(cost>=avlstm[i]) { System.out.println(avlstm[i]); cost=cost-avlstm[i]; } i++; } if(cost!=0) { System.out.println("Solution not possible."); } } void Foo(int cost) { if (cost % 5 != 0) Console.WriteLine("Not possible"); else if (cost stampCosts = new List() { 50, 20, 10, 5 }; int count = 0; while (cost > 0) foreach (int stampCost in stamptCosts) if (cost >= stampCpst) { cost -= stampCost; Console.WriteLine("Stamp: " + stampCost); count++; break; } } Console.WriteLine("Count: " + count); } |

### Software Engineer at Google was asked...

Can't disclose the exact question because of NDA, but here's some food for thought: 3 can be written as 1+1+1, 1+2, 2+1 4 can be written as 1+1+1+1, 1+1+2, 2+2, 1+2+1, 2+1+1, 3+1, 1+3 Given an integer, how many possible expressions exist? (1+2 and 2+1 are different) 8 AnswersThere are total 2 ^(n-1)-1 expressions exist for any integer to be written on the basis of integers < the given Integer. Like for n=3, total 2^(3-1)-1= 3 expressions. For 4, 7 expressions exist and so on. No f(1) = 0 f(2) = 1 f(n) = Σf(i) + (n-1), where i = 1 to n-1, n>2 Show more responses Ader Lee: Shouldn't it be: f(n) = Σf(i) + (n-1), , where i = 1 to n-2, n>2 (i ranges from 1 to n-2, not n-1) f(1) = 0 and f(i) = i - 1 + sum_{i = 0}^{i - 1} f(i) Writing it down helps to find the sum: f(1) = 0(0) f(2) = 1 + 0(1) f(3) = 2 + 1 + 0(3) f(4) = 3 + 3 + 1 + 0(7) f(5) = 4 + 7 + 3 + 1 + 0(15) The first term(i - 1) equals the number of second terms and the second terms are the sum of 2 powers - 1 from 0 to (i - 2) so f(i) = 2^{i - 1} - 1 Also there is a neat normal form to generate all variations. For the sake of simplicity I show it for i = 4: Start from 1 + 1 + 1 + 1 and for j in 1 to i - 1 add together j and (j + 1) and write down the numbers and mark the added number in the next iteration. | | | 2 + 1 + 1 1 + 2 + 1 1 + 1 + 2 From the marked numbers to (last - 1) run j and do the same as before. The first generates 2 more, the second 1 more and the last one none. gen by first | | 3 + 1 2 + 2 gen by second: | 1 + 3 We could also generate the one element sum(4) from the first one but it's not needed in the problem. Also this representation looks nicer in a tree form but I can only type text here. The marks moved to the begining of the rows since the forum probably has some nice mangling algorithm. I hope you can figure out how the normalisation works. Might post some python code which does this later. a coin change problem with little modification will do . |

The most surprising part was that i was even asked questions about the basic electronics in the interview round as my branch was ECE... 6 AnswersIn the aptitude round... we had two cut-offs.. one was sectional and the other was overall cut off. For this post be thoroughly prepared with C, C++, sql, DBMS, puzzles Hi... i want to know about the date of this interview, and how much time they take to give response after HR round?? This was interview was held on 22nd September,2013. They took about 3 days after the HR round to respond back. Show more responses Thanks.. i also gave hr interview on 22sep but havn't received their call till now. Does thi mean i am not selected??? or they will call me for 2nd batch after sometime??? any idea?? No idea... |

### Software Engineer at Google was asked...

Given n numbers (P1,P2,P3,.....Pn). Divide them in m contiguous partitions such that the sum of the maximum is minimum. For e.g. (5,1,4,2,3) and m =2 then (5,1)(4,2,3) 7 AnswersWas not able to solve this. But some guys used DP. Need to try all options according to m, Can be referred as spanning tree in depth of M. The leaf of the tree will hold the combination of the indexes that we've decided to divide by and than we can compute the min sum and choose the correct leaf Assume they are all integers? Get the sum and divide by m. Then try to get sum that can get the exact same value. If can't increase m by 1, try again, until find. Show more responses Binary search can be used to solve this. Let consider d[ i ][ j ] is solution of the problem when S = {s1, ..., si } and k = j. So it is easy to see that: d[ 0 ][ j ] = 0 for each j from 1 to k d[ i ][ 1 ] = sum(s1...si) for each i from 1 to n d[ i ][ j ] = minfor t = 1 to i (max ( d[i - t][j - 1], sum(si - t + 1...si)) for i = 1 to n and j = 2 to k Now let's see why this works: When there is no elements in the sequence it is clear that only one interval there can be (an empty one) and sum of its elements is 0. That's why d[ 0 ][ j ] = 0 for all j from 1 to k. When only one interval there can be, it is clear that solution is sum of all elements of the sequence. So d[ i ][ 1 ] = sum(s1...si). Now let's consider there are i elements in the sequence and number of intervals is j, we can assume that last interval is (si - t + 1...si) where t is positive integer not greater than i, so in that case solution is max ( d[i - t][j - 1], sum(si - t + 1...si), but as we want the solution be minimal we should chose t such to minimize it, so we will get minfor t = 1 to i (max ( d[i - t][j - 1], sum(si - t + 1...si)). Example: S = (5,4,1,12), k = 2 d[0][1] = 0, d[0][2] = 0 d[1][1] = 5, d[1][2] = 5 d[2][1] = 9, d[2][2] = 5 d[3][1] = 10, d[3][2] = 5 d[4][1] = 22, d[4][2] = 12 Code: #include #include #include using namespace std; int main () { int n; const int INF = 2 * 1000 * 1000 * 1000; cin >> n; vector s(n + 1); for(int i = 1; i > s[i]; vector first_sum(n + 1, 0); for(int i = 1; i > k; vector > d(n + 1); for(int i = 0; i <= n; ++i) d[i].resize(k + 1); //point 1 for(int j = 0; j <= k; ++j) d[0][j] = 0; //point 2 for(int i = 1; i <= n; ++i) d[i][1] = d[i - 1][1] + s[i]; //sum of integers from s[1] to s[i] //point 3 for(int i = 1; i <= n; ++i) for(int j = 2; j <= k; ++j) { d[i][j] = INF; for(int t = 1; t <= i; ++t) d[i][j] = min(d[i][j], max(d[i - t][j - 1], first_sum[i] - first_sum[i - t])); } cout << d[n][k] << endl; return 0; See Skiena's algorithm book. Dynamic programming chapter has this linear partition problem. Binary search the result and greedy check if it is obtainable. |

what is the HD? 7 AnswersHigh degination its HIGH DEFINATION high definition Show more responses high defination high defination high definition digital satellite tv channels Hard Drive, given the fact that the question is, "what is THE HD?" indicates that the interviewer is asking for an object. |

Find all anagrams in a file. Improve the running time to O(n). 7 Answersfor each work in the file, sort the letters in the work and add the result into a stack, if there is a collision, the original word is part of set whose words in that set is an anagram. Since adding to a stack only take O(1) and you must visit each word once, the complexity is O(n). The way I approach anagrams is that I assign a prime number to each letter and then multiply the letters. In theory, ABC gives you say 3 * 5 * 7 = 105 Any anagram will have letters that when multiplied give you 105. In the solution above, it's far more than O(n) because of the sort step which depending on how you're trying to sort could wind up nlogn or n2 or something like that. I should note that this is generally good to about 9 characters, at which point overflowing becomes an issue and you'll probably want to go to some construct such as BigInteger in Java or go with what Anonymous presented. Show more responses @SeanB: Instead of multiplying number just add them. Adding won't cause a big value for stack overflow or something.(e.g A=1, a=1: b=2, B=2...so on.) Rule of Association in maths. That would do. However even for multiplying or adding we have to split the string which will involve some complexity, therefore that might not make the whole operation o(n). @SeanB, thats good idea, adding to that: we can map a prime number for each alphabet. if any string has same multiplied product then both should be anagram. For example: Map the first 26 prime numbers to "abcd....xyz" "1, 3, 5, 7, 9, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" now consider the anagram: "cinema" and "iceman" the product of the two numbers will be same. Since we use prime numbers, the factors should be same. so its proved that both are anagrams. To check overflow: 97 is for the char "z", and usual word size is 10. So, Math.pow(9, 10) is 73742412689492830000 and which still finite. @Jimmy: There is a small flaw in your assumption. Let's say we take the prime number sequence as 1, 2, 3, 5, 7,,, assigned to A, B, C, D, E etc Your assumption would give out the same answer for "BC" and "D". But these two are two not anagrams. So i guess i better approach would be to multiply the numbers. 1 is not prime man |

Classix 2 eggs problem . * You are given 2 eggs. * You have access to a 100-storey building. * Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical. * You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking. * Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process 6 AnswersThis is a BS question to begin with bc gravity will max the egg's speed out at 9.8m per second, whether it be the 1st or 100th floor. BUT, I know what they are intending to ask... The answer is 14. n(n+1)/2 9.8m/sec^2 is the acceleration due to gravity, not velocity. No falling object can ever achieve terminal velocity, as you incorrectly stated. Secondly, although your answer is correct, your formula is wrong. The general form is ceiling[ (sqrt(8n+1)-1) / 2], with n = # of stories. use first egg to reduce the problem half size and then use second egg progressively to find answer. 100/2 then 50/2 then 25/2 then 13/2 then 7/2 then 4/2 then2/2 but while you start start dropping in reverse order from first, second... Show more responses use first egg to reduce the problem half size and then use second egg progressively to find answer. 100/2 then 50/2 then 25/2 then 13/2 then 7/2 then 4/2 then2/2 but while you start start dropping in reverse order from first, second... Otherwise simple mathematical inequality eqn q(q+1)/2>=100 will solve the problem. Lets assume you divide the floors into y partitions of size x each. The least value of y gives the best solution: here, x^y +x-1 =99 for the worst case best satisfactory ans. The problem is harder as you are only allowed to throw 2 eggs. Thus, the second throw operation is a linear operation. Thus, the problem is reduced to finding a solution which requires minimum number for 2nd linear throw. Let's say that x is the optimal number of throws required. And, for time being let's say x=20. Then, You would do the first throw from 20th floor and if egg breaks you would do a linear operation of throws from 1st to 20th floor to find which floor the egg breaks. However, if the egg doesn't break then you will throw from 39th floor, as you are now one throw less. Following this logic 20 39 57 73 88 102 but you only have 100 floors thus this is not the right answer. x + (x-1) + (x-2) + ... + 1 = 100 x(x+1)/2=100 which gives x=14 which is the optimal number of throws required. |

### Software Engineer I at Adobe was asked...

Puzzle question: A Floating ship contains 1 stone , If I drop that stone in sea,,What will happen with water level??? Is it increase or decrease n why?? 8 Answersafter long discussion... concluded that it will decrease.. nothing will happen even i feel nothing will happen to the level.plz explain the ans. Show more responses Level will decrease Yes It will decrease, as per Arcemedes object with same masses upward buoyant force is higher for object which has larger volume area, so when stone is on boat, it increase boat weight and so upward buoyant force is high for boat, but when It is thrown its upward buoyant force is less with compare to when it is on boat, and upward buoyant force of boat also decreases because stone is thrown, so ultimately upward buoyant force decrease than means decrease in water level, hope it will help :) I think it will decrease as when the stone is on the boat the volume of water it displaces is more than when it is thrown into the sea. as more volume of water is displaced the more water level goes up we can say that water level will be higher when the stone is on the boat. The amount of water displaced is equal to the mass of the object immersed. Since the net mass of objects in water is the same, the same amount of water needs to be displaced. Hence no change in the water level. It solely depends upon the density of stone. If density of stone is higher than boat material then it will increase the water level .. Otherwise decrease |

**11**–

**20**of

**77,156**Interview Questions

## See Interview Questions for Similar Jobs

- Senior Software Engineer
- Software Developer
- Associate Software Engineer
- Java Developer
- Software Development Engineer
- Intern
- Analyst
- Business Analyst
- Consultant
- Technical Lead
- Trainee Software Engineer
- Engineer
- Software Development Engineer II
- Systems Engineer
- Fresher
- Technical Support Engineer
- QA Engineer
- Software Engineer II
- Associate
- Project Manager