Software Developer Intern Interview Questions | Glassdoor

# Software Developer Intern Interview Questions

549

Software developer intern interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Feb 15, 2012

### Financial Software Developer Intern at Bloomberg L.P. was asked...

Apr 17, 2012
 There are 20 floors in a building. If you're on an elevator and you're trying to get to the 20th floor, what is the probability that 4 people ahead of you click the 20th floor before you do? Assuming you click last.10 Answersassume there is one button for each floor, so 20 buttons. a person can press any 1 button out of the 20, prob is 1/20. Since there are 4 people, so1/16000These are independent events so the chances of one person before you going to the 20th floor is 1/20. Since this happens 4 times before you the probability is 4*(1/20) or 1/5.The above two are close, but wrong.. There are 20 buttons, thus 20 choices, sure. But you are getting on at one of the floor. No body will press the button for the floor they get on.. Thus, there is really only 19 choices. P = (1/19)^3 (Independent events mean (1/19)(1/19)(1/19)).Show More Responses1/19 + 1/18 + 1/17 + 1/16 assuming that there were no repeated destinations.based on question: P(all 4 ahead of you want to get off on 20th fl) = (1/19)^4 real life(all 4 want to get off on 20th fl, and one of them is the first person press the button to 20th fl, and that leave all others, including you, stay still): (1/19) * (1/4)about 20% is the right answer. I am surprised with some of the answers, they are all very small possibilities (some less than 1%).I'm quite sure you are all wrong: The real probability is 1 - P(nobody pushes 20) = 1 - (18/19)^3 = 15%1- (19/20)^4If one of the 4 press the button for the 20th floor then the others won't have to do anything. The chances of one of them pressing 20th is: 1/19 + 1/19 + 1/19 + 1/19 = 4/19The answer is 1-(19/20)^4

Aug 13, 2013

### Software Development Engineering Intern at Amazon was asked...

