Software Intern Interview Questions | Glassdoor

Software Intern Interview Questions

1,400

Software intern interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Sep 26, 2012

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?

Amazon Software Developer Intern at Amazon was asked...

Apr 1, 2011
 how would you design how a cellphone implements its contact list when you press a certain letter. For example, If you press M it will tell you all the names starting with M. then if you press MI it will tell you all names starting from MI and so forth....6 AnswersUse a tree structure where each level is a consecutive character. So, if M is chosen first, travel down the "M" branch. To show remaining set of possible contacts, traverse the tree and print out all leaf nodes.Use a trie or radix (patricia) treeKeep a sorted contact list in an array. The names will be in char arrays so the access time is constant for a specific index. Do a binary search for the left boundary (the first appearance of a match and the right boundary (the last appearance of a match). Iterate through that index range. When dealing with mobile space might be an issue and making such a tree might cost more overhead then just looking through a sorted array.Show More ResponsesThe tree answer is a probably the right idea, but what about edge cases like if you have a contact Matt and a contact Matthew, in this case Matt will not be a leaf node but be an intermediary node on the way to Matthew. Any clarification would be appreciatedyou'll probably need a suffix tree for this oneWhat about having a hash map where the keys are the various letter of the alphabet, and the associated values are sorted collections of names starting with that same letter as the corresponding key.

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

Mar 13, 2013
 Linked list memory management: deleting a node from the middle of a list was easy. Next question - how to delete a node from the end of a list. Was too tired to think and realize this was a trick question.5 AnswersYou can't, since the pointer already points to null. No way around it.Disagree, Instead of 1 use 2 pointers, having pointer 1 one step ahead of pointer 2, once pointer 1 points to NULL, use pointer 2 to remove the last node.It depends. on how the link-list is implemented.Show More Responsescheck node->next->next equals to null or not, then can just update node->next = nullI guess this question makes sense only when we don't know the Head node !

Software Engineering Intern at Yelp was asked...

Mar 7, 2013
 You have two arrays with N integers in them. Merge those arrays using a recursive algorithm so that the integers in the final array are sorted.6 AnswersIsn't this essentially mergesort?how to solve it?def funky(arrOne, arrTwo, arrThree, indexOne, indexTwo, indexThree): if(indexOne >= len(arrOne) and indexTwo >= len(arrTwo)): return arrThree if(not(arrOne[indexOne] in arrTwo)): arrThree.append(arrOne[indexOne]) if(not(arrTwo[indexOne] in arrOne)): arrThree.append(arrTwo[indexTwo]) indexOne = indexOne + 1 indexTwo = indexTwo + 1 funky(arrOne, arrTwo, arrThree, indexOne, indexTwo, indexThree)Show More Responses@Dung Pham you are right it is mergesort def merge(a1, a2): """ it is mergesort with unusual interface 2x Array on input """ return _merge(a1 + a2) def _merge(seq): if len(seq) = a_size: out.extend(b[b_i:]) break else: out.append(b[b_i]) b_i += 1 if b_i >= b_size: out.extend(a[a_i:]) break return out if __name__ == "__main__": got = merge([1,10,2,4], [12,1,9,7]) print(got)Actually, merge sort will require an extra O(m + n) space to store the temporary merged array. Probably it's better to concatenate two arrays then do quick sort?def merge(nums_1, nums_2): result = [] if len(nums_1) == 0: result.extend(nums_2) return result if len(nums_2) == 0: result.extend(nums_1) return result if nums_1[0] < nums_2[0]: result.append(nums_1[0]) result.extend(merge(nums_1[1:], nums_2)) else: result.append(nums_2[0]) result.extend(merge(nums_1, nums_2[1:])) return result

Jul 5, 2012

Oct 18, 2011
 How can one implement a queue with only a stack implementation?4 AnswersYou will need at least two stacks. public class Queue { private Stack inbox = new Stack(); private Stack outbox = new Stack(); public void queue(E item) { inbox.push(item); } public E dequeue() { if (outbox.isEmpty()) { while (!inbox.isEmpty()) { outbox.push(inbox.pop()); } } return outbox.pop(); } }you have double ended queue (Deque) and insertion and removal can be handled at both end either left or right. But if you want to implement Queue as stack, then restrict the operation at any one end either left. So Front and rear both become at the same end.Never mind my previous answer was wrong implementation. It is actually implementing stack using Queue.Show More Responses#include #include using namespace std; stack st1, st2; int pop( ) { if (!st1.empty()) { int t,t1; while(st1.size() != 1) { t = st1.top(); st1.pop(); st2.push(t); } t1 = st1.top(); st1.pop(); while(st2.size()) { t = st2.top(); st2.pop(); st1.push(t); } return t1; } } int main() { st1.push(2); st1.push(3); st1.push(4); st1.push(5); st1.push(6); cout<

Feb 10, 2013