# Software Test Engineer Interview Questions

Software test engineer interview questions shared by candidates

## Top Interview Questions

I was asked a pretty straight forward brain teaser during my last phone interview, which they said they don't normally do, but because I put that I was a logical problem solver on my resume they couldn't resist the opportunity to. It was the following "There are 20 different socks of two types in a drawer in a completely dark room. What is the minimum number of socks you should grab to ensure you have a matching pair?" 9 Answers3 is the answer when the probability is 50% for either color. "20 DIFFERENT socks of two type" In my opinion It's a brain teaser not a probability question. The answer is none. There is no sock alike, so you can't get a pair. 3 is the answer no matter what... there are only 2 types, if you grab 3, you must have 1 of one type and 2 of the other Show More Responses I'm not a mathematician, statistician or highly analytical but if you pick up 3 socks they could still be all the same type - even if the odds are 50%. Odds do not equal reality. So the only way to "ensure you have a matching pair"is to pick up 11 of the 20. This is the only fool proof guaranteed way to get a pair (in the real world and not the world of odds). All of the previous answers are somehow wrong or misleading. "Not-a-mathematician": the method you describe would ensure that you get 2 DIFFERENT socks instead of matching - and only in the situation that the ratio is exactly 50-50. "Anonymous on Oct 20 2012": No, you could also have 3 of the same sock after grabbing 3. "Anonymous on Oct 3": The probability has little to do here, while it is over 0%. THE REAL ANSWER: Given that there are 2 types, and you want to get a MATCHING PAIR (not 2 different socks) you must grab 3. When you have 3, you WILL have at least 2 of the same kind, since there are only 2 kinds available. Easy. I do this every morning when I get up. The answer is ONE PAIR. If you are like most people and have rolled the socks together in pairs when you put them away, there is no guessing and you just grab a pair of socks. I think it's more of a question about habits and prep. ;) It says "ensure" you have a pair. So all the probability answers are dead wrong. The person who said "The answer is none. There is no sock alike, so you can't get a pair" is probably correct. However if the question is to get two of the same type (of which there are two), then the only correct answer is 11. That is the MINIMUM number to ENSURE you have a pair--all probability aside. It says "ensure" you have a pair. So all the probability answers are dead wrong. The person who said "The answer is none. There is no sock alike, so you can't get a pair" is probably correct. However if the question is to get two of the same type (of which there are two), then the only correct answer is 11. That is the MINIMUM number to ENSURE you have a pair--all probability aside. It doesn't tell you that there are 10 and 10. There could be 19 and 1. But regardless: There IS a way to grab 2 socks and not have 2 that match. (one of each) But there is NO WAY to grab three socks and not have 2 of them match. |

find if 2 strings are anagrams 5 Answershash Hash what, lol ? :))) You simply need to alphabetically sort characters in strings and then compare the result. think about the time complexity. Whats the time complexity of the sorting? NlogN And when using hash mapping, it can be only N. Mapping the string to an alphabet array, the index is the char and the value stores the frequency of the char. Hope it helps. Show More Responses easiest way probably to reduce the characters to ascii, add them all together. If values are equal, they all contain the same characters. O(n) Just reverse one string and then compare the result with other string. |

### Software Engineer In Test at Google was asked...

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[0].length == 0) { return true; } int rowlen = matrix[0].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 col Show More Responses If 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); |

In a BST write a program to find 2 nodes x and y such that X+y=k 4 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 Responses You 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 :) |

Given a triangle, determine if its a scalene, equilateral, isosceles or neither... required knowledge of triangle properties, I learnt these properties about two decades ago so ofcourse I was fuzzy on the details, completely unexpected 4 Answerstesting use of ==, got a feeling he wanted to use bit level comparisons to compare sides lengths If the sides are all integers, then compare the length^2 instead of length to avoid the floating comparison; If the sides are floating numbers, then we need to set an epsilon to test. You'd better ask the interviewer about this. Asking this will definitely gives the interviewer better impression.... I believe :-) BTW, if you are given the sides instead of points, the condition to make an triangle is: a+b > c && b+c > a && c+a > b Show More Responses /* Q: Given a, b, c, determine if it can be the 3 sides of triangles, if yes determine if it's equilateral, isosceles, or scalene. */ #include #include #include using namespace std; // Use this in real world typedef enum { NONE = 0, EQUILATERAL = 1, ISOCELES = 2, SCALENE = 3 } TriangleType; double Epsilon = 1.0E-6; string GetTriangleType(double a, double b, double c) { if (a+b > c && b+c > a && c+a > b) { bool ab = (fabs(a-b) < Epsilon); bool bc = (fabs(b-c) < Epsilon); bool ca = (fabs(c-a) < Epsilon); if (ab && bc && ca) return "Equilateral"; if (ab || bc || ca) return "Isoceles"; return "Scalene"; } else { return "None"; } } int main() { cout << GetTriangleType(3, 3, 3) << endl; cout << GetTriangleType(3, 3, 5) << endl; cout << GetTriangleType(3, 4, 5) << endl; cout << GetTriangleType(3, 4, 7) << endl; return 0; } /* Output: Equilateral Isoceles Scalene None */ |

