Enginerring Interview Questions | Glassdoor

# Enginerring Interview Questions

73,606

Enginerring interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

### Engineer at Eventbrite was asked...

Mar 11, 2011
 Given a table that has parent's id and children id, write a query that return grandparents and grandchildrens1 AnswerRelational schema - p_name and c_name make a composite primary key relation {p_name varchar, c_name varchar} select t1.Grandchild, t2.Grandparent from (select c_name as Grandchild, p_name from relation where p_name in (select distinct(r.p_name) from relation r join relation t on r.p_name = t.c_name)) as t1 inner join (select p_name as Grandparent, c_name from relation where c_name in (select distinct(r.p_name) from relation r join relation t on r.p_name = t.c_name)) as t2 on t1.p_name=t2.c_name order by t1.Grandchild;

Jun 19, 2012

### Senior Software Engineer at Facebook was asked...

Jul 18, 2010
 Write some pseudo code to raise a number to a power.10 Answerspretty trivial...int raise(num, power){ if(power==0) return 1; if(power==1) return num; return(raise(num, power-1)*num); }double Power(int x, int y) { double ret = 1; double power = x; while (y > 0) { if (y & 1) { ret *= power; } power *= power; y >>= 1; } return ret; }Show More ResponsesIn Ruby: def power(base, power) product = 1 power.times do product *= base end product end puts "2^10 = 1024 = #{power(2,10)}" puts "2^0 = 1 = #{power(2,0)}" puts "2^1 = 2 = #{power(2,1)}"If I were an interviewer, I would ask the Aug 29, 2010 poster why he used bitwise operators, and whether he would deploy that code in a production environment, or if he merely wanted to demonstrate, for purposes of the interview, that he understands bitwise operations.Because it uses dynamic programming and is lots more efficient than your algorithm.If the power is not integer, use ln and Taylor seriesIf I'm the interviewer, none of above answers is acceptable. What if y < 0? what if y < 0 and x == 0? I'm seeing an endless recursion that will eventually overflow the stack, and the none-recursive one just simply returns 1.There is a way to do this in a logN way rather than N. function power(x, n) { if n == 1 return x; // Even numbers else if (n%2 == 0) return square( power (x, n/2)); // Odd numbers else return power(x, n-1); } This is from Programming pearls.. interesting way.small mistake function power(x, n) { if n == 1 return x; // Even numbers else if (n%2 == 0) return square( power (x, n/2)); // Odd numbers else return power(x, n-1) * x; }

Sep 6, 2010

### Machine Learning Software Engineer at Facebook was asked...

Jan 21, 2010
 Suppose you have a matrix of numbers. How can you easily compute the sum of any rectangle (i.e. a range [row_start, row_end, col_start, col_end]) of those numbers? How would you code this?6 AnswersIt can be done in constant time by precalculating sums of some basic rectangles (extending all the way to the border of the matrix). That precalculation times time O(n) by simple dynamic programming.Please elaborate, which "basic rectangles"? Are you recursively dividing each rectangle into 4 smaller rectangles? Precalc time for doing that is not O(n)?!?Compute the sum of the rectangles, for all i,j, bounded by (i,j), (i,m), (n,j), (n,m), where (n,m) is the size of the matrix M. Call that sum s(i,j). You can calculate s(i,j) by dynamic programming: s(i,j) = M(i,j) + s(i+1,j) + s(i,j+1) - s(i+1,j+1). And the sum of any rectangle can be computed from s(i,j).Show More ResponsesAwesome!!The answer is already popular in computer vision fields!! It is called integral imaging. See this page http://en.wikipedia.org/wiki/Haar-like_featuresIt wasn't 100% clear to me, then I found the Wiki page http://en.wikipedia.org/wiki/Summed_area_table

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

Apr 18, 2012
 Describe and code an algorithm that returns the first duplicate character in a string?7 AnswersSimple Python example. Not sure it's most efficient. def findDup(str): match=[] i=1 while (i

### Senior Software Engineer at Google was asked...

Mar 19, 2009
 What sort would you use if you required tight max time bounds and wanted highly regular performance.6 AnswersVector sort.Guaranteed to be O(n log n) performance. No better, no worse.That is so say, a "Balanced Tree Sort" is guaranteed to be O(n log n) always.Show More ResponsesMerge sort and heapsort are always guaranteed to be n*log(n). Quicksort is usually faster on the average but can be as bad as O(n^2), although with very low probability. Heapsort also does it sorting in-place, without needing an extra buffer, like mergesort. Lastly, heapsort is much easier to implement and understand than balancing trees mentioned by earlier posts.for something like this you generally want bubble sort or insertion sort. It's not about being fast it's about being consistent. Make it do exactly the same thing every time.Use a sorting network. There's some precomputation time, but runtime will be very consistent (the only variability is branch prediction performance)

### Software Development Engineer In Test || at Amazon was asked...

Mar 14, 2012
 Write a method to decide if the given binary tree is a binary search tree or not.4 Answersfor binary search tree, inorder traversal should result in sorted array in the increasing order.Further, know that the difference between the two is that a binary search tree cannot contain duplicate entries. recur down the tree - check if element is already in hashtable - - if it is, return false - - if it isnt, insert element into the hashtable - - - recur to childrenI'm sorry but Anon's answer is not correct, at least according to "Introduction to Algorithms, 3d Edition" by Cormen. The binary search tree property says that there CAN be duplicates: "Let x be a node in a binary search tree. If y is a node in the left subtree of x, then y.key = x.key." In other words, the value of a child node may be equal to the value of a parent node, which would yield the result that "Interview Candidate" posted on Mar 14 2012. Performing an inorder tree walk would yield sorted nodes.Show More Responsespublic static isValidBST(TreeNode root, MIN_INTEGER, MAX_INTEGER) { if (root == null) // children of leaf nodes { return true; } return root.data >= INTERGER_MIN && root.data <= INTEGER_MAX && isValidBST(root.left, INTEGER_MIN, root.data) && isValidBST(root.right, root.data, INTEGER_MAX) }

### Product Design Engineer at Apple was asked...

Sep 21, 2011
 What are the different ways you can you tell if this part is steel or aluminium.4 AnswersSimply by using a magnet, Steel has metallic properties, and the magnet will connect. Aluminium will do nothing.Many stainless steel alloys are not magnetic, so if your magnet is attracted to the material you will definitely know it is steel, but if it doesn't you will not know what the material is.Simple methods would be density (feeling the mass of the object), surface finish (color, texture). If coated that may give you the answer i.ie anodized would indicate aluminium. For more information I would go for EDX( Energy-dispersive X-ray spectroscopy) and possible a cross section to look at the grain structure.Show More ResponsesBy far the easiest way is to test for material properties. -density -hardness -modulus of elasticity I would choose hardness. Strike each item with an equal force, which one deforms more? Thats aluminum. You could probably pull this test off with a hammer. The simplest solutions is always the best.

May 4, 2010