Software development engineer in test sdet Interview Questions
software development engineer in test sdet interview questions shared by candidates
Top Interview Questions
Describe and code an algorithm that returns the first duplicate character in a string? 12 AnswersSimple Python example. Not sure it's most efficient. def findDup(str): match=[] i=1 while (i first clarify if it is ASCII or UNICODE string For ASCII, create BOOL checkArray [128] = {false}; walk the string and update the index of checkArray based of the character. for (int index=0;index< strlen(str); index++) { if (checkArray[str[index]] == true) { printf (str[index]); return; } else { checkArray[str[index]] = true; } } public class FirstDupCharacter { public static void main(String[] args) { System.out.println(findDupCharacter("abcdefghiaklmno")); } private static Character findDupCharacter(final String input) { final Set set = new HashSet(); Character dup = null; for (int i = 0; i < input.length(); i++) { if (set.contains(input.charAt(i))) { dup = input.charAt(i); break; } else { set.add(input.charAt(i)); } } return dup; } } Show More Responses String samp = "Testing"; samp = samp.toLowerCase(); char chararr[] = samp.toCharArray(); int size = chararr.length; char repeat = ' '; for (int i=0;i for (int i=0;i public static in findDuplicateChar(String s) { if (s == null) return -1; char[] characters = s.toCharArray(); Map charsMap = HashMap(); for ( int index = 0; index < characters.length; index++ ) { // insert the character into the map. // returns null for a new entry // returns the index if it previously if it existed Integer initialOccurence = charsMap.put(characters[index], index); if ( initialOccurence != null) { return initialOccurance; } //there where no characters that where duplicates return -1; } } Another python solution: def findFirstNonRepeatedCharInOneIteration(str1): for i,j in enumerate(str1): if j in str1[:i] or j in str1[i+1:]: print "First non-repeated character is "+ j break str1 = "abcdefglhjkkjokylf" findFirstNonRepeatedCharInOneIteration(str1) function getFirstDuplicateCharacter(str) { const seen = new Set(); for (const char of str) { if (seen.has(char)) return char; seen.add(char); } } import java.io.*; import java.util.*; /* * code an algorithm that returns the first duplicate character in a string? */ class Solution { public static void main(String[] args) { String input = ""; int j = removeduplicate(input); if(j == input.length()){ System.out.println("String has unique characters" ); } else{ System.out.println("duplicate character is "+input.charAt(j)); } } public static int removeduplicate(String input){ Set set = new HashSet(); boolean flag = false; int i =0; for(; i import java.io.*; import java.util.*; class Solution { public static void main(String[] args) { String input = ""; int j = removeduplicate(input); if(j == input.length()){ System.out.println("String has unique characters" ); } else{ System.out.println("duplicate character is "+input.charAt(j)); } } public static int removeduplicate(String input){ Set set = new HashSet(); boolean flag = false; int i =0; for(; i public static int removeduplicate(String input){ Set set = new HashSet(); boolean flag = false; int i =0; for(; i One or more comments have been removed. |
In a given sorted array of integers remove all the duplicates. 8 AnswersIterate the array and add each number to a set, if number is already there, it won't be added again, thus removing any duplicates. Complexity is Big-O of N The array is already sorted, no need for a set. example: 2,2,5,7,7,8,9 Just keep tracking the current and previous and the index of the last none repeated element when found a difference copy the element to the last none repeated index + one and update current and previous, no extra space and it will run in O(n) public RemoveDuplicates() { int[] ip = { 1, 2, 2, 4, 5, 5, 8, 9, 10, 11, 11, 12 }; int[] op = new int[ip.Length - 1]; int j = 0, i = 0; ; for (i = 1; i <= ip.Length - 1; i++) { if (ip[i - 1] != ip[i]) { op[j] = ip[i - 1]; j++; } } if (ip[ip.Length - 1] != ip[ip.Length - 2]) op[j] = ip[ip.Length - 1]; int xxx = 0; } Show More Responses def removeDuplicatesSecondApproach(inputArray): prev = 0 noRepeatIndex = 0 counter = 0 for curr in range(1,len(inputArray)): if (inputArray[curr] == inputArray[prev]): counter = counter + 1 prev = curr else: inputArray[noRepeatIndex+1] = inputArray[curr] noRepeatIndex = noRepeatIndex + 1 prev = curr inputArray = inputArray[:-counter] return inputArray if(inpArr[i] == inpArr[i+1]) { int repeats = 1; opArr[opPos] = inpArr[i]; int j = i + 1; while(j+1 <= inpArr.length - 1 && inpArr[i] == inpArr[j+1]) { j++; repeats++; } opArr = Arrays.copyOf(opArr, opArr.length - repeats); i = i + repeats; } else { opArr[opPos] = inpArr[i]; } opPos++; } for(int i =0; i<=opArr.length-1;i++) { System.out.println(opArr[i] + ","); } Apologies for the previous incomplete answer int[] inpArr = {1,2,2,3,4,5,5,5,8,8,8,9,13,14,15,18,20,20}; int[] opArr = new int[inpArr.length]; int opPos = 0; for(int i= 0; i<=inpArr.length - 1; i++) { if(inpArr[i] == inpArr[i+1]) { int repeats = 1; opArr[opPos] = inpArr[i]; int j = i + 1; while(j+1 <= inpArr.length - 1 && inpArr[i] == inpArr[j+1]) { j++; repeats++; } opArr = Arrays.copyOf(opArr, opArr.length - repeats); i = i + repeats; } else { opArr[opPos] = inpArr[i]; } opPos++; } for(int i =0; i<=opArr.length-1;i++) { System.out.println(opArr[i] + ","); } public static void removedup(int[] input){ int count =1; int i=0; for( ;i public static void removedup(int[] input){ int count =1; int i=0; for( ;i |
how can a particular application be tested apart from testing its functionality 4 AnswersReliability Test, Stability Test, UI Test, Platform Test, Also include, performance, stress & load testing Accessibility, user experience, globalization, localization, integration, compatibility Show More Responses One or more comments have been removed. |
Given a string (understood to be a sentence), reverse the order of the words. "Hello world" becomes "world Hello" 2 Answers2 ways. At the low level: reverse the entire string. 'Hello World' becomes "dlroW olleH". Then reverse each word, becomes "World Hello". At a higher level: Tokenize the words and push them onto a stack, then pop them out. class Solution { public static void main(String[] args) { String input = "Hello World this is a string"; reversestring(input); } public static void reversestring(String input){ // Stack stack = new Stack(); String[] str = input.split(" "); for(int i = str.length-1;i>=0;i--) { System.out.print(" "+str[i]); } } } |
Write code in your favorite programming language that will accept two strings and return true if they are anagrams. 2 AnswersThis was not really that hard to write it, however the interviewer asked me to reduce the complexity. My initial version had n*log(n) complexity and he asked me to reduce it to no more than n complexity. If you have had some upper level Computer Science classes this is not too difficult, however what they are looking for is a way to stump you. If you adjust your code or thinking rapidly to their request they will change it again until they find something that you have trouble with. Do not be discouraged by this, it is the interviewers job to determine how much you know! Found this good link. Time complexity is O(n). http://www.dreamincode.net/code/snippet1481.htm The algorithm can still be improved but gives some basic idea on how to implement. |
Given a set of numbers -50 to 50, find all pairs that add up to a certain sum that is passed in. What's the O notation for what you just wrote? Can you make it faster? Can you find an O(n) solution? Implement the O(n) solution 17 AnswersO(n^2) solution is just two double for loops. O(n log n) solution will use a binary tree O(n) solution will use a hash table O(n) solution possibility (no need for a data structure) void findpairs(int sum) { //given a set of numbers -50 to 50, find all pairs that add up to a certain sum that is passed in. if (sum == 0) { cout 0) { for(int i = 0; i((sum/2)-1) && i>-26; i--) { if( (i - sum+i) == sum) { cout << i << " " << sum+i << "\n"; } } } } @Mike "if( (i + sum-i) == sum)" will always give you "sum". Show More Responses @Mike: if (sum == 0) does not imply 0,0. It implies -50,50; -49,49; -48,48,... Has anyone found the O(n) solution??? I'm having trouble with this one... Put all the numbers from the array into a hash. So, keys will be the number and values of the keys be (sum-key). This will take one pass. O(n). Now, foreach key 'k', with value 'v': if k == v: there is a match and that is your pair. this will take another O(n) pass totale O(2n) ~ O(n) Easiest way to do it. Written in python. If you consider the easiest case, when our summed value (k) is 0, the pairs will look like -50 + 50 -49 + 49 -48 + 48 etc.... etc... So what I do is generalize the situation to be able to shift this k value around. I also allow us to change our minimums and maximums. This solution assumes pairs are commutative, i.e. (2, 3) is the same as (3, 2). Once you have the boundaries that you need to work with, you just march in towards k / 2. This solution runs in O(n) time. def pairs(k, minimum, maximum): if k >= 0: x = maximum y = k - maximum else: x = k + maximum y = minimum while x >= k / 2 and y <= k / 2: print str(x) + " , " + str(y) + " = " + str(x + y) x = x - 1 y = y + 1 here is my solution using hash table that runs in O(2n) => O(n): public static String findNums(int[] array, int sum){ String nums = "test"; Hashtable lookup = new Hashtable(); for(int i = 0; i < array.length; i++){ try{ lookup.put(array[i], i); } catch (NullPointerException e) { System.out.println("Unable to input data in Hashtable: " + e.getMessage()); } } int num2; int num1; for (int i = 0; i < array.length; i++){ num2 = sum - array[i]; Integer index = (Integer)lookup.get(num2); if ((lookup.containsKey(num2)) && (index != i)){ num1 = array[i]; nums = array[i] + ", and " + num2; return nums; } } //System.out.println(lookup.get(-51)); return "No numbers exist"; } The number you're looking for is T. You can just create an array of size 101. Then you loop through the array, and drop each number i in cell of index i-50. Now you do a second pass, and for each number, you look at the number at index T-i-50. If there's something there, you have a pair. typedef pair Pair; list l; //create an empty list of tuples pairofsum(l,10); // an example of how to call the function which adds to your list of tuples the possible pairs of the sum void pairofsum(list& l,int sum) { if(sum==0) { Pair p; loadPair(p,0,0); l.push_back(p); for(int i=1;i<51;i++) { loadPair(p,i, -i); l.push_back(p); } } else if (sum<0) { Pair p; for(int i=0;i+-sum<51;i++) { loadPair(p,i,-(i+-sum)); l.push_back(p); } for(int i=1;i<=-sum/2;i++) { loadPair(p,-i,sum+i); l.push_back(p); } } else { Pair p; for(int i=1;sum+i<51;i++) { loadPair(p,-i,sum+i); l.push_back(p); } for(int i=0;i<=sum/2;i++) { loadPair(p,i,sum-i); l.push_back(p); } } } void loadPair(Pair& p, int f, int s) { p.first=f; p.second=s; } Here is my C# implementation. It runs O(N) and doesn't include duplicate pairs (e.g. including [50,-50] as well as [-50,50]). static void FindPairs(int sum) { for (int i=-50; i=-50) { Console.WriteLine(i + " " + otherNum); } } } Solution with no duplicates: @Test public void findPairsTest() { // TestCases // Alternately you can put this test cases in dataprovdier findPairs(50); findPairs(20); findPairs(-20); findPairs(-50); findPairs(0); } private void findPairs(Integer sum) { HashMap inputPair = new HashMap(); HashMap outputPair = new HashMap(); for(int i=-50; i<=50; i++) { inputPair.put(i, sum-i); } // print pairs for(Integer key : inputPair.keySet()) { Integer potentialOtherNum = inputPair.get(key); if(inputPair.containsKey(potentialOtherNum) && potentialOtherNum < key) { outputPair.put(key, potentialOtherNum); } } System.out.println(outputPair.entrySet().toString()); } Show More Responses Use two pointers, one at the begin, one at the end, let us call the pointer begin and end, the array is named nums. If nums[begin]+nums[end]>target, end--;if end Half=sum/2; i=1; While (half+i -51) { first = half-i; second = half+i; System.out.println(“” + first + “, “ + second); } half=sum/2; i=1; While (half+i \ -51) { first = half-i; second = half+i; System.out.println(“” + first + “, “ + second); } Weirdly the less than and greater than signs make the text between them invisible. The conditional statement is supposed to say Half=sum/2; i=1; While (half+i LESSTHAN 51 && half-i GREATERTHAN -51) One or more comments have been removed. |
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?" 12 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. 1 black : 19 white. .. 3 socks 2 black : 18 white ... 3 socks 3 black : 18 white ... 3 socks 4 black : 16 white.. . 3 socks 5 black : 15 white .. . 3 socks 6 black : 14 white ... 3 socks . .. . .3 socks. why? The worst case scenario is always 2 of one color and one of the other. Actually, the worst case scenario is you could pick 19 socks and still have ALL the same color if only one is a different color. My solution is "Turn on the light". It also does not say the two types of socks are evenly divided in the drawer :) |
Are two words palindrome of each other? 7 AnswersI solved by Sorting as well as using HashMap. I was asked to implement sort which I had never encountered in my past interviews. Create a hashmap where int specificies the number of times the char appears in the string. process the first string, then ensure the 2nd has the same chars as the first in the same #. First check if the strings are the same length and if they are, run a loop for the number of times as there are letters and one at a time check the first letter of one word and the last letter of the other and then the 2nd letter and 2nd to last etc and if they all check out then it is a palindrome, otherwise it is not Show More Responses My version public class PalindromTwoWords { boolean isPalindrome(String a, String b) { boolean isPalindrome = false; for (int i = 0; i 0; j--) { if (a.substring(0, i).equals(b.substring(j))) isPalindrome = true; } } return isPalindrome; } } Sorry when i pasted the code some words escaped. public class PalindromTwoWords { boolean isPalindrome(String a, String b) { boolean isPalindrome = false; for (int i = 0; i 0; j--) { if (a.substring(0, i).equals(b.substring(j))) isPalindrome = true; } } return isPalindrome; } } 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) experts on Prepfully? Really helps to get some real-world practice and guidance. prepfully.com/practice-interviews One or more comments have been removed. |
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. 6 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 //I hope this Solution Would help public ListNode reverse(ListNode head) { ListNode current=head; ListNode previous=null; ListNode next=null; while(current!=null) { next=current.next; current.next=previous; previous=current; current=next; } return previous; } public ListNode addTwoNumbers(ListNode head1,ListNode head2) { head1=reverse(head1); head2=reverse(head2); int sum=0;int carry=0; LinkedList result = new LinkedList(); while(head1!=null || head2!=null ) { sum=((head1==null) ?0 :head1.value )+ ((head2==null) ?0 :head2.value)+carry; //carry=0; if(sum>9) { carry=sum/10; sum=sum%10; } else { carry=0; } result.add(sum); if(head1!=null) { head1=head1.next; } if(head2!=null) { head2=head2.next; } } if(carry!=0) { result.add(carry); } ListNode dummy=reverse(result.head); return dummy; } |
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 Responses def 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 |
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