Senior engineer Interview Questions | Glassdoor.ca

# Senior engineer Interview Questions

1,594

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

### Senior Software Developer at D2L was asked...

Oct. 18, 2018
 Given an array of int[] like 1,2,3 Find the next largest integer than can be made with these digits (e.g.: 2,1,3)5 AnswersWrote code in C# to solve the problem in a generic case. Think about this situation: 5,9,8,7,6,4,3,1,2 -> 5,9,8,7,6,4,3,2,1 followed by 5,9,8,7,6,4,3,2,1 -> 6,1,2,3,4,5,7,8,9.// Typescript implementation // Assumption 1: all numbers in the input array are single digits, i.e. between 0 and 9 // Assumption 2: if a larger number cannot be found then return the current number as is const getNextLargestNumber = (inputs: number[]): number => { if (inputs) { // Do not mutate the initial inputs let copiedInputs: number[] = inputs.slice(); // Loop through the digits in reverse order // Exclude the first digit for (let i = copiedInputs.length - 1; i >= 1; i--) { // Loop through the previous digits for (let j = i - 1; j >= 0; j--) { const swapFrom: number = copiedInputs[i]; const swapTo: number = copiedInputs[j]; // Swap if a smaller digit is found before if (swapTo x - y)]; return convertArrayToNumber(copiedInputs); } } } } return convertArrayToNumber(inputs); }; const convertArrayToNumber = (inputs: number[]): number => { let num: number = 0; if (inputs) { const inputsLength: number = inputs.length; for (let i = 0; i < inputsLength; i++) { // Use index to determine the power of 10 num += inputs[i] * (10 ** (inputsLength - i - 1)); } } return num; }; console.log(getNextLargestNumber([4, 1, 9, 5])); console.log(getNextLargestNumber([4, 5, 1, 9])); console.log(getNextLargestNumber([4, 5, 9, 1])); console.log(getNextLargestNumber([4, 9, 1, 5])); console.log(getNextLargestNumber([4, 9, 5, 1])); console.log(getNextLargestNumber([5, 1, 4, 9])); console.log(getNextLargestNumber([1, 4, 2, 4, 3, 8, 6, 4, 0])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 6, 8])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 8, 6])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 6, 3, 8])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 1, 2])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 2, 1])); console.log(getNextLargestNumber([6, 1, 2, 3, 4, 5, 7, 8, 9])); console.log(getNextLargestNumber()); console.log(getNextLargestNumber([6, 5])); console.log(getNextLargestNumber([5, 6]));// Wrong copy-paste // Corrected version // Typescript implementation // Assumption 1: all numbers in the input array are single digits, i.e. between 0 and 9 // Assumption 2: if a larger number cannot be found then return the current number as is const getNextLargestNumber = (inputs: number[]): number => { if (inputs) { // Do not mutate the initial inputs let copiedInputs: number[] = inputs.slice(); // Loop through the digits in reverse order // Exclude the first digit for (let i = copiedInputs.length - 1; i >= 1; i--) { // Loop through the previous digits for (let j = i - 1; j >= 0; j--) { const swapFrom: number = copiedInputs[i]; const swapTo: number = copiedInputs[j]; // Swap if a smaller digit is found before if (swapTo x - y)]; return convertArrayToNumber(copiedInputs); } } } } return convertArrayToNumber(inputs); }; const convertArrayToNumber = (inputs: number[]): number => { let num: number = 0; if (inputs) { const inputsLength: number = inputs.length; for (let i = 0; i < inputsLength; i++) { // Use index to determine the power of 10 num += inputs[i] * (10 ** (inputsLength - i - 1)); } } return num; }; console.log(getNextLargestNumber([4, 1, 9, 5])); console.log(getNextLargestNumber([4, 5, 1, 9])); console.log(getNextLargestNumber([4, 5, 9, 1])); console.log(getNextLargestNumber([4, 9, 1, 5])); console.log(getNextLargestNumber([4, 9, 5, 1])); console.log(getNextLargestNumber([5, 1, 4, 9])); console.log(getNextLargestNumber([1, 4, 2, 4, 3, 8, 6, 4, 0])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 6, 8])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 8, 6])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 6, 3, 8])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 1, 2])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 2, 1])); console.log(getNextLargestNumber([6, 1, 2, 3, 4, 5, 7, 8, 9])); console.log(getNextLargestNumber()); console.log(getNextLargestNumber([6, 5])); console.log(getNextLargestNumber([5, 6]));Show more responses// Hmm, after posting the comment, some code gets changed (after "Swap if a smaller digit is found before" comment) // Attempt 3 to post // Typescript implementation // Assumption 1: all numbers in the input array are single digits, i.e. between 0 and 9 // Assumption 2: if a larger number cannot be found then return the current number as is const getNextLargestNumber = (inputs: number[]): number => { if (inputs) { // Do not mutate the initial inputs let copiedInputs: number[] = inputs.slice(); // Loop through the digits in reverse order // Exclude the first digit for (let i = copiedInputs.length - 1; i >= 1; i--) { // Loop through the previous digits for (let j = i - 1; j >= 0; j--) { const swapFrom: number = copiedInputs[i]; const swapTo: number = copiedInputs[j]; // Swap if a smaller digit is found before if (swapTo x - y) ]; return convertArrayToNumber(copiedInputs); } } } } return convertArrayToNumber(inputs); }; const convertArrayToNumber = (inputs: number[]): number => { let num: number = 0; if (inputs) { const inputsLength: number = inputs.length; for (let i = 0; i < inputsLength; i++) { // Use index to determine the power of 10 num += inputs[i] * (10 ** (inputsLength - i - 1)); } } return num; }; console.log(getNextLargestNumber([4, 1, 9, 5])); console.log(getNextLargestNumber([4, 5, 1, 9])); console.log(getNextLargestNumber([4, 5, 9, 1])); console.log(getNextLargestNumber([4, 9, 1, 5])); console.log(getNextLargestNumber([4, 9, 5, 1])); console.log(getNextLargestNumber([5, 1, 4, 9])); console.log(getNextLargestNumber([1, 4, 2, 4, 3, 8, 6, 4, 0])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 6, 8])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 8, 6])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 6, 3, 8])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 1, 2])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 2, 1])); console.log(getNextLargestNumber([6, 1, 2, 3, 4, 5, 7, 8, 9])); console.log(getNextLargestNumber()); console.log(getNextLargestNumber([6, 5])); console.log(getNextLargestNumber([5, 6]));// Last attempt // Possibly, angle brackets break the code sample // Typescript implementation // Assumption 1: all numbers in the input array are single digits, i.e. between 0 and 9 // Assumption 2: if a larger number cannot be found then return the current number as is const getNextLargestNumber = (inputs: number[]): number => { if (inputs) { // Do not mutate the initial inputs let copiedInputs: number[] = inputs.slice(); // Loop through the digits in reverse order // Exclude the first digit for (let i = copiedInputs.length - 1; i >= 1; i--) { // Loop through the previous digits for (let j = i - 1; j >= 0; j--) { const swapFrom: number = copiedInputs[i]; const swapTo: number = copiedInputs[j]; // Swap if a smaller digit is found before if (swapTo < swapFrom) { copiedInputs[i] = swapTo; copiedInputs[j] = swapFrom; // Take portion of array up to the swap point // The remaining digits are sorted in ascending order copiedInputs = [...copiedInputs.slice(0, j + 1), ...copiedInputs.slice(j + 1).sort((x, y) => x - y)]; return convertArrayToNumber(copiedInputs); } } } } return convertArrayToNumber(inputs); }; const convertArrayToNumber = (inputs: number[]): number => { let num: number = 0; if (inputs) { const inputsLength: number = inputs.length; for (let i = 0; i < inputsLength; i++) { // Use index to determine the power of 10 num += inputs[i] * (10 ** (inputsLength - i - 1)); } } return num; }; console.log(getNextLargestNumber([4, 1, 9, 5])); console.log(getNextLargestNumber([4, 5, 1, 9])); console.log(getNextLargestNumber([4, 5, 9, 1])); console.log(getNextLargestNumber([4, 9, 1, 5])); console.log(getNextLargestNumber([4, 9, 5, 1])); console.log(getNextLargestNumber([5, 1, 4, 9])); console.log(getNextLargestNumber([1, 4, 2, 4, 3, 8, 6, 4, 0])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 6, 8])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 3, 8, 6])); console.log(getNextLargestNumber([1, 4, 2, 4, 4, 0, 6, 3, 8])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 1, 2])); console.log(getNextLargestNumber([5, 9, 8, 7, 6, 4, 3, 2, 1])); console.log(getNextLargestNumber([6, 1, 2, 3, 4, 5, 7, 8, 9])); console.log(getNextLargestNumber()); console.log(getNextLargestNumber([6, 5])); console.log(getNextLargestNumber([5, 6]));

