# 15 k

Questions d'entretien pour Controls Engineer partagées par les candidats

## Principales questions d'entretien

Trier: Pertinence|Populaires|Date
On a demandé à un Software QA Engineer...6 octobre 2010

### There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly?

46 réponses

Swaz answer is almost correct however it does not work in all scenarios. lets assume: box 1 is labelled Oranges (O) box 2 is labelled Apples (A) box 3 is labelled Apples and Oranges (A+O) and that ALL THREE BOXES ARE LABELLED INCORRECTLY" Pick a fruit from box 1, 1) if you pick an Orange: - box 1's real label can only be O or A+O - box 1's current label is O - since ALL LABELS ARE INCORRECT then box 1's real label can not be O - box 1's new label should then be A+O by elimination - since ALL LABELS ARE INCORRECT - box 2's label is changed to O - box 3's label is changed to A - SOLVED 2) if you pick an Apple: - box 1's real label can only be A or A+O - box 1's current label is O - since ALL LABELS ARE INCORRECT then box 1's real label can not be O - this still leaves us with the choice between label A and label A+O - which would both be correct - FAILURE Solution: The trick is to actually pick a fruit from the A+O labeled box Pick a fruit from box 3: 1) if you pick an Orange: - box 3's real label can only be O or A - box 3's current label is A+O - since ALL LABELS ARE INCORRECT then box 3's real label can not be A+O - box 3's new label should then be O by elimination - since ALL LABELS ARE INCORRECT - box 1's label is changed to A - box 2's label is changed to A+O - SOLVED 2) if you pick an Apple: - box 3's real label can only be O or A - box 3's current label is A+O - since ALL LABELS ARE INCORRECT then box 3's real label can not be A+O - box 3's new label should then be A by elimination (not O) - since ALL LABELS ARE INCORRECT - box 1's label is changed to A+O - box 2's label is changed to O - SOLVED Moins

It's easier to draw it out. There are only 2 possible combinations when all labels are tagged incorrectly. All you need to do is pick one fruit from the one marked "Apples + Oranges". If it's Apple, then change "Apple + Orange" to "Apple" The "Apple" one change to "Orange" The "Orange one change to "Apple + Orange" If it's Orange, then change "Apple + Orange" to "Orange" The "Apple" one change to "Apple + Orange" The "Orange" one change to ""Apple" Moins

All the three boxes are names incorrectly. SO the bax lebeled Apples+Oranges contains only Oranges or Only Apples. Pick one fruit from it. If it is Orange then lebel the box as Orange. So the box lebeled Oranges contains Apples and the remaining contains both. Moins

Afficher Plus de réponses

### A dwarf-killing giant lines up 10 dwarfs from shortest to tallest. Each dwarf can see all the shortest dwarfs in front of him, but cannot see the dwarfs behind himself. The giant randomly puts a white or black hat on each dwarf. No dwarf can see their own hat. The giant tells all the dwarfs that he will ask each dwarf, starting with the tallest, for the color of his hat. If the dwarf answers incorrectly, the giant will kill the dwarf. Each dwarf can hear the previous answers, but cannot hear when a dwarf is killed. What strategy should be used to kill the fewest dwarfs, and what is the minimum number of dwarfs that can be saved with this strategy?

21 réponses

Think broadband communication. Exploit the capabilities of the communications medium. A minimum of nine dwarves can be saved based on the information provided in the original post I viewed. The strategy is for each dwarf to employ the expected language to communicate the color of their own hat to the giant, while simultaneously employing a vocal pitch protocol to indicate the color of the hat of the dwarf in front of him, high pitch for white and low pitch for black. The original post, indicates the dwarves may collude prior to the distribution of hats, so there is opportunity to negotiate such a simple broadband communication protocol. The tallest dwarf only has a 50/50 chance since the number of black and white hats in play is not known (rhetorical question, what are the odds the tallest dwarf's hat is black if he turns to find that all nine hats in front of him are white? I don't know, but odds are high that the giant is a sadistic bloke). The original post I viewed is here. http://www.businessinsider.com/toughest-job-interview-questions-2013-7#a-dwarf-killing-giant-lines-up-10-dwarfs-from-shortest-to-tallest-each-dwarf-can-see-all-the-shortest-dwarfs-in-front-of-him-but-cannot-see-the-dwarfs-behind-himself-the-giant-randomly-puts-a-white-or-black-hat-on-each-dwarf-no-dwarf-can-see-their-own-hat-the-giant-tells-all-the-dwarfs-that-he-will-ask-each-dwarf-starting-with-the-tallest-for-the-color-of-his-hat-if-the-dwarf-answers-incorrectly-the-giant-will-kill-the-dwarf-each-dwarf-can-hear-the-previous-answers-but-cannot-hear-when-a-dwarf-is-killed-the-dwarves-are-given-an-opportunity-to-collude-before-the-hats-are-distributed-what-strategy-should-be-used-to-kill-the-fewest-dwarfs-and-what-is-the-minimum-number-of-dwarfs-that-can-be-saved-with-this-strategy-11 Moins

