Senior Engineer Interview Questions | Glassdoor.ca

# Senior Engineer Interview Questions

533

Senior engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

### 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

Dec. 2, 2013
 After asking the details of my current role, he only gave me a simple coding question. Write a function using C++ or Java that is passed an integer and it returns the number of bits set to 1. Is there a way to improve your solution and make it faster and more efficient?3 AnswersThere are obviously multiple solutions: Solution 1: Set sum = 0 Find the remainder by dividing by 2. Divide by 2 for the next iteration. Solution 2--much better. Set sum = 0 Start loop Set mask = 1 sum += mask & number Loop return sumThere is another way, that is explained here: http://en.wikipedia.org/wiki/Hamming_weigh (with just 24 operation and without any cycle you can find the number of bit set to 1)An example in Java with 10000 results in answer 5 int number = 10000; int numberOfBitsSet = 0; for (int i = 1; i <= number;) { int result = (i & number); if (result != 0) { numberOfBitsSet++; } i = i << 1; } System.out.println(numberOfBitsSet);

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

Aug. 11, 2011
 find LCA for two nodes of a binary tree. 4 AnswersList 1: tree nodes inorder List 2: tree nodes postorder List 3: all the nodes in between the given 2 nodes List 4: all the nodes after the given 2 nodes the LCA is the common node in List 3 and List 4.I think there's an easier solution: List1: the parents of node1 in order bottom to top (can get them by navigating up tree from node 1). Navigate up tree from node2. First parent of node 2 found in list1 is LCA.There is a better and standard approach. The key is to visualize the ancestor in a BST (Of course we are referring to a BST here). If you start from the top of the tree while comparing both values to each node, the point where the branching differs, is going to be your NCA I wrote sample code a while back too http://forum.codecall.net/topic/64400-finding-nearest-common-ancestor-in-a-bst/Show more responsesThe advantage? Well complexity is log (n) and there is no extra memory required i.e. no list creation needed

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

Aug. 11, 2011
 how to merge two sorted linklist? 2 AnswersUse MergeSort.You don't need merge sort here. This is a O(n) task, because the lists are already sorted. In fact, this merge routine is part of merge sort. No sorting takes place here, only merging, and it could be done in linear time. Node* merge(Node* list1, Node* list2) { Node* merged = null; Node** tail = &merged; while (list1 && list2) { if (list1->data data) { *tail = list1; list1 = list1->next; } else { *tail = list2; list2 = list2->next; } tail = &((*tail)->next); } *tail = list1 ? list1 : list2; return merged; }

### Sr. Software Engineer at Thomson Reuters was asked...

Jan. 11, 2018
 Hackerrank question: valid braces segregate even and odd numbers 1 Answersimple algorithm

### Senior Systems Engineer at VANOC was asked...

Aug. 31, 2010
 What would you say are you're biggest weaknesses if any?2 AnswersToo much attention to detail in the past, very aware of this and because of this I can tailor solutions to requirements and time available.Answering stupid questions like this one.

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

May 6, 2019
 Explain Asynchronous JS to us and what it means for a team working in a standard Node backend. What are your favorite products and why? (CEO will always ask this, I think it is the most important question he asks) What is the hardest thing you've ever done/what is your greatest accomplishment? 1 AnswerThey want you to ask them questions about the questions. If you don't and try to answer a hard question without further clarification I think you lose points.

### Senior Front End Engineer at Shopify was asked...

Mar. 14, 2019
 Build an email sign up form HTML/CSS/JS following a given spec. Include validation, proper colors, etc. make it look as close to the 'mock-up' as possible1 AnswerUsing React I built an application component to house state and pass down to all children, CSS with flex-box is very easy to do the alignment they were looking for and validation can be handled with html5 input with type='email'.

### Senior Software Engineer at The Stars Group was asked...

Jun. 15, 2013
 siizof() of empty class1 AnswerIt is 1 and the reason the size is non-zero is "To ensure that the addresses of two different objects will be different." And the size can be 1 because alignment doesn't matter here, as there is nothing to actually look at.

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

Jan. 1, 2012
 How NAT works?1 AnswerConverting between the private IP/port and public IP/port so that you can access Intnert from internal network
110 of 533 Interview Questions