Testing Interview Questions | Glassdoor

# Testing Interview Questions

3,209

Testing interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Oct 3, 2012

### Software/Test Engineer at Amazon was asked...

Apr 18, 2012
 how to get the most significant bit from a byte?3 AnswersI couldnt understand what he ment by byte. I thought eight bits in binary format. But what he was asking about converting a decimal number into binary and getting the most significant bit out of it.right shift the number by 7 positions and you get the most significant bit printf("%d",n>>7);If he was asking about converting a decimal integer number into binary and getting the most significant bit out of it, then the answer is just: divide by 2, again and again until you get the last '1'; Or using programming code: while(x) { x >>= 1; ++n; }

### Software Development Engineer In Test (SDET) at Microsoft was asked...

May 31, 2012
 reverse a linked-list3 Answerssimple declare 2 temperary variables and store the links of the variables of link list sequencially and alter the links make 1st link null.you'll need 3 pointers hereYou will need 3 pointers and iterate through the list, then reverse each element

Jun 21, 2011
 Given a sorted array of integers, write a function to remove any duplicates. Give algorithm, then code and finally list how you would test your program.4 AnswersThe easy way is to create a new array with the same size. Add only non repeating integer to the new array. Return new array in the end of loop For in place solution: loop through array compare n+1 with n create one reference idx and set idx = n loop through array from 0...n and n+1 < length of array if array[n+1] == array[idx], set array[n+1] == null else array[++idx] = array[n+1]To test you can want to have various array size 1. array = null 2. array is zero 3. array is xth size but some are null values 4. array does not have duplicate values 5. array have all the same values 6. array with multiple duplicate values 7. array with one value 8. array with duplicate values in the end 9. array with duplicate values in the beginning 10. array is not ordered, function should check if it is orderedIn C++11, assuming that the function takes a pair class with array and array size, and returns a pair with array and array size. Slightly inefficient memory wise, but it's a lot simpler and it works. pair deduplicateIntArray(pair input) { set mySet; mySet.insert(input.first, input.first + (input.second)); int* newArray = new int[mySet.size()]; int idx = 0; for(auto s : mySet) { newArray[idx] = s; idx++; } return make_pair(newArray,idx); }Show More ResponsesAdding the elements of the array to a HashSet would remove the duplicates without requiring extra logic.

### Software Development Engineer In Test (SDET) at Microsoft was asked...

Feb 28, 2013
 Write a program takes in a string and a delimiter, and uses that delimiter to split a string and then will reverse the characters in every word (or jumble of characters between the delimiters), stuffing them back into a string when finished. ('The dog walks' becomes..... 'ehT god sklaw')4 Answersin C# static string ReverseStrings(string original, char splitter) { if (string.IsNullOrEmpty(original)) return null; int currentSplitIndex = -1; int p1 = 0, p2 = 0; while (p2 < original.Length) { while (p2 < original.Length && original[p2] != splitter) p2++; if (p2 < original.Length) //p2 points to separator { Reverse(ref original, p1, p2 - 1); p1 = ++p2; } } return original; } static void Reverse(ref string org, int start, int end) { for (int i = start; i <= start + (end - start) / 2; i++) { var c1 = org[i]; var c2 = org[end - i + start]; org = org.Remove(i, 1); org = org.Insert(i, c2.ToString()); org = org.Remove(end - i + start, 1); org = org.Insert(end - i + start, c1.ToString()); } }public void ReverseEachWordOfString(string orignal, char del) { int errorCode = 0; List list = SplitString(orignal, del, out errorCode); if (errorCode == -1) { Console.WriteLine("Empty string provide, Please provide valid input"); } else if (errorCode == -2) { Console.WriteLine("Empty delimiter provide, Please provide valid input"); } else { StringBuilder strbld = new StringBuilder(); char[] revString; foreach (var item in list) { revString = new Char[item.Length]; for (int i = 0, j = item.Length - 1; i SplitString(string orignal, Char del, out int errorCode) { errorCode = 0; List list = new List(); if (orignal == null || orignal == string.Empty) { errorCode = -1; return null; } if (del == null) { errorCode = -2; return null; } StringBuilder str = new StringBuilder(); for (int i = 0; i < orignal.Length; i++) { if (orignal[i] == del) { list.Add(str.ToString()); str.Clear(); } else { str.Append(orignal[i]); } } return list; }using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Reverse_Words { class Program { static void Main(string[] args) { string revString = string.Empty; string bufferString = string.Empty; string inputString = ""; // Checking input if (string.IsNullOrEmpty(inputString)) { Console.WriteLine("Input is empty"); inputString = Console.ReadLine(); } // Asuming word is set of leters and not include any other chars like "-" or "'" for( int i = 0; i = 65) & (Convert.ToByte(inputString[i]) = 0; i--) { outString += wordString[i]; } return outString; } } }Show More Responsesdef splitReverseString(inputArray,delimeter): tempArray = [] tempElement = '' if len(inputArray) == 0: return 'Null String' for i in range(len(inputArray)): if (inputArray[i] != delimeter): tempElement = tempElement + inputArray[i] else: tempArray.append(tempElement) tempElement = '' tempArray.append(tempElement) for j in range(len(tempArray)): tempElement = '' temp = tempArray[j] for k in range(len(temp)-1,-1,-1): tempElement = tempElement + temp[k] tempArray[j] = tempElement return tempArray