given two linked lists with a digit in each node, add the two linked lists together. the result must be a linked list with one digit in each node. use only one iteration of the two input lists. 5 AnswersIs this to remove duplicates from linked list or just combining both the linked lists blindly? assume the numbers you need to add are 560 and 890. the result should be 1450. so linked list A will have 5 -> 6 -> 0 and linked list B will have 8 -> 9 -> 0 so you must add them together to produce 1 -> 4 -> 5 -> 0. i believe the reason for an algorithm like this is to have a method of adding arbitrarily large numbers together. rather than storing an integer as int32 or int64, we can store the int as a linked list, which can be any size integer we want. Of course, the underlying 'int' we use for the data of the linked list only needs to be 4 bits to cover 0-9 in decimal. public static List AddTwoLists(List first, List second) { return first.Zip(second, (a, b) => a + b).ToList(); } Show More Responses i don't believe this answer is correct. you must account for cases where you will carry a 1. for example, if node A_i is 5 and node B_i is 7, then C_i = 2 and C_(i-1) = C_(i-1) + 1. In short, you must consider the carry value. I don't see that your solution considers this. Your solution would make C_i = 12, but 12 is two digits, not one. I think the answer should traverse both link lists and add each node data and make a new link list with digit on each node of the answer. In this way we can traverse in N time and at the end if any nodes are left in second link list we can attach them at the end of new link list |

Write a function to find the node where two linked lists meet. 3 Answerspublic static void main(String[] args) { List L1 = Arrays.asList(1,2,5,7,9,10,12,18,3); List L2 = Arrays.asList(2,3,4,8,9,9,10,11,12,18); LinkedList list1 = new LinkedList(); list1.addAll(L1); LinkedList list2 = new LinkedList(); list2.addAll(L2); System.out.println("L1 : " + list1); System.out.println("L2 : " + list2); ArrayList result = new ArrayList(); System.out.println("two linked lists meet: " + findCommon(list1, list2,result)); } public static ArrayList findCommon(LinkedList list1,LinkedList list2,ArrayList result) { if (list1.isEmpty()) return result; int pop = list1.pop(); if (list2.contains(pop)) result.add(pop); return findCommon(list1, list2, result); } // solution in C++ #include #include using namespace std; // simple Node class class Node { public: Node(int v) : val(v), next(NULL) {} int val; Node* next; }; // function to find intersection Node Node* findNodeWhere2ListsMeet(Node* head1, Node* head2) { // interate through first list and populate map map nodeMap; while (head1 != NULL) { nodeMap[head1] = head1->val; head1 = head1->next; } // interate through second list and try to find in map while (head2 != NULL) { if (nodeMap.find(head2) != nodeMap.end()) { return head2; } head2 = head2->next; } return NULL; } // test code (happy path only) int main() { // linked list 1 values = 1,2,3,4,5,6 Node* head1 = new Node(1); Node* n12 = new Node(2); Node* n13 = new Node(3); Node* n14 = new Node(4); Node* n15 = new Node(5); Node* n16 = new Node(6); head1->next = n12; n12->next = n13; n13->next = n14; n14->next = n15; n15->next = n16; // linked list 2 values = 11,12,13,5,6 Node* head2 = new Node(11); Node* n22 = new Node(12); Node* n23 = new Node(13); head2->next = n22; n22->next = n23; n23->next = n15; Node* intersection = findNodeWhere2ListsMeet(head1, head2); while (head1 != NULL) { cout val next; } cout val next; } cout << endl; Previous answer got truncated. Here's the last of the test code starting at the function call. Node* intersection = findNodeWhere2ListsMeet(head1, head2); while (head1 != NULL) { cout val next; } cout val next; } cout val << endl; cout << "\n\n\nPress Enter to quit. "; cin.ignore(); return 0; } |

Write a function to turn a string into an integer and test it 3 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; } |

### Software Engineer In Test at Google was asked...

Design a function which returns the number of set bits in a given number, when expressed in binary 4 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 Responses Use a logarithm, base-2. def num_bits(n): return int(math.log(n, 2) + 1) |

