Developer Intern Interview Questions | Glassdoor

# Developer Intern Interview Questions

761

Developer intern interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

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

Nov 5, 2013
 About the details, and interviewer will communicate with you when you are typing. 3 AnswersDivision - Divide A/B - repeatedly subtract B from A, until A < B. At which time print the number of subtractions as the quotient. The left over value in B, is the remainder.More efficient - http://www.prasannatech.net/2009/01/division-without-division-operator_24.htmlFor the sum case of digits try a binary search type approach: Let S be the sum we are searching for Sort the array - you can do this in n*Log(n) (see http://en.wikipedia.org/wiki/Sorting_algorithm) Here is where the binary search idea comes in Divide the sorted array into sub arrays A1 and A2. Take the mid elements of both sub arrays as pivots p1 and p2. This gives us 4 sub-sub arrays - In A1, we have the left of p1 as A11 to the right of p1 as A12. In A2, we have to the left of p2 as A21 and right of p2 as A22. If p1 + p2 > S then we look in A12 and A13, A11 and A13 and A11 and A12 If p1 + p2 < S look in A12 and A14

Jun 23, 2012

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

Jun 23, 2012
 Write a function that returns the depth of a tree.3 Answerspublic static int depth(Node root, int level) { if(root != null) { if(depth(root.right, level + 1) > depth(root.left, level + 1)) return depth(root.right, level + 1); else return depth(root.left, level + 1); } return level; }Slightly simplified :] (I think this works; not doubling up on the recursive calls either) public static int depth(Node root, int level) { if (root == null) return level-1; return Math.max(depth(root.right, level+1), depth(root.left, level+1)); }int finddepth(node_t* node) { if(node == NULL) return -1; else return 1 + MAX(finddepth(node->lchild), finddepth(node->rchild)); }

### Web Development Intern at AllofE Solutions was asked...

Aug 28, 2012
 One of the software engineers asked me the question about the colored chameleons bonking into each other question. Basically, there are 15 red, 17 green, and 19 blue chameleons on a desert island. Whenever two chameleons of different colors collide, they both become chameleons of the third color. Can it ever be that all the chameleons on the island are the same color?3 AnswersGoogle the problem for a full mathematical proof. I was able to solve it intuitively and explain my reasoning for my (correct) solution, and that seemed to be what the interviewer was looking for.Answer is yes - Green and Blue combine to give a Red. State: 16R 16G 18B - All the 16R and 16G can combine to give 16 more BluesAnshul its incorrect what you said, because when 2 chameleon bonk they turn into other color of 2 chameleon and not 1 chameleon.

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

Jan 11, 2014
 Write a program that verifies that a binary tree is a binary search tree.3 AnswersLet the BinaryTree contain 3 variables: value, leftChild, rightChild. The leftChild and the rightChild are again type of BinaryTree only. Now say you are given root node as the argument. At every stage, check if the value of the leftChild is less than current node value which is less than value of rightChild. If it is satisfied, recurse through its children. Otherwise, return "Not a Binary Search Tree"void traversal(Node* root){ if(*root== NULL) return; ArrayList thislevel = new ArrayList; thislevel.add(root) ; while(!thislevel.isempty()){ArrayList nextlevel = new ArrayList; for(Node s in thislevel) { if(s= = NULL)break;if(s>s.leftchild)if(s.rightchild>s){nextlevel.add(left);nextlevel.add(right);}else{return(0);)} thislevel = nextlevel;}return(1);}The first ans won't work since there can be a right node on left hand side of root ..thats more than parent and also more than root.. A violation.. So have min max values check each node shd b between min and max.. If yes bst else no

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

May 15, 2009
 Given an array of integers, all but one of which appears an even number of times, find the one integer which appears an odd number of times. Upon completion, asked to improve the algorithm in terms of both time and space, eventually asked to do it in O(n) time and constant space.4 Answersxor the entire array, all the integers which appear an even number of times will cancel eachother outint[] theArray = new int[]{1, 1, 2, 2, 3, 3, 3, 4, 4, 10, 10, 10, 10, 10, 11, 11, 12, 12}; Map theMap = new HashMap(); for (int i = 0; i mapKeys = theMap.keySet(); for(int keyInt : mapKeys) { if(theMap.get(keyInt) % 2 != 0) { System.out.println(keyInt + " occurs odd number of times"); } } }I was also asked this in 2010,march.Show More ResponsesXOR

Aug 27, 2012

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

Feb 7, 2011
 Find the maximum subset sum in an array of numbers. Discuss complexity.3 AnswersI assume you mean sub sequence, not subset. e.g. 4 8 -2 4 0 0 3 5 -30 12 the max subset would be, 4 8 4 0 0 3 5 12 = 34 but the max sub sequence would be 4 8 -2 4 0 0 3 5 = 22 you would need to track the start point of the current subsequence and its sum, when the sum becomes negative you would start a new subsequence and update the current max subsequence.I assume you mean sub sequence, not subset. It can be solved in linear time but using a cumulative array instead of the original one. e.g. 4 8 -2 4 0 0 3 5 -30 12 4 12 10 14 14 14 17 22 -8 4 find the max number and the min number before that 4 - 22 the max sum sub sequence are between these indicies and max value is the max sumI think they asked about Maximum subarray problem: http://en.wikipedia.org/wiki/Maximum_subarray_problem

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

Jan 10, 2012
 Print the BST in level order3 AnswersBasic idea: perform a breadth first traversal of the tree. Every time you dequeue a node, print it. This will give a level order print in linear time.Recursive function that starts at the root and recursively prints the value of each left and right node, along with the level order. bstprint(node, count) { if (node == null) { return; } print count + ": " + node.value; //pseudocode for printing cause lazy bstprint(node.left, count + 1); bstprint(node.right, count + 1); } bstprint(root, 0); //initial callif not tree: return nodes=collections.deque([tree]) currentCount, nextCount = 1, 0 while len(nodes)!=0: currentNode=nodes.popleft() currentCount-=1 print currentNode.val, if currentNode.left: nodes.append(currentNode.left) nextCount+=1 if currentNode.right: nodes.append(currentNode.right) nextCount+=1 if currentCount==0: #finished printing current level print '\n', currentCount, nextCount = nextCount, currentCount

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

Jan 10, 2012
 in an array of characters find the character that is repeated the most3 AnswersPriority QueueCorrect me if I'm wrong, but is priority queue really the best way? I think efficiency ends up being O(nlogn) for PQ...inserting n elements into the queue (insert is O(logn)) then peeking. Using a hash table, it takes O(n) to insert the n elements and O(n) to find the max, resulting in O(n) efficiency.Okay actually building a heap is O(n) not O(nlogn). So both techniques take O(n). Priority queue might be a little better since it only requires one scan and peek is O(1), whereas the hash table method requires two scans through the array.
2130 of 761 Interview Questions

More