### 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.Show more responsesThe advantage? Well complexity is log (n) and there is no extra memory required i.e. no list creation needed One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

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 Operations Developer, at PNI Digital Media was asked...

Nov. 19, 2018
 write a c# method to bring pairs of integers that sum up to 10 from an array of integers.3 AnswersThey said the solution should have to sorted the integer array, put two pointers at the end and front compare the sum of a and b, if it was more than 10 then bring the last pointer forward until end of array ... They best solution was (On), and I gave them( lgn)... The other solution was to build a dictionary with pairs and each time adding new element check to see if it already exited ... #include #include #include static std::map findPairsOfSum(int array[], int sum){ std::map myPair; int len = sizeof(array); if (array == NULL) return myPair; for (int i=0; i pairs; int myArray[] = {0,10,3,7,3,5,7,3}; pairs = findPairsOfSum(myArray,10); // printing map std::map :: iterator it; for (it = pairs.begin(); it != pairs.end(); ++it){ std::coutfirstsecond myPairs(int [] myArr, int sumUp){ Dictionary returnPair = new Dictionary (); int len = myArr.Length; Console.WriteLine("Array Size -> "+len); for (int i=0;i myDictionary = myPairs(myArray,10); foreach (var item in myDictionary) { Console.WriteLine("key {0} and value {0}",item.Key,item.Value); } } } }#include #include #include static std::map findPairsOfSum(int array[], int sum){ std::map myPair; int len = sizeof(array); if (array == NULL) return myPair; for (int i=0; i pairs; int myArray[] = {0,10,3,7,3,5,7,3}; pairs = findPairsOfSum(myArray,10); // printing map std::map :: iterator it; for (it = pairs.begin(); it != pairs.end(); ++it){ std::coutfirstsecond <<'\n'; } return 0; }using System; using System.Collections.Generic; namespace pairsSum { class Program { public static Dictionary myPairs(int [] myArr, int sumUp){ Dictionary returnPair = new Dictionary (); int len = myArr.Length; Console.WriteLine("Array Size -> "+len); for (int i=0;i myDictionary = myPairs(myArray,10); foreach (var item in myDictionary) { Console.WriteLine("key {0} and value {0}",item.Key,item.Value); } } } }

### Senior Software Engineer - Microservices at Hopper was asked...

Oct. 14, 2018
 A HackerRank challenge with 90 mins to solve 3 AnswersI Solved it, but not the best code I've ever written as I had only 90mins.Through questions like this, interviewers are mostly trying to test your skillset (and its relevance to the role) as robustly as possible, so be prepared for multiple offshoots and followups. It could be a useful exercise to do mocks with friends or colleagues in Hopper to get a real sense of what the interview is actually like. Alternatively Prepfully has a ton of Hopper Senior Software Engineer - Microservices experts who provide mock interviews for a pretty reasonable amount. prepfully.com/practice-interviewsany more details on this question?

### Senior Engineer at SEMAFO was asked...

Oct. 22, 2020
 Pourquoi Semafo2 AnswersPour sa réputationEst une entreprise spécialisée dans le domaine Minier Au bf

### Senior Mechanical Engineer at Hatch was asked...

Nov. 1, 2014
 Why are you planning to leave your current employer?2 AnswersI feel there has been a shift in the company's corporate culture, away from quality engineering, design and innovation, towards becoming just a cog in the wheel of a large construction company. It is not a culture I am prepared to embrace.Want to learn new things and pursue new challenges

### Senior Engineer at Ciena was asked...

Nov. 15, 2015
 What is mutex.2 Answersyescould you post the technical questions you were asked ?

### 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; }
110 of 1,594 Interview Questions