Developer Intern Interview Questions | Glassdoor

# Developer Intern Interview Questions

760

Developer intern interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Apr 11, 2012
 Swap two variables without using a temp.4 AnswersCan be done using adding/subtracting, multiply/divide, xor.in c/c++: x^=y^=x^=y;You don't want to use +-/* as you might face under/overflow.Show More Responsesa= a*b; b = a/b; a = a/b;

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

Jan 29, 2010
 There is an array of numbers, containing the integers 1-n, how can you find the sum of the numbers in that array?3 Answersn(n+1)/2what if duplicates r thr or some number missing?wat a stupid ques..just traverse the array and add up every number

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

Jan 4, 2013
 Print a binary tree level by level in zigzag order3 AnswersYou should use two stacks: for the current level and for the next one.Use a queue. 1.Push root on queue. 2. Begin Loop Repeat while node is not equal to NULL: a. Pop b. Print value c. Push node's Right Child d. Push node's Left Child 3. EndThe answer given by me above is wrong because I was not clear about the zig zag ordering I applied it wrong !

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

Oct 1, 2012
 Calculate the square root of a number. 3 Answerspublic double squareRoot(double x) { double epsilon = 0.000001; double base = 0; double increment = 1; while (increment > epsilon) { double diff = base*base - x; if (diff 0) { base -= increment; increment /= 10; } else { break; } } return base; }private static double sqrt(double n) { double lower = 0; double upper = n; for (int i = 0; i < 1000; i++) { double mid = (lower + upper) / 2; if (mid * mid < n) lower = mid; else upper = mid; } return (lower + upper) / 2; }#include #include using namespace std; #include int main() { float n; cout>n; if(n0.00001) { if(mid*midn) high=mid; mid=(low+high)/2; } return mid; }

### Software Development Engineer In Test Intern at Microsoft was asked...

Apr 21, 2012
 You have a building with 100 stories. You also have two glass balls. You can drop the glass balls as many times as you want before they break. How can you find the floor at which they start breaking with the fewest number of drops? 3 AnswersNot truly a brain teaser because the answer is mathematical.If you have N stories, you use the first glass ball to increment by sqrt(N) stories. Once that ball breaks, you use your second to go to the level of sqrt(N) below where it broke, and increment floor by floor. You know it must break somewhere in that group of sqrt(N) stories. I believe this method gets you a runtime of O(n^0.5).search for "two egg problem". its a minimization of maximum regret problem http://www.datagenetics.com/blog/july22012/index.html

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

Mar 18, 2009
 Write an algorithm that does an in-order traversal of a tree recursively. Now, write the same algorithm iteratively.4 AnswersHint: You'll want to use a stack in the iterative version.Haha, I got that same question on my interview. It made me sweat, because I knew I was supposed to use a stack, but I had never done it before. It was fun working it out on my own.public void inOrder(Node* root) { if(root == NULL) return; inOrder(root->left); cout element; inOrder(root->right); }Show More Responses// recursive void InorderTraversal( Node *root) { if ( root== NULL) return ; // status 2 InorderTraversal( root->left ); // status 1 Print (root); InorderTraversal(root->right); // status 0 } // NON-Recursive Version for Pre/In/Post-Order the idea behind this method is to employ a stack to emulate the recursion void NonRecTraversal( Node *root ) { if ( root == NULL ) return ; stack stk; bool flag = 2;// the key: keep track of the status of the top element stk.push(root); while( !stk.empty()) { if ( flag == 2 ) { /* Print (node) ; this is preorder */ if ( stk.top()->left != NULL ) stk.push(stk.top()->left ); else flag = 1; } else if ( flag == 1) { /* Print (node) ; this is inorder */ if ( stk.top()->right != NULL) { stk.push(stk.top()->right); flag = 2; } else flag = 0; } else { /* Print (node) ; this is postorder */ Node *temp = stk.top(); Stk.pop(); If ( !stk.empty() && stk.top()->left == temp ) Flag = 1; // come back from left child Else Flag = 0; // come back from right child } } }

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

Mar 18, 2009
 Connect Four is a game where two players take turns dropping their color discs into a vertically suspended grid. The game ends when a player adds a disc to the playing grid that connects four discs of their color. The connected discs can be in a horizontal, vertical or diagonal line. Write a function to be called after every turn that returns true if the game is over (and false otherwise).3 AnswersThere are many ways to solve this, especially since you're not given any other details about the code architecture. Note that checking for four connected discs horizontally, vertically and diagonally is very similar, but varies in the direction. This is a good hint that it should be a method taking a parameter specifying the direction.The ask for a function, but how about a class and a method in order to explain some of my thinking (I think in Python nowadays) class Game: def __init__(self, w, h): self.w = w self.h = h self.board = [] # WxH (ColxRow) array ... def get_rows(self): ... def get_columns(self): ... def get_diagonals(self): ... def done(self): in_a_row = 0 lastdot = -1 for (c,r) in self.get_columns() + self.get_rows() + self.get_diagonals(): if self.board[c,r] is not None and self.board[c,r] == lastdot: in_a_row = in_a_row + 1 if in_a_row == 4: return True # TODO: perhaps return the dot instead? else: lastdot = self.board[c,r] in_a_row = 0 return Falses-The ask-They ask-g

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

Mar 11, 2010
 Write a function to cause stackoverflow. 3 AnswersCall a function from itself in an infinite loop.That is not true if the compiler use tail recursion. Using tail recursion will not cause a stack overflow.Call a function inside of itself with no exist condition

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

Mar 11, 2010
 Write a function to convert First Name, Last Name to Last Name, First Name.3 AnswersYou can do it inplace my swapping the last and first char and then shifting the start index and rest string by one place each time.#include using namespace std; void swap (string * first, string * last); int main () { string first, last; cout > first; cout > last; swap (&first, &last); cout << "Swapping your first and last name." << endl; cout << "Your first name is now " << first << "." << endl; cout << "Your last name is now " << last << "." << endl; return 0; } void swap (string * pfirst, string * plast) { string temp = *pfirst; *pfirst = *plast; *plast = temp; }To be precise I forgot to add: // above swap (&first, &last) cout << "Your name is " << first << ", " << last << endl; // replace above return 0; cout << Your name is now " << first << ", " << last << endl; You don't have to pass by reference, you could have just used the swap function to reverse the order of the first and last name, but this is more impressive for an interview!

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

Aug 27, 2012
 Is it possible to sort using linear time a file with lots of numbers that contain duplicates, when there are no limits of resources or space?3 AnswersIt is possible, just use a hash map in the first pass, and then on the second pass store it in a one dimensional array.if space is not a problem, create a integer array with size equal to the range of numbers. initialize all to 0. Then do array[number]++ for each number in fileuse bucket sort.. if stability is not the issue. or use counting sort
3140 of 760 Interview Questions

More