Software development engineer in test ii Interview Questions

227

Software Development Engineer In Test Ii interview questions shared by candidates

Top Interview Questions

Sort: Relevance|Popular|Date
Expedia Group
Software Development Engineer In Test (SDET) II was asked...3 October 2012

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 Answers

Creating 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? Less

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); } } Less

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); } } Less

Expedia Group

Reverse each word of the string without reversing the order of the words this is a test BECOMES siht si a tset

3 Answers

public class ReverseWordsInString { public static void main(String[] args) { System.out.println(">"); } private static String reverseWords(String original) { if (original == null || original.isEmpty()) { throw new IllegalArgumentException("IP cannot be null or empty"); } final Pattern p = Pattern.compile("[a-zA-Z]"); final StringBuilder returnString = new StringBuilder(); StringBuilder temp = new StringBuilder(); for (int i = 0; i 0) { returnString.append(reverse(temp.toString())); temp = new StringBuilder(); } returnString.append(original.charAt(i)); } } if (temp.length() > 0) { returnString.append(reverse(temp.toString())); } return returnString.toString(); } private static String reverse(String data) { StringBuilder ret = new StringBuilder(); for (int i = data.length() - 1; i >= 0; i--) { ret.append(data.charAt(i)); } return ret.toString(); } Less

/// /// Recieve a string of words and returns the words reversed without changing the order. /// Here's my C# method: public static string ReverseWordsInSentence(string sentence) { char[] whiteSpace = " \t\n".ToCharArray(); string[] words = sentence.Split(whiteSpace); int count = 0; foreach (string individualWord in words) { words[count] = new string(individualWord.ToCharArray().Reverse().ToArray()); count++; } return string.Join(" ", words); } Less

public class ReverseString { public String stringReverse(String str) { if (str == null || str.length() = 0; i--) { sentence.append(word.charAt(i)); } sentence.append(" "); } return sentence.toString(); } public static void main(String[] args) { ReverseString obj = new ReverseString(); String test = "this is a test"; System.out.println(obj.stringReverse(test)); } } Less

Expedia Group

Remove all characters of a string from another string. The algorithm should be less than O(m*n) where m & n are lengths of strings and the space used should be less than O(m+n).

3 Answers

I have written a program using Hashmap and StringBuilder.

