Software engineer in test Interview Questions | Glassdoor

# Software engineer in test Interview Questions

421

software engineer in test interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Mar 18, 2009
 Implement a binary tree and explain it's function4 AnswersBinary Search tree is a storage data structure that allows log(n) insertion time, log(n) search, given a balanced binary search tree. The following implementation assumes an integer bst. There's a million implementations. Just look on wikipedia for search and insert algorithms.Hi Xin Li, A binary tree is not the same as binary search tree.. A binary tree is a tree in which every node has atmost two children nodes. It is a k-ary tree in which k=2. A complete binary tree is a tree in which all nodes have the same depth.The fact is ttttttt t t. T to t. To. A a aaAs Sdsassss.Show More Responses One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

Mar 19, 2009

Nov 20, 2009

Jan 15, 2010
 You are a parking lot attendant in a lot that has one open spot, and you want to move the cars from their original positions into a new arrangement. Create a program that will print out instructions on how to move the cars most efficiently. 7 AnswersThe problem is not too difficult, what you have to do is find the empty spot, then look in the desired arrangement for what car should be in that spot, and move that car there. Repeat until complete.Does this really work? If I the empty spot is expected to be the same, but the positions of two (or more) cars are switched, how to rearrange it without a complete search?It's the Tower of Hanoi Problem.Show More ResponsesSo there are actually 2 empty spots then or is there a way to 'stack' cars I don't know of?The parking lot problem has nothing to do with Tower of Hanoi, which requires O(2^n -1). This problem, however, can be solved in O(n) - that's because all you need to do is to perform (0 or more) rotations using the empty parking spot.Here is a C# implementation, using generics and .NET 4.0 Tuple: IEnumerable> RearrangeCars( TCar emptyCarMarker, IDictionary initial, IDictionary desired) { // reverse the lookup: car -> spot Dictionary pending = initial.ToDictionary(p => p.Value, p => p.Key); // remove emptySpot from lookup TSpot emptySpot = pending[emptyCarMarker]; pending.Remove(emptyCarMarker); while (pending.Any()) { // check if the empty spot is where is should be if (desired[emptySpot].Equals(emptyCarMarker)) { while (true) { // pick a car (any car would do) var carToMove = pending.First(); // check if this car is already in its desired position if (desired[carToMove.Value].Equals(carToMove.Key)) { // remove from pending, no moving is necessary pending.Remove(carToMove.Key); if (pending.Any() == false) yield break; } else { yield return new Tuple(carToMove.Key, carToMove.Value, emptySpot); // move the car TSpot newSpot = emptySpot; emptySpot = carToMove.Value; pending[carToMove.Key] = newSpot; break; } } } // move the car into its desired spot var car = desired[emptySpot]; var newEmptySpot = pending[car]; yield return new Tuple(car, newEmptySpot, emptySpot); emptySpot = newEmptySpot; pending.Remove(car); } } Note that there is a while-loop inside another while-loop. However, the complexity is still O(n) since at every iteration of internal or external loop, the "pending" map is reduced by one element. Below are some examples (emptyCarMarker == ""). EXAMPLE 1: Input: initial == { "", "B", "A"} desired == { "", "A", "B"} Output: (B, 1, 0) // move car B from spot #1 to #0 (A, 2, 1) // move car A from spot #2 to #1 (B, 0, 2) // move car B from spot #0 to #2 EXAMPLE 2: Input: initial == { "", "B", "A", "D", "C" } desired == { "A", "B", "", "C", "D" } Output: (A, 2, 0) (D, 3, 2) (C, 4, 3) (D, 2, 4)Here is a Java Implementation, using Google's guava library for the BiMap. It takes O(n) to first create the BiMap and O(n) to move the cars, total O(2n), i.e. O(n) time complexity. import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import java.util.Map; import java.util.Set; class ParkingAttendant { static class ParkingConfiguration { static final Integer EMPTY = -1; Integer moves = 0; BiMap conf, i_conf; static ParkingConfiguration getInstance(int[] conf){ return new ParkingConfiguration(conf); } private ParkingConfiguration(int[] conf){ this.conf = arrayToMap(conf); this.i_conf = this.conf.inverse(); } BiMap arrayToMap(int[] arr){ BiMap m = HashBiMap.create(arr.length); for(int i=0;i> entrySet(){ return conf.entrySet(); } } static void moveCars(ParkingConfiguration from, int[] to){ for(int pos=0; pos e : p.entrySet()){ int pos = e.getKey(); int car = e.getValue(); System.out.format("%1\$s, ", ParkingConfiguration.EMPTY.equals(car)?"_":car); } System.out.println("]"); } static void printCars(int[] p){ System.out.print("["); for(int pos=0; pos

Sep 20, 2015

Nov 20, 2009
 Onsite Interview 2 a): check whether a number is the power of 2 b) Skyline silhouette puzzle . c) Discussion on uses of hash-tables and trees ? d) Few general questions on Work and academic background .5 Answers2a. Simple solution: boolean isPowerOfTwo(int n){ double d = (Math.log(n))/(Math.log(2)); // == log(base 2) n if (d == Math.floor(d)) return true; return false; } Without Java Math class: boolean isPowerOfTwo(int n){ int x = 1; while(true){ if (x == n) return true; if (x > n) return false; x = x * 2; } } or boolean isPowerOfTwo(int n){ if (n < 1) return false; while(n != 1){ if (n % 2 != 0) return false; n = n/2; } return true; } Are there any problems with these approaches? What might be a better approach?boolean isPowerOfTwo (int a) { return (a&(a-1)==0); }@ellemeno: You are expected to give the solution as Anonymous which by the way can be done in java as well , ( it's generally called bit wise operations)Show More Responses@ellemeno: You are expected to give the solution as Anonymous which by the way can be done in java as well , ( it's generally called bit wise operations)@ellemeno: You are expected to give the solution as Anonymous which by the way can be done in java as well , ( it's generally called bit wise operations)

Jun 4, 2013
 Given a 2D rectangular matrix of boolean values, write a function which returns whether or not the matrix is the same when rotated 180 degrees. Additionally verify that every boolean true is accessible from every other boolean true if a traversal can be made to an adjacent cell in the matrix, excluding diagonal cells. That is , (x , y ) can access the set [ ( x + 1 , y ) , ( x - 1 , y ) , (x , y - 1 ) , (x , y + 1 ) ] For example, the matrix { { true , false } , { false , true } } should not pass this test.4 Answersif the matrix A is a11, a12 a21, a22 after 180 rotation a22, a21 a12, a11 so a11 == a22 and a12 == a21 function is BOOL isSame = (a11==a22) && (a12==a21) done.public static boolean isMatrixEqualToFlip(boolean[][] matrix) { if (matrix==null || matrix.length == 0 || matrix.length == 0) { return true; } int rowlen = matrix.length; int highInd = matrix.length/2; int lowInd = highInd - 1 + (matrix.length % 2); System.out.println("rowlen: " + rowlen + " high: "+ highInd + " low: " + lowInd); while (lowInd >= 0) { System.out.println("high: " + highInd + " lowInd: " + lowInd); for(int i=0; i < rowlen; i++) { System.out.println("Compare " + matrix[highInd][i] + " to " + matrix[lowInd][rowlen - 1 - i]); if (matrix[highInd][i] != matrix[lowInd][rowlen - 1-i]) { return false; } } lowInd--; highInd++; } return true; }def rotate180(mtx): col=mtx col.reverse() for row in col: row.reverse() print colShow More ResponsesIf the matrix is: true, false false, true 90 degree rotation would be: false, true true, false 180 degree rotation would be: true, false false, true If we define the matrix as: a11, a12 a21, a22 Then the solution would be: boolean isMatch = !(a11 && a12) && !(a11 && a21) && !(a12 && a22) && !(a21 && a22);

Mar 28, 2011