Testing Interview Questions | Glassdoor

Testing Interview Questions

3,214

Testing interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

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

Jun 18, 2011
 In a BST write a program to find 2 nodes x and y such that X+y=k4 AnswersI think we need to do traversals and check for every node.For a given x traverse nodes upto x + y <= k.This problem requires the use of a map aka dictionary aka hashtable. Visit a node If the node data isn't in the map; add the data to the map. Solve for what the other number should be; check if it's in the map. if it is you're done... otherwise keep searching.Show More ResponsesYou can solve the problem in O(n) time. First you find the smallest number in the tree then you find the highest number (worst-case linear time, logarithmic time if the BST is balanced). If their sum is larger than K, you find the largest number in the tree that is lower than y (you can do it in amortized constant time) If their sum is lower than K, you find the smallest number in the tree that is higher than x (amortized constant time). And you continue this algorithm until you reach the correct X and Y :)

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

Nov 11, 2013

Apr 17, 2010
 Given Vcc and 2 capacitors A and B in series to ground, what is the voltage in between4 AnswersSomewhere in betweenVb=(Cb/Ca+Cb)VI mean Vb=(Cb/(Ca+Cb))VShow More ResponsesIt depends on the initial condition.... if both capacitors were discharged to 0V at first, and then one side is charged to Vcc, then the answer would be Vb=(Ca/(Ca+Cb))Vcc Vcc---Ca----Cb----gnd However since there was no initial conditions given , the middle voltage could be anything if the capacitors are ideal

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

Nov 29, 2009
 Write a function to find the maximum sum of sub array where the array can have negative and positive numbers.4 AnswersDon't jump to the answer. As some of you noticed, the question has ambiguties. Ask questions to clarify the question. They would like you to solve the problem after understanding all the details so that you won't miss any edge cases in your solution. Hint: The answer is recursive.answer in java: int array[] ={1,2,3,-6,5,6,9}; table = new int[7][7]; int i, j; int localMax = -999999999; for(i = 6 ; i >= 0 ; i--) for(j = i ; j < 7 ; j++) { if(i == j) table[i][j] = array[i]; else table[i][j] = array[i] + table[i+1][j]; localMax = Math.max(localMax, table[i][j]); } System.out.println(localMax);In Python: def largest_segment(s): y = 0 z = 0 for i in range(0, len(s)): y = max(y + s[i], 0) z = max(z, y) return z Algorithm is O(n). Only works if the max value for an array containing all negatives is 0.Show More Responsesdef maxSumSubArray(inputArray): currentSum = 0 grandSum = 0 for i in range(len(inputArray)): if (currentSum + inputArray[i]) < currentSum: currentSum = 0 continue else: currentSum = currentSum + inputArray[i] if (grandSum < currentSum): grandSum = currentSum return grandSum

Software Engineer In Test at Google was asked...

Mar 18, 2009
 Design a function which returns the number of set bits in a given number, when expressed in binary4 Answersint numBits(int num) { int numBits = 0; while(num > 0) { if(num % 2) numBits++; num /= 2; } return numBits; }The question stipulates "a number", but the code assumes "a positive integer". (It also assumes the number expressed in binary has a C compiler's default number of bits for type int (e.g. 32); that's probably acceptable since a real-world case would likely specify that type. ) Consider: /* return n of set bits in a signed int */ int numBits(int num) { int numBits = 0; while (num != 0) { if (num < 0) ++numBits; num <<= 1; } return numBits ; }You may get faster results with some precomputing... /* lookup table with number of bits set per byte */ const short lookupTable[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, ... }; int numBits(int num) { unsigned char *p = (unsigned char *)# // not necessarily required, but makes for easier reading return lookupTable[p[0]] + lookupTable[p[1]] + lookupTable[p[2]] + lookupTable[p[3]]; // assumes 32 bit integer }Show More ResponsesUse a logarithm, base-2. def num_bits(n): return int(math.log(n, 2) + 1)

Software Development Engineer In Test at Amazon was asked...

Jan 26, 2012
 Coding question - given a binary tree, write code to count the sum off all siblings.3 AnswersNot sure if this works... value == null) return \$sum; \$sum = \$sum + \$tree->value; countSiblings(\$tree->left,\$sum); countSiblings(\$tree->right,\$sum); } ?>int totalNumberOfNodes(Node root) { if(root == null) return 0; return 1 + totalNumberOfNodes(root.left) + totalNumberOfNodes(root.right); }private int siblingCounter = 0; public int countSiblings(BinaryNode node) { if(node.element == null) { return siblingCounter; } else { siblingCounter++; if(node.right() != null) { countSiblings(BinaryNode right); } if(node.left() != null) { countSiblings(BinaryNode left); } } return siblingCounter; }

Software Development Engineer In Test at Amazon was asked...

Feb 16, 2012
 Implement a Queue using 2 Stacks3 AnswersUntil the first de-queue operation, keep pushing one of the stacks, say stack1, for every enqueue operation. When you encounter the first dequeue operation, then pop stack1 into stack2. Now, pop stack2, to get the dequeued element. Henceforth, on every dequeue operation, pop stack2, and on every enqueue operation, push stack1. At some point, stack2 might become empty, but this brings you back to the first stage !Here is an idea: public class StacksQueue { private readonly Stack stack1 = new Stack(); private readonly Stack stack2 = new Stack(); private Stack dequeueStack; private Stack queueStack; private Stack secondaryStack { get { if (object.ReferenceEquals(queueStack, stack1)) { return stack2; } else { return stack1; } } } public StacksQueue() { queueStack = stack1; } public void Queue(T item) { int count = 0; while (queueStack.Count > 0) { secondaryStack.Push(queueStack.Pop()); count++; } queueStack.Push(item); for (int i = 0; i < count; i++) { queueStack.Push(secondaryStack.Pop()); } if (dequeueStack == null) { dequeueStack = queueStack; } queueStack = secondaryStack; } public T Dequeue() { if (dequeueStack == null) { throw new InvalidOperationException("Trying to dequeue from queue which is empty"); } T result = dequeueStack.Pop(); if (object.ReferenceEquals(dequeueStack, stack1)) { dequeueStack = stack2; } else { dequeueStack = stack1; } if (dequeueStack.Count == 0) { dequeueStack = null; } return result; } }Hi, here is a smart solution in java based on shan.phreak solution : class Queue { Stack stack1 = new Stack(); Stack stack2 = new Stack(); public void push(Integer value){ while (!stack2.isEmpty()){ stack1.push(stack2.pop()); } stack1.push(value); } public Integer dequeue(){ while (!stack1.isEmpty()){ stack2.push(stack1.pop()); } return stack2.pop(); } }

Nov 5, 2012