post order traversal of a Binary Search Tree Follow up Create a BST from this post order traversed array and write test cases for this function 3 AnswersCreating a BST from the post order traversal output would involve adding the nodes in reverse order of the post order traversal output. For example, if the post order traversal output was 2,4,3,20. I would insert in the following order: 20, 3, 4, 2. Can anyone confirm if this is correct? package test; import java.util.ArrayList; import java.util.List; public class TreeTraversal { static List preOrder = new ArrayList(); static List inOrder = new ArrayList(); static List postOrder = new ArrayList(); static void traverseTree(Node root) { Node left = root.getLeftNode(); Node right = root.getRightNode(); if (null == left.getLeftNode() && null == left.getRightNode() && null == right.getLeftNode() && null == right.getRightNode()) { preOrder.add(root.getValue()); preOrder.add(left.getValue()); preOrder.add(right.getValue()); inOrder.add(left.getValue()); inOrder.add(root.getValue()); inOrder.add(right.getValue()); postOrder.add(left.getValue()); postOrder.add(right.getValue()); postOrder.add(root.getValue()); } else { preOrder.add(root.getValue()); traverseTree(left); inOrder.add(root.getValue()); traverseTree(right); postOrder.add(root.getValue()); } } public static void main(String[] args) { Node left = new Node(2, new Node(1), new Node(3)); Node right = new Node(6, new Node(5), new Node(7)); Node root = new Node(4, left, right, true); traverseTree(root); System.out.print("Pre Order Traversal ::"); System.out.println(preOrder); System.out.print("In Order Traversal ::"); System.out.println(inOrder); System.out.print("Post Order Traversal ::"); System.out.println(postOrder); } } package test; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; enum TraversalType { PREORDER, INORDER, POSTORDER; } public class ConstructTreeBack { static Node root = new Node(); static TraversalType traversalType; static void formSubTrees(List treeList) { List leftSubTree = new ArrayList(); List rightSubTree = new ArrayList(); Iterator it = treeList.iterator(); int rootNodeVal = root.getValue(); while (it.hasNext()) { int nodeVal = it.next(); if (rootNodeVal > nodeVal) { leftSubTree.add(nodeVal); } else if (rootNodeVal treeList) { Node node = new Node(); if (traversalType.equals(TraversalType.PREORDER)) { if (null != treeList.get(0)) { node.setValue(treeList.get(0)); } if (null != treeList.get(1)) { node.setLeftNode(new Node(treeList.get(1))); } if (null != treeList.get(2)) { node.setRightNode(new Node(treeList.get(2))); } } else if (traversalType.equals(TraversalType.INORDER)) { if (null != treeList.get(1)) { node.setValue(treeList.get(1)); } if (null != treeList.get(0)) { node.setLeftNode(new Node(treeList.get(0))); } if (null != treeList.get(2)) { node.setRightNode(new Node(treeList.get(2))); } } else if (traversalType.equals(TraversalType.POSTORDER)) { if (null != treeList.get(2)) { node.setValue(treeList.get(2)); } if (null != treeList.get(0)) { node.setLeftNode(new Node(treeList.get(0))); } if (null != treeList.get(1)) { node.setRightNode(new Node(treeList.get(1))); } } return node; } public static void main(String[] args) { int rootNodeVal = 0; List treeList; /*PRE ORDER TRAVERSAL*/ Integer treeArrPreOrder[] = { 4, 2, 1, 3, 6, 5, 7 }; rootNodeVal = treeArrPreOrder[0]; root.setValue(rootNodeVal); root.setRoot(true); treeList = Arrays.asList(treeArrPreOrder); traversalType = TraversalType.PREORDER; formSubTrees(treeList); /*IN ORDER TRAVERSAL*/ Integer treeArrInOrder[] = { 1, 2, 3, 4, 5, 6, 7 }; int rootIndex = 3; root.setValue(treeArrInOrder[rootIndex]); root.setRoot(true); treeList = Arrays.asList(treeArrInOrder); traversalType = TraversalType.INORDER; formSubTrees(treeList); /*POST ORDER TRAVERSAL*/ Integer treeArrPostOrder[] = { 1, 3, 2, 5, 7, 6, 4 }; rootNodeVal = treeArrPostOrder[treeArrPostOrder.length - 1]; root.setValue(rootNodeVal); root.setRoot(true); treeList = Arrays.asList(treeArrPostOrder); traversalType = TraversalType.POSTORDER; formSubTrees(treeList); } } |

**21**–

**30**of

**1,657**Interview Questions

## See Interview Questions for Similar Jobs

- Software Engineer
- Software Development Engineer
- Senior Software Engineer
- Software Developer
- Software Development Engineer In Test
- Software Engineer In Test
- QA Engineer
- Intern
- Software Development Engineer II
- Software Test Engineer
- Software QA Engineer
- Program Manager
- Senior Software Development Engineer
- Test Engineer
- Software Development Engineer I
- Quality Assurance Engineer
- Software Engineer Intern
- Business Analyst