An efficient solution to the problem can done using simple pattern matching. A sample solution goes as follows : public class SampleMain { /** * @param args */ public static void main(String[] args) { String charStream = "ABABCBABABABABABATGBHacbfoabcbahasacbJKOPLMNBGDESRABADACAJALAMNBADDHEMSZPQ"; String noise = "ABCPQR"; System.out.println("CharStream : " + charStream + "\n" + "Noise : " + noise + "\n" + "FliteredCharStream : " + func(charStream, noise)); } private static String func(String charStream, String noise) { String regex = "[" + noise.toLowerCase() + noise.toUpperCase() + "]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(charStream); return m.replaceAll(""); } } Less

import java.util.Arrays; public class Solution{ public static void main(String[] args){ System.out.println(remove("as","asasfsg")); } public static String remove(String s1, String s2){ boolean[] flags = new boolean[255]; char[] a1 = s1.toCharArray(); char[] a2 = s2.toCharArray(); String str = ""; Arrays.fill(flags,false); for(int i=0; i=a1.length && i Less

Tokopedia

Q: By share screen, please create code to reverse each words in a sentence.

2 Answers

create code by split, looping, and reverse each words

There's a lot of elements to typically cover in these questions, clarifications, scoping, making sure you're answering the actual question the interviewer is looking for you to answer, etc. Could be worth doing a mock interview with one of the Prepfully Tokopedia Software Development Engineer In Test (SDET) II experts... they've worked in the role so they clearly know how to get through the interview. prepfully.com/practice-interviews Less

Microsoft

The interviewer confused me like hell when describing the question. Every node of the tree has a pointer to its left most child. each node has a pointer to its next sibling. Its a BST. Find the smallest value in the tree.

2 Answers

He confused me like hell. He started with "given a tree find the first node". Then went on clarifying the question as I digged in. Less

The key in generic questions like this, is to make sure to cover the fundamentals. There's usually a back-and-forth with the interviewer. Might be worth doing a mock interview with one of the Microsoft Software Development Engineer In Test (SDET) II experts on Prepfully? Really helps to get some real-world practice and guidance. prepfully.com/practice-interviews Less

Microsoft

how to reverse words in a string preserving the formatting

2 Answers

google it

public void ReverseWords(StringBuilder sb) { if (sb == null) { return ; } String tempStr = ""; int start = -1; int end = -1; //"My na" for (int i = sb.Length -1; i >= 0; i--) { if (sb[i] == ' ') { if (end != -1) { start = i + 1; // end = 4 // start = 3 while (start <= end) { tempStr = tempStr + sb[start]; start++; } start = -1; end = -1; } tempStr = tempStr + sb[i]; } else { if (end == -1) { end = i; } } } if (end != -1) { for (int i = 0; i <= end; i++) { tempStr = tempStr + sb[i]; } } Console.WriteLine(tempStr); } Less

Microsoft

Find out the number of connected cells in a 2D array

2 Answers

Adjacency matrix representation of Graph

The key in generic questions like this, is to make sure to cover the fundamentals. There's usually a back-and-forth with the interviewer. Might be worth doing a mock interview with one of the Microsoft Software Development Engineer In Test (SDET) II experts on Prepfully? Really helps to get some real-world practice and guidance. prepfully.com/practice-interviews Less

Microsoft

Given a BST find the second largest element?

2 Answers

Since A binary search tree is arranged into subtrees such that, the left subtree contains the values which are less than the root node and the right subtree contains the values which are larger than the root node. So, the largest element will be the Rightmost element of the right subtree. And the SECOND largest element will be it's parent. int findSecondLargest(tree *root) { tree *ptr, *prevPtr; prevPtr = NULL; ptr = root; while( ptr->right != NULL) { prevPtr = ptr; ptr = prevPtr->right; } if (ptr->left == NULL) return (prevPtr->info) ; // if ptr is the rightmost leaf node, then return its parent node // else if it has a left subtree then return the rightmost node in the left subtree. prevPtr = ptr; ptr = ptr->left; while (ptr ! = NULL) { prevPtr = ptr; ptr = ptr ->right ; } return (prevPtr->info) ; } Less

Node findSceondLargest(Node root) { // If tree is null or is single node only, return null (no second largest) if (root==null || (root.left==null && root.right==null) return null; Node parent = null, child = root; // find the right most child while (child.right!=null) { parent = child; child = child.right; } // if the right most child has no left child, then it's parent is second largest if (child.left==null) return parent; // otherwise, return left child's rightmost child as second largest child = child.left; while (child.right!=null) child = child.right; return child; } Less

Amazon

Most questions are around data structures. Also expect word puzzles, like write an algorithm to spell out actual numbers. E.g. 121 -> "One Hundred and Twenty One".

2 Answers

Break it down into 0, 1-9, 10-19, 20-99, 100-999, 1000-9999, ect...

I created my algorithm by parsing through the number from the largest place down to the smallest place i.e. for 1234 I parsed starting from 1 then 2, then 3 and finally 4. I created a bunch of switch statements that took in the numbers and spelled out the numbers. I had to be sure that in cases where I had 11, for example, that I looked at the proceeding number or else it could be ten, eleven, twelve, etc. Less

Microsoft

Given the definition of a Fibonacci sequence, write a function to give the n-th term of the sequence.

2 Answers

Need to know the solution to this quickly.

int fib(n) { int n1=0; int n2=1; int x=0; for(int i=2;i<=n;i++) { x= n1 + n2; n1 = n2; n2 = x; } return x; } Less

Viewing 1 - 10 of 227 Interview Questions