Programming Interview Questions | Glassdoor

# Programming Interview Questions

12,267

Programming interview questions shared by candidates

## Top Interview Questions

Sort: Relevance Popular Date

Apr 2, 2012

### Q & A Analyst Training Program at Eze Software was asked...

Apr 26, 2010
 Scenario: You have 8 golf balls and 1 is heavier than the 7 others. All you have is a balance used in chemistry classes. What is the shortest number of times you could measure the golf balls to find the heaviest ball? 5 Answers You have to keep in mind that you're dividing up the balls. They try to confuse you, but just ignore the people and stick to your intuition. The quickest way to discover the heaviest ball was in 2 steps. i would say three. you could put 4 balls on each side and then take the heavier side. split that group into two balls on each side. then lastly split that group to have one ball on each side. i would say three. you could put 4 balls on each side and then take the heavier side. split that group into two balls on each side. then lastly split that group to have one ball on each side. Show More Responses 2 steps. 1. Put 3 balls on each side of the scale measure( [123], [456] ) If each group of 3 is equal: 2. Place the remaining two balls on the scale - measure( [7], [8] ) If each group of 3 is not equal: assuming [123] is heavier than [456] 2. Take 2 balls from the heavier group from step 1 and place them on the scale. measure( [1], [2] ) If they are equal then [3] is the heaviest 3 v. 3 Case 1: Heavier ball lies within the first 3v3 weighing. Weigh 2 of the balls on the heavier side. Either one is heavier or they balance. If they balance, then it's the 3rd one we didn't weigh. Done. Case 2: 3v3 balances. Then the heavier ball lies within the other 3 not weighed. Weigh 1v1, either it balances or it doesn't. If it doesn't, we're done because we can see that one side is heavier. If it does, then it's the third one not being weighed. Minimum amount of weighings is 2.

### Program Manager at Microsoft was asked...

Oct 22, 2012
 Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum. 4 Answers This is an extension of the problem of finding the subsequence of an array with largest sum. In that problem, you keep a running sum of all the previous elements for each element of the array, then the sequence of the largest sum is the subsequence between the smallest running sum and the largest sum. Similar idea can be applied to this problem with somewhat a big modification. First, for element at index (i, j), you keep a sum of all elements in the sub matrix (0...i, 0...j). Then, you keep another running sum at index (m, n) of elements (x, y) s.t. {x < m or y < n}. (The l shaped union of the horizontal band (0-n) and vertical band (0-m)). This gives you that sum(m...i, n...j)= submatrix_sum(i, j) - bands_sum(m, n). Now, find the largest value of submatrix_sum(i, j) and then the smallest bands_sum(m, n) such that m,n are in the sub matrix (0...i, 0...j). The answer is the submatrix (m...i, j...n). Running time should be O(n^2) Actually above answer is wrong...needs correction. It really depends whether the matrix must be a A*A matrix or just can include the "relevant" numbers (i.e., only eliminate the "problematic" numbers) I asume the later is required. So - We need to go over the matrix and drop the "0"-s it will cost us O(n) We need to check how many negative numbers are there - we need a pair number so if we have an odd one we will drop the smallest one Now, the remaining numbers give us the max number. Show More Responses Whatever your solution is, make sure it runs in O(n^4) time. If you get O(n^6), its ok but it is not what they want. The O(n^4) solution can reduce to O(1) in the best case. (I'm also kind of tired of typing my solutions in, figure it out yourself if you are interested).

### Technical Program Manager at Amazon was asked...

Jan 6, 2012
 What is the hardest thing in moving a team to Agile? 5 Answers Not hard but varies so speak to your experience, there is not right answer for this. Personalities and level of comfort of the development staff. Some team members can resist change they don't understand. The key is in presentation of the core of Agile/Scrum and not in the buzzwords or trendiness - emphasize the minimized reaction to positive developments and test/missed Architecture or requirements, the daily standups being the only real hassle, etc. You pitch it to the team member's values and sense of worth, as being an improvement to empower the coder and add worth. The next hardest thing is convincing a skeptical management, PMO, Systems Engineering staff, and probably best to not mention it to the Customer for a release or two. It's the people. Getting them to understand the Agile concept, then utilize it. Some developers never get "Fluid Requirements". They want final requirements and that's it. Show More Responses 1. Communication. Frequent communication from the developers to ensure problems are raised and solved 2. Team needs to learn how to ship products with low-pri bugs - New team (everyone is still forming, norming, storming) so hard to estimate and collaborate - Distributed team members (works best if teams are collocated) - Strong, individual performers. Agile is about team work. - Not having a product owner - etc.

### Software Edison Engineering Development Program at GE Healthcare was asked...

Jun 8, 2012
 Given the following terms please draw a logical diagram/hierarchy on the board as you see fit. Dog, Cat, Woof, Animal, Fifi, Run 3 Answers This tests your knowledge of inheritance and basic object oriented structure. what was your answer? animal, dog, cat, woof, run,fifi? The correct answer to this question is as follows: Animal is the base class Animal has the abstract method Run Dog and Cat both inherit from Animal Dog has the method woof Fifi could either be an instance of the dog/cat class or it could be a name attribute.

### Technical Program Manager at Amazon was asked...

Jul 9, 2011
 Given two arrays find all the points of intersection between the (i.e. equal elements) and return them in an array. 4 Answers couple of solutions - sort the array (nlogn) complexity - browse with the smaller array and visit each of the bigger array and return if there is a match. Complexity (n square) thus not a good solution next solution - sort the arrays and remove duplicates (nlogn) - create a table, with the longer array - browse to the smaller array and update the count - use a hashtable. O(n). traverse first array: O(n) put elements into hashtable: O(1) traverse through second array: O(m) check for existence of element in hashtable: O(1) if yes, add to resultant array. return resultant array So, final time complexity is O(n) Show More Responses def intersect(a1, a2): return [x for x in a1 if x in a2] One-liner in Python

Jan 24, 2012

May 21, 2010