### Software Development Engineer In Test Intern at Microsoft was asked...

Apr 21, 2012
 You have a building with 100 stories. You also have two glass balls. You can drop the glass balls as many times as you want before they break. How can you find the floor at which they start breaking with the fewest number of drops? 3 AnswersNot truly a brain teaser because the answer is mathematical.If you have N stories, you use the first glass ball to increment by sqrt(N) stories. Once that ball breaks, you use your second to go to the level of sqrt(N) below where it broke, and increment floor by floor. You know it must break somewhere in that group of sqrt(N) stories. I believe this method gets you a runtime of O(n^0.5).search for "two egg problem". its a minimization of maximum regret problem http://www.datagenetics.com/blog/july22012/index.html

Sep 3, 2010

### Software Development Engineer In Test (SDET) at Microsoft was asked...

Jan 13, 2012
 Check if tic-tac-toe has a winner4 AnswersTic-Tac-Toe is game like soduku or checkers that is represented as having columns and rows which translates as a 2 Dimensional array. In this case a 3x3 array. Represented as [0][0] [1][0] [2][0] You would therefore permutate each possibility. .... ..... ...... ...... ..... ..... [2][2]It's all about state. You can only win on the placement of a token so check the possible ways to win from this position. So say the user places a value in the bottom left corner. Then you need only check the vertical, horizontal and the diagonal from this position. From the center position you will need to check 4 different positions (+ and x). This retains a O(1) solution but then again this only works if you can keep count of how many moves have already occurred.@Matt: I like your approach, but still question in doubtful. We have final state of game or we have to write decision function after every move?Show More Responses@VIctor.. It does not matter that we have final state or not we need to check with every input from users..and probably the check function gonna check on 8 places ...

### Software Development Engineer In Test (SDET) at Microsoft was asked...

Oct 7, 2010
 Write a function to turn a string into an integer and test it3 AnswersCString csNum; int nNum = 2; csNum.format("%d", nNum);oops wrong one CString csNum = "1"; int nNum = atoi(csNum);public int AtoI(string str) { bool isNeg = false; int index = 0; if (str[0] == '-') { isNeg = true; index++; } int result = 0; // "123" 123 // 1 * 10 + 2 12 * 10 + 3 int multiple = 1; int number = 0; for (int i = index; i < str.Length; i++) { number = str[i] - '0'; result = result * multiple + number; multiple = 10; } if (isNeg) { result = result * -1; } return result; }