Engineering Interview Questions | Glassdoor.ca

# Engineering Interview Questions

7,414

Engineering interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Feb. 20, 2014

Nov. 3, 2012
 implement sqrt without using math libray9 Answerse^((ln(x))/2)I think exp and ln still require a Math library. How about using Newton's method to find the root of f(x) = x^2 - a, where x is the solution (the sought square root) and where a is the number for which you want to find the square root?I would have implemented either Taylor or MacLaurin series, centered at an integer number that is closest to the number that you want to find the square root for, such that the square root of this integer is clean. So if you wanted to find the square root of 8.5, I would centre the series at 9 (sqrt(9) = 3), then compute the series at that point. I'd probably choose between 8 and 10 terms, as that is what is used in any scientific calculator.Show more responsesActually, to add to that, I wouldn't be able to include 8 - 10 terms, as that would rely on the square root operation itself.... so I'd have to rely on a linear approximation.This is the way to go. Fast inverse square root as used in Quake III. float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed return y; }For detailed explanation of the algorithm, see http://en.wikipedia.org/wiki/Fast_inverse_square_rootI wouldn't know about this algorithm, but I can think of a (definitely slower than this one) bisection algorithm to find the root of x^2 = number.Often what they are looking for is a programming data structures oriented solution. Such as using binary search to find sq root etc.poop

Aug. 14, 2016
 Tell us about a time you handled a new experience/situation?8 AnswersAfter how many days were you called for your second round of interviews?I think “accepted offer” is a default option which you must select before post any interview reviews. Just called GE guys and they said it's still in the process of reviewing 1st round stuff, but around 500+ applicants makes this super tough lolHave you heard back from them yet? I called them yesterday and they said they haven't finalized.Show more responsesNot yet, who did you call? Ven?Yeah.Any update? I tried to call Ven couple times but did not succeedHaven't received a response yet.I guess they made their minds alrdy

Sep. 12, 2012

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

Aug. 16, 2012
 Write a function that divides one number by another, without using the division operator, and make it better than O(n).7 AnswersThis can be done in a recursive function, the following code is in Python. # get result of a/b without using a "divide" operator def div(a,b): if a < b: return 0 else: return div(a-b, b)+1 This is how human being do the division naturally, however, the running time of this is O(n/m), where n is the size of a, and m is the size of b, which means, O(n/m) is guaranteed to be less than O(n), when m is larger than 1. -MaximThe answer above is still O(n). We can use binary search and find the answer in the interval [1,a] and use multiplication operator.Totally agree with Vasil. Other option: Long Division Algorithm. O(log n) anyway.Show more responseswhy not just a * b^(-1) :-)// Write a function that divides one number by another, without using the division operator, // Assume that x%y = 0 // O(log n) (function() { 'use strict'; var divide = function(x, y) { var xLength = (x + '').length; var i = 0; var result = 0; var xAry = ('' + x).split(); var xStart = ''; for (i = 1; i = y) { xStart -= y; result = parseInt(result, 10) + 1; } } } return result; }; console.log(divide(1000, 4)); })();Use logarithms? O(1) log(x/y) = log(x) - log(y) = log(answer) answer = 10 ^ log(answer)Convert the number to divide into the base of the number that you are dividing with and then shift the 'bits' to the right by 1 then convert back to decimal

Jan. 27, 2014

