Senior Software Engineer Interview Questions in Canada | Glassdoor.ca

# Senior Software Engineer Interview Questions in Canada

231

Senior software engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

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

16 Aug, 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

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

2 Dec, 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...

11 Aug, 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...

11 Aug, 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; }

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

5 Jun, 2012
 So, you have almost talked to everyone in the building?1 AnswerPut me in a very unconformable situation.

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

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

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

13 Aug, 2013
 Difficult challenging technical question which I know the answer but I couldn't get it at that time1 AnswerInterview was great, to the point, they know what they are doing

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

15 Jun, 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...

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

### Senior Software Engineer at Redline Communications was asked...

2 May, 2013
 find the missing number from a number series from 1 to a milion read in from a db.1 AnswerGot stumped on this, but it is the sum of a series, S= n(n+1)/2. Read in the numbers, adding them as you go along. Let the sume be R. Then, the missing number = S-R
110 of 231 Interview Questions