Senior Software Engineer Interview Questions | Glassdoor.ca

# Senior Software Engineer Interview Questions

357

Senior software 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

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

Aug. 11, 2011

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
 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; }

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

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

Mar. 29, 2020
 what are some marketing strategies that can be used to sell a product?1 AnswerDo you realize I'm applying for a software engineer position?

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

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

### Recruitment Coordinator at Index Exchange was asked...

Feb. 27, 2020
 Questions regarding past experience.1 AnswerDo you have any experience with KPIs?

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

Aug. 17, 2019
 Write Fizz-Buzz in C++. Now make all the stupid constant-time optimizations you can think of to it. Formally: given an int, return “fizz” if it’s a multiple of 3, “buzz” if it’s a multiple of 5, or “fizz buzz” if it’s a multiple of both. It it isn’t a multiple of 3 or 5, return “”. Then find stupid ways to over-optimize it, such as using no if-statements.1 AnswerEveryone who knows what an of statement is has written fizz-buzz. Check x%3, then check x%5, and write out your four if/else cases. You can use only a single branch with a switch on from x%15 from -14 to 14, or no branches at all by hardcoding 30 strings in an array and accessing that index.

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

Aug. 17, 2019
 Given an int, return it as a string without using any library methods to do so. It should work for all values of an integer.1 AnswerPretty common question everyone should have learned in high school, except this one is only for base 10, so it is even easier. I made sure I handled 0 and -2^31 correctly. -2^31 I special-cases out, but in hindsight a cleaner solution would be to just store x as a long long before doing anything. You need to watch out for -2^31 because if you multiply it by -1, you get the same thing.
110 of 357 Interview Questions