May 27, 2015
 Take a paragraph as Input and output the top three most repeated words6 Answersfrom collections import Counter def get_most_3_repeated_words(paragraph): counter = Counter(paragraph.split()) return sorted(counter.items(), key=lambda x: x)[-3:]#/usr/bin/env python from collections import defaultdict wordlst = [] wordcnt = defaultdict(lambda : 0) paragraph = open('/home/nacho/python_test.txt','r') for line in paragraph.readlines(): for word in line.split( ): wordcnt[word] += 1 del wordlst paragraph.close() mostCommon3 = wordcnt.items() del wordcnt mostCommon3 = sorted(mostCommon3, key=lambda value: value, reverse=True) for indx in xrange(3): print "%s: %i" % (mostCommon3[indx], mostCommon3[indx])for i in `cat input. txt` ; do echo \$i |sort|uniq - c|sort - r| head - 3Show more responsesfor word in \$(cat paragraph.txt);do echo \$word;done|sort|uniq -c|sort -n|tail -3|awk {'print \$2'}Python 2 solution: #!/usr/bin/python import operator with open("paragraph.txt", "r") as fin: text = fin.readlines() words = text.split() struct = {} for word in words: if not word in struct.keys(): struct[word] = 1 else: struct[word] += 1 ordered_words = sorted(struct.items(), key=operator.itemgetter(1), reverse=True) for index in ordered_words[0:3]: word = index count = index print word, countA more correct shell answer, which returns the top word first: for word in `cat input.txt`; do echo \$word; done | sort | uniq -c | sort -nr | head -3 | awk '{print \$2}'

### Software Engineer at Zenefits was asked...

Mar. 21, 2015
 Given a Binary Search Tree with integers at every node and an integer k, write code that decides whether or not there exists two nodes a and b such that a+b=k6 AnswersSomething like this? (Untested) private class Node { public boolean ContainsSum(int k) { return ContainsSum_(k, new ArrayList()); } protected boolean ContainsSum_(int k, ArrayList vals) { for (int i : vals) { if (i + m_val == k) return true; } vals.add(m_val); return (m_right != null && m_right.ContainsSum_(k, vals)) || (m_left != null && m_left.ContainsSum_(k, vals)); } private int m_val; private Node m_left; private Node m_right; }can you please list some more questionsPretty good solution listed aboveShow more responsesThe solution mentioned above is O(n^2), because for every node, it is comparing value with all the nodes in Vals array. We can do better than this because we have BST, which is in sorted order. (For unsorted Binary tree, we should have sorted first in O(nlogn) and then searched O(nlogn). O(nlogn) solution - Traverse the BST with DFS (O(n)). For each node of value 'a' search for node of value "b = k - a". Searching in BST would be O(logn). Thus the solution becomes O(nlogn)HashMap tracker = new HashMap(); public SumPair parseTree(Node node, int sum) { if (node == null) { return null; } SumPair pair = parseTree(node.left, sum); if (pair == null) { pair = parseTree(node.right, sum); } if (pair == null) { if (tracker.containsKey(node.data)) { pair = new SumPair(node, tracker.get(node.data)); } else { tracker.put(sum - node.data, node); } } return pair; }With a node reference to left,right and parent, it can be done in O(n) Start at deep left with 2 node references at lowest node, value L. move one reference in DFS way until it find a node R >= K-L. if equal then we have a L and R then move the first reference to the next value in DFS, until node L > K-R repeat until last node is reached and L + R > K lot of micro-optimization possible (skip a whole node by going direct to parent when the parent is still lower than what we looking for)

### Engineering Co-Op at Imperial Oil was asked...

Jun. 20, 2015
 Have you ever lead a team ?5 AnswersYes, I have led teams of Engineers and Technicians in the recent pastYes, I have led a team of Engineers and Technicians in the recent pastYes, I have led teams of Engineers and Technicians in the recent pastShow more responsesYesYes. I have led teams of Engineers and Technicians in the recent past.

### Software Engineer at Morgan Stanley was asked...

Feb. 28, 2012
 A few questions on basic command-line syntax in Unix shells: 1. How would you log output and error messages from a command to a file? 2. How would you run the same command on every file in a directory? 3. How would you find the PID of a named process (say if you wanted to kill it)?5 Answers1. command >file 2>&1 2. cd dir; for i in *; do command; done 3. ps | grep processname or ps -C processname#3 I disagree, more like ps aux |awk '\$0 ~ /ProcessName/ && \$0 !~ /awk/ {print \$2}' If you want the PID#3 To find the PID: pgrep -xShow more responses#3 - to find the PID Or simply use: pidofOpps!! there is typo; it should be: pidof
110 of 7,414 Interview Questions