the question does not mention that there will be equal number of white and black hats ! Moins

What is the minimum number of dwarfs that can be saved with this strategy? 9 First of all, let's numerate the dwarfs as N1, N2, N3, etc. with N10 being the tallest. Now, N10 will state the color of N9 as his own answer, "My hat is WHITE". Based on this answer, N9 will state his color with a positive statement if the color of N8 is the same as his, "My hat is WHITE". Based on N8's answer, N8 knows that his color is WHITE, now, he will state his color depending on N7. Let's say N7 is black, so N8 will state, "My hat is NOT BLACK". N7 knows that his color is BLACK, but N6 is white, so he will use a negative statement, "My hat is NOT WHITE" and so on. Full example: N10 = BLACK N9 = WHITE N8 = WHITE N7 = BLACK N6 = WHITE N5 = WHITE N4 = WHITE N3 = BLACK N2 = BLACK N1 = WHITE N10: My hat is WHITE (Dies) N9 = My hat is WHITE N8 = My hat is NOT BLACK N7 = My hat is NOT WHITE N6 = My hat is WHITE N5 = My hat is WHITE N4 = My hat is NOT BLACK N3 = My hat is BLACK N2 = My hat is NOT WHITE N1 = My hat is WHITE N10 will have a 50/50 chances of survival... I'm sorry N10, I couldn't save you :'( Moins

Afficher Plus de réponses

### Find the union of two strings?

14 réponses

public static void UnionOfStrings() { String s1 = "XYZ"; String s2 = "YZOP"; String s3 = s1.concat(s2); char ch[] = s3.toCharArray(); Set setChars = new TreeSet(); for(char c : ch) { setChars.add(c); } System.out.println(setChars.toString()); } Output : [O, P, X, Y, Z] Moins

public static void IntersectionOfStrings() { String s1 = "XYZYYP"; String s2 = "YZOPP"; Set setChars = new TreeSet(); char c[] = s1.toCharArray(); for(char x : c) { if(s2.indexOf(x)!=-1) { setChars.add(x); } } System.out.println(setChars.toString()); } OUTPUT : [P, Y, Z] Moins

public static void IntersectionOfStrings() { String s1 = "yybbb78"; String s2 = "y7"; if(s1.length() &gt; s2.length()) intersect(s1,s2); else intersect(s2,s1); } public static void intersect(String first, String second) { Set setChars = new TreeSet(); char c[] = first.toCharArray(); for(char x : c) { if(second.indexOf(x)!=-1) { setChars.add(x); } } System.out.println(setChars.toString()); } Moins

Afficher Plus de réponses

### Draw a bridge and you have three people trying to cross? Seriously&amp;gt;

12 réponses

I actually had an interview with Clearleap yesterday and I can tell you that above comments are not true. Interview process was very professional. Problem solving questions were quite interesting and I enjoyed them! Moins

Unfortunately, your response is quite immature and therefore I withdraw myself from this conversation. Moins

4 people actually (you missed the requirement). Looks like you did not pay attention during the interview. These types of questions are designed to figure out your: a) Problem solving skills b) Creativity c) Ability to work under pressure And most of all to observe your thought process. But in your Senior QA Engineer role you should have know about that already, right? Moins

Afficher Plus de réponses

### Write a function in any language that will print "AN" if a number is divisible by 8, "ANIM" if divisible by 16 and "ANIMAL" if divisible by 32.

11 réponses

Good work. I checked your code and it runs. This is a variation on the classic FizzBuzz coding question. One suggestion: You can simplify your code by printing the user prompt in the input function. # i = input("Enter a number or press Q to quit:") Another suggestion: Make the letter "q" case insensitive by passing the ".lower()" method after your input string # i = input("Enter a number or press Q to quit:").lower() One thing: You don't need the following if clause which I've commented out. This condition is already checked and handled outside of the try block. """ try: n = int(i) # if i == "q": # print("Goodbye!") """ Moins

Use string builder to improve the run time.

public static String printAnimal(int num) { if (num &gt;= 8 &amp;&amp; num = 16 &amp;&amp; num = 16 &amp;&amp; num &lt; 32) { if (num % 32 == 0) { return "ANIMAL"; } } return "Number Not Divisible by 8"; } Moins

Afficher Plus de réponses

### From a given list of array (Not sorted) find the second largest value Find the prime numbers from the given list of array (1 -100) Test plan for Amazon login screen

10 réponses

The second question is pretty simple, and it does relate back to test cases. Think of every number as a different state of a program, and proceed as follows: Create a new list to house all your prime numbers. Add 2, 3, 5, and 7 to it. Then, iterate through your list. If the number you're looking at can be taken to 0 with a modulus of 2, 3, 5, or 7, ignore it. If passes all those tests, add it to your list of primes. This will give you a list of all prime numbers between 0 and 100. The trick is that if you know the largest number in the list, you can find all prime numbers in the list just by knowing all prime numbers less than the square root of your largest number (in this case, sqrt(100) = 10 and we look at 2, 3, 5, and 7. If the list was up to 121, we'd look at 2, 3, 5, 7, and 11.) This both gets you your answer AND minimizes the runtime of your program. I don't have any fancy tricks for the first question, but given that sorting is often time-consuming I would go with something like this: 1: Iterate through the list. Use two variables, a "largest" and "second largest." These two should start at 1 and 0 respectively. 2: With every number N, compare the value of N to "largest" and "second largest." 3: If N is larger than "second largest" and smaller than "largest," replace "second largest" with N. 4: If N is bigger than both "largest" and "second largest," then make "second largest" the value of "largest" and make the value of "largest" equal to N. This is very much a "brute force" solution. It may not be the best, but like I said - I don't know any special tricks for this problem. Moins

x = [10,21,2,3,4,5,6,7,8,9,12,45,67,88,888,4,4,5,3,3,45,37,34,6,777] y = [0,0] for(i= 0 ;i y[0] ){ y[0]= x[i] } } for(i= 0 ;i y[1] &amp;&amp; x[i] !== y[0]){ y[1]= x[i] } } console.log(y[1]) Moins

var foo = []; var bar = [] for (var i = 1; i &lt;= 100; i++) { foo.push(i); } for (var i = 0; i &lt; foo.length ; i++) { if(isPrime(foo[i])){ bar.push(foo[i]) } } function isPrime(n){ if(n&lt;=1){ return false} if(n&lt;=3){ return true} if(n === 5 || n === 7) { return true} if(n % 2 === 0 || n % 3 === 0 || n % 5 === 0 || n % 7 === 0) {return false} return true; } console.log(bar) Moins

Afficher Plus de réponses

### Reverse a string

9 réponses

def main(): str=input("Enter a string") print(str[: : -1]) main()

Javascript const foo = "bar"; const baz = foo.split('').reverse().join(''); :^) Moins

How about this: for(int index = 0; index &lt; input.length() ; index++ ) { output.insert(0, input.charAt(index)); } Moins

Afficher Plus de réponses

### find the largest sum of consecutive integers in an array

8 réponses

int consecutive_Sum (int arr[]){ int prev =0,temp_sum=0,ret_sum=0,i=0; for(i=0;arr[i]!='\0';i++){ if(arr[i] == (prev+1)){ temp_sum += arr[i]; prev = arr[i]; if(ret_sum &lt; temp_sum){ ret_sum = temp_sum; } }else{ temp_sum = arr[i]; prev = arr[i]; } } return ret_sum; } Moins

def maxSubArray(self, nums: List[int]) -&gt; int: result = -sys.maxsize sum_ = 0 for i in range(0, len(nums)): sum_ = max(sum_ + nums[i], nums[i]) result = max(result, sum_) return result Moins

a = [29, -22, 0.22, 0, 999, -22] a.sort() max_a = a[-1] print(max_a)

Afficher Plus de réponses

### Given an array with numbers 1-5, how would you subtract one number from every EVEN number in each index?

8 réponses

public class Animal { public static void main(String[] args) { int[] nums={3,4,5,6,7,8}; System.out.println(Arrays.toString(substract(nums,6))); } static int[] substract(int[] nums, int n){ //int[] nums2=nums; for (int i=0; i Moins

for(int i=0;i

public class am2 { public static void main(String[] args) { int[] a = {1,2,3,4,5}; int sub = 0; for (int i = 0; i &lt; a.length; i++) { if(i%2==0 &amp;&amp; i!=0) { sub = a[i]-1; a[i] = sub; } } for (int A:a) { System.out.println(A); } } Moins

Afficher Plus de réponses

### input string = aabbbccccaaa, maintain the insertion order and output should be a2b3c4a3

8 réponses

//input string = aabbbccccaaa, maintain the insertion order and output should be a2b3c4a3 public class Test { public static void process(String mystring) { StringBuilder sb = new StringBuilder(); char[] mychar = mystring.toCharArray(); int count = 1; for(int i=0; i&lt; (mychar.length)-1;i++) { System.out.println("mychar[p1]: "+mychar[i]+" mychar[p2]: "+mychar[i+1]); if(mychar[i] == mychar[i+1]) { count = count+1; System.out.println("count: "+count); } else { sb.append(mychar[i]); sb.append(count); count = 1; } if(i==(mychar.length)-2) { sb.append(mychar[i+1]); sb.append(count); } } System.out.println(sb.toString()); } public static void main(String[] args) { process("aabbbccccaaa"); process("ggggyyynnnkkkkkk"); process("aabbcccdef"); process("abcdefghj"); } } Moins

public class Stringoupt { int count =0; void outputString(String str){ char st = str.charAt(0); for(int i=0;i Moins

a = "aabbbccccaaa" if not a: print ("") if len(a) == 1: print (a+"1") start, end = 0, 1 new_string = a[0] count = 1 while end &lt; len(a): if a[start] == a[end]: count += 1 end += 1 else: new_string += str(count) count = 1 start, end = end, end+1 new_string += a[start] new_string += str(count) print (new_string) Moins

Afficher Plus de réponses
1 - 10 sur 15 203 Questions d'entretien