Jun 23, 2012
 You are given an array with n positive integers where all values in the array are repeated except for one. Return the one that is not repeated.10 Answerspublic static int notRepeated(int[] given) { Map m = new HashMap(); for(i=0; i < given.length; i++) { if(m.get(given[i])) { m.put(given[i], 2); } else m.put(given[i], 1); for(x:m) { if(x == 1) return x; } } }If you have an array of positive integers with only ONE non repeated integer, the easiest thing is just xor them all. Whatever you return will be the answer. Perl answer below sub findNotRepeated{ my (\$arr) = @_; if(@\$arr==0) { return - 1; } my \$val = 0; foreach(@\$arr) { \$val ^= \$_; } return(\$val); } sub findMissingElement{ my (\$arr,\$arr2) = @_; if(@\$arr==0 || @\$arr2 == 0 ) { print " arr2=" .@\$arr2 . "X\n";; return - 1; } my \$val = 0; foreach((@\$arr , @\$arr2)) { \$val ^= \$_; } return(\$val); }first sort the array.n then 1)for i=1 to n { if ( element [i] !=element [i+1] ) { cout<Show More ResponsesThis answer is in-place with O(n) complexity. A slight improvement over the space complexity of the Hash Map answer. public int returnNonRepeat(int[] input) { if(input.length < 3) return -1; else { int repeat = null; if(input == input) repeat = input; else if(input == input) return input; else return input; for(int i = 2; iCant use XOR as it fails when any element repeats odd number of times..... Can use hash map with O(n) time and O(n) spaceonly 2 possible solutions 1.) using sorting 2.) using additional space. which will be less than o(n)sub find_odd { my @a = @{\$_}; my (\$i, \$n); \$n = \$a; for \$i (1 .. \$#a) { \$n = \$n ^ \$a[\$i]; } printf("number is %s\n", \$n); }Use xoridea: 2(1 + 2 + 3) - (1+2+3+2+3) = 1 array = [1, 2, 3, 2, ,3] return( (2*sum(set(arr)) - sum(arr))This person from Amazon told me what to expect in this interview. it was really good info and helpful. Here's their profile: https://www.rooftopslushie.com/profile/ask

### Software Development Engineer Intern at Amazon was asked...

Feb 15, 2012
 To return the 'm' smallest numbers from a file of 'n' numbers8 AnswersI would first create an array holding the first m values of the file, and sort. Then, each value I read from the file, I can compare the the last (largest) value in the array. If its smaller, do a binary search to find the correct spot in the array. Insert the number and shift everything behind it back by 1. Worst case runtime will be O(n lg m)Why cant we simply start with min=INT_MIN. Then, read first number from file, if lower, set min=that number. Seek next number and so on... We dont need to load the whole file. We will go to the disk often though.I will create a min heap with the given numbers and extract 'm' minimums from the heap which will get stored into the resultant arrayShow More ResponsesAnuj, Wont it take time of O((M+N)log N)@spammer, I think it's O(n+m*log n), since you can construct the min heap bottom-up and that only takes O(n)Why don't we just sort the array and return the first m numbers? Takes O(nlogn) for sorting and O(m) to return the first m numbers.Modified quick sort. Pick a pivot and test if one half is smaller than m. If it is, drag the rest from the other half; if it is not, keep partitioningMaintain a heap of m numbers and also track a variable which stores the current highest value. So as u go through the n numbers, if the number is higher than the current highest number, ignore it else insert it into the heap and set the current highest value to the newly inserted value

Jan 6, 2011

### Software Development Engineer Intern at Amazon was asked...

Jan 6, 2011
 Write a program to find the square root of a double.5 Answersuse binary search to narrow down the search space and keep multiplying the answer in each iteration by itself to check if it is equal to the double given. If it is lesser, move up the lower bound, else move down the upper bound.One easy to remember method that also has much better performance than binary searching for the result is the Babylonian Method. It is similar to Newton's method for finding derivatives. See the algorithm here: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method Also, combining this algorithm with the Rough Estimation also described on that page will compute the squareroot of most double numbers in less than 10 iterations.Is it too obvious to ask if you can do double^.5 ?Show More ResponsesI would respond by showing that I am thinking about the problem as it is defined, not by making assumtions about what is implied. This can result in product that does not meet the requirement specifications, which can be very costly: "What do you mean, a program or a function? A program would require input and output mechanisms to make it meaningful, but makes it pretty usesless as a job assessment question. A function makes more sense in this context. "There's a variation of the problem which says "find the square root of a double up to the third decimal digit". I'd just multiply the original number by 10^position (meaning, for 3 digit accuracy it'd be 10^3) and ran a simple loop to find the closest integer. As soon as i*i > 10^position * number, you can return (i-1)/10^position. It's hella slow and unimaginative, but it works and you won't sound like you knew this problem ahead of time (if you come up with a Babylonian solution).

### Software Developer Intern at Halliburton was asked...

Nov 2, 2009
 What is the angle between the two arms of the clock at 2:40?8 Answersint time(int h, int m) { angleH = (h*360)/12; angleM = (m*360)/60; return Math.abs(angleH - angleM); }160 degreesif a circle is bisected, the degree would be 180, as a circle is 360 degrees. How do you come up with 160?Show More Responses160 of coursehttp://en.wikipedia.org/wiki/Clock_angle_problem#Equation_for_the_angle_between_the_handsThis should help http://www.mathcelebrity.com/clockangle.php?num=2%3A40&pl=Calculate360*(40/60)-360*(2/12)-(360/12)*(40/60)=160Hours needle move with mins needles. Think about in one hour the hr needle move 30 degree. And 40 mins the hr needle move 20 degree. At time of 2:40, hr needle move 80 degree, mins move 240 degree. The angle between two needles will be 240-80=160.

### Software Development Engineer Intern at Amazon was asked...

Jan 30, 2012
 Write a program that sees if two binary trees are equal.6 AnswersI utilized a depth-first traversal method, comparing the data within each node and recursively checking the left, then right child.Don't know if this works or not... value = \$value; \$this->left = \$left; \$this->right = \$right; } // O(n) times inorder traversal function testEsqual(\$tree1,\$tree2) { if(\$tree1->value ==null || \$tree2->value==null) return false; if(\$tree1->value ==null && \$tree2->value==null) return true; while(\$tree1->value!=null) { if(\$tree1->value == \$tree2->value) { equal(\$tree1->left,\$tree2->left); equal(\$tree1->right,\$tree2->right); } else { return false; } } } } ?>How if we use in-order traversal? If my understanding is correct, two binary trees are equal if they contain the same elements (although at different positions in the tree)Show More Responsesbool AreEqual(Node* node1, Node* node2) { if( (node1 == NULL && node2 != NULL) || (node2 == NULL && node1 != NULL ) return false; if(node1 == NULL && node2 == NULL) return true; if(node1->data != node2->data) return false; return( AreEqual(node1->left, node2->left) && AreEqual( node1->right, node2->right) }; int main(); { AreEqual(root1, root); };The solution by kvr doesn't cover a case when node1->data and node2->data are equal. An additional if is required.fb, If if(node1->data != node2->data) is not true, what does that tell you *Is* true?

### Software Development Engineer Intern at Amazon was asked...

Jan 25, 2011
 Write a function that takes in an array and repeats an integer that appears the most.5 Answersif: Array  it should print Confusing. In your example, 2 appears the most. Do you mean the integer that repeats the most consecutively? Cause that would be 3. Anyways, in either case, you can go through the array adding all the key-value pairs (number and times) to a hashmap and then access the hashmap in constant time. O(n).class FindMostOccurences { public static DictionaryEntry MostOccurences(int[] Array) { Hashtable ht = new Hashtable(); for (int i = 0; i Int32.Parse(de.Value.ToString())) { { de.Key = item.Key; de.Value = item.Value; } } } return de; } }Show More ResponsesUsing map , i think one loop is sufficient. private static int mostReapeatingNumber(int[] is) { HashMap map = new HashMap(); int tempHighestCount = 0; int keyHighest = 0; for (int index=0; index tempHighestCount) { tempHighestCount = numCount; keyHighest = number; } } } return keyHighest; }I think there's no need to have a map. Just maintain variables prev_max_run, prev_max_num, prev_num, curr_num and curr_run. In the loop if the prev_num was equal to curr_num increment curr_run. When you find the num is different check curr_run with prev_run. If curr_run > prev_run, prev_max_num = curr_num.
110 of 549 Interview Questions