Senior software developer Interview Questions in Canada | Glassdoor.ca

# Senior software developer Interview Questions in Canada

1,153

senior software developer 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([6])); 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([6])); 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([6])); 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([6])); console.log(getNextLargestNumber([6, 5])); console.log(getNextLargestNumber([5, 6]));

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

Apr. 11, 2018

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

### Senior Applications Developer at RBC was asked...

Mar. 10, 2018
 What would the count for the list of it. public class Test { string Data; int Id; public Test(int id, string data) { Data = data; Id = id; } } static void Main(string[] args) { List list = new List(); list.Add(new Test(10, "test")); var d = new Test(10, "test"); if (!list.Contains(d)) list.Add(d); Console.WriteLine("Count of the list is : " + list.Count); Console.ReadLine(); } } What to do to make count 1?2 AnswersFirst count would be 2. To make it 1. Add override method as following. public override bool Equals(object obj) { if (obj == null) return false; var d = (Test)obj; return (d.Data == Data && d.Id == Id); }public class Test : IEquatable { string Data; int Id; public Test(int id, string data) { Data = data; Id = id; } public bool Equals(Test other) { return this.Id == other.Id && this.Data == other.Data; } }

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

Jun. 11, 2013
 What you do if you cannot get something from upper management you need?2 Answersvery typical question in many companies this dayThese should not be issues, upper management should be aware of these needs from the get go. A clear and concise communication plan as well as regular engagement reviews including upper management should always be in place. Unless logic and common sense are not the norm this should not occur. This said each project or initiative should have its sponsorship clearly defined and hopefully proper support already in place
110 of 1,153 Interview Questions