Software Developer Interview Questions in Mountain View, CA | Glassdoor

# Software Developer Interview Questions in Mountain View, CA

"Software developers design, write, test, and maintain the code for a software system. Extensive knowledge of programming languages, data structures, and algorithms are necessary to pass the technical interview which is designed to test these skills. Employers are looking for candidates with a bachelor's degree in computer science or related field or equivalent work experience. "

## Top Interview Questions

Sort: RelevancePopular Date

Feb 23, 2010
 How would you write a sort routine to ensure that identical elements in the input are maximally spread in the output?4 AnswersThis is my opinion: First of all, understand what "maximally spread out" means - if we have an array of 4 identical elements, there are 4! = 24 permutations we can arrange the elements by. If we measure for each element the distance of its new position minus its old one (i.e. the number of "hops" the element made), and sum these measurements we get an idea of how well the permutation "mixed up" the array. However, there is more than one such maximal permutation, and so we need to choose the "maximally spread out" one. I think this is the one where the minimal amount of "hops" for any element is maximal, in the 4 elements array case - each element does 2 hops, i.e. [a b c d] turns into [c d a b]. In order to achieve this we can use a *stable* MergeSort, and when performing the last merge (e.g. between [a b] and [c d]), we simply choose to perform this specific merge with preference for items from the right array and not the left one. (all through the recursions levels of the operation we stayed stable, meaning we preferred to initially place elements from the left array, this time we do the opposite). We can accomplish this by giving an extra boolean parameter for the recursion, the top level gets it as 'true' and invokes all other levels with it being 'false'. ... This is just my opinion :)I am confused for more than one reason. First, "sort" usually means "arranged in ascending or descending order". In sorted output the identical elements are right next to each other, not "maximally spread out"! Or do I miss something? If your "sort" means "any arrangement that follows certain rules", then you should mention what these rules, besides identical elements in the input being maximally spread out. Is there some ordering of non-identical elements?probably dynamic programming question, o(n^2) for each item in input_array for i=0 to i=output_array.length if (item == output_array[i]) { swap_in_output_array(i, i-count) count++ } output_array.append(item)Show More Responsesrefer here http://stackoverflow.com/questions/17899312/disperse-duplicates-in-an-array

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

Jul 13, 2012
 Create a data structure that minimizes time complexity of retrieving median and inserting new element. Getting median should be O(1) and insertion should be O(log(n)).5 AnswersA heap in which the root is the median and it has max heap of the lower half on left and min heap of the rest on right.Can we not use a BST which is kept balance after every insertion using AVL ? The median is always the root of this tree, so median is retrieved in O(1) and insertion/deletion is O(log n) for balanced tree.I guess a Red-Black tree would be a more appropriate data structure to use. Since it is a perfectly balanced tree data structure, the median would always be at the root. The insertion takes time proportional to the height of the tree i.e. O(logn)Show More ResponsesWe can use two heaps, one max heap, one min heap. Large values are pushed into the min heap, and small values are pushed into the max heap. Keep the difference of the number of elements in the two heaps smaller than 2. The median will be the top of the heap with more elements or the average of the tops of the two heaps if they have same number of elements. I think this is easier to implement.array?binary search when do insertion?

Jun 24, 2010
 Find the optimal map route between two points on a grid (maze) with some areas blocked out.3 AnswersIs this just testing if you know Djikstra's algorithm?Sounds more like an A* application to meBFS

Mar 30, 2010

Jun 15, 2012
 Browsers running javascript is single threaded, how can we make AJAX calls in the backgroung? 2 AnswersWe can use Javascript to make AJAX call in the background. Ex:For Chating ,we need to update the content of chat after every one or three sec so we call the javascript function once and then we use javascript inbuild function Settimeout() which call ajax in the background.JavaScript is single threaded, but AJAX is *asynchronous* (by default), so it runs in a background. If we need another thread, we can use web workers.

Oct 14, 2009
 What's your favorite programming language? Talk to me about it.2 AnswersThis was the most difficult because it was entirely open ended and required me to know a lot about the language, what it allows, how it differs from other languages, and how it might be implemented.I'd say Java, because it keeps me awake. Or maybe I'd say it's the next one I'm going to learn.

### Software Development Engineer In Test (SDET) at Microsoft was asked...

Feb 11, 2012
 How can you write a recursive function calculating the exponential of a number?2 Answersf(n) = a if n=0. f(n) = a*f(n-1) otherwise.//Imports using System; //Test class class Test { //Constructor public Test() { //Nothing } public int RecursiveExp(int x, int n) { //First base case if (n == 0) { return 1; } //Second base case if (n == 1) { return x; } //Even values of (n) if (n % 2 == 0) { int y = RecursiveExp(x, n / 2); return y * y; } //Odd values of (n) else { int y = RecursiveExp(x, n - 1); return x * y; } } } //Main class class Program { //Main static void Main(string[] args) { //Create a test object Test tst = new Test(); //Examples Console.Out.WriteLine(tst.RecursiveExp(2, 0)); Console.Out.WriteLine(tst.RecursiveExp(2, 1)); Console.Out.WriteLine(tst.RecursiveExp(2, 3)); Console.Out.WriteLine(tst.RecursiveExp(2, 4)); } }

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

Jun 29, 2012
 How would you detect if a linked list is circular and how would you fix it?1 AnswerThis is the standard Tortoise and Hare Problem and can be solved using the method described here: http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare