Yewes Software interview question

You have one weight-balance and 12 identical-looking balls. One of the balls is either heavy/light than the rest. Within 3 iterations, find out which ball is the odd one and whether it is heavy or light compared to the rest.

Interview Answers

Anonymous

27 Aug 2012

A long answer. Took around 25-30 minutes to get to the answer. You can try it or Gooooooooogle it.

Anonymous

30 Aug 2012

var arr:Array = [0,1,1,1,1,1,1,1,1,1,1,1,1]; var a:int = arr[0]; var changePos:int = 0; var isHeavy:Boolean = false; for(var i:int = 1; i arr[changePos+1]) { isHeavy = true; } else { isHeavy = false; } } else { if(arr[changePos] > arr[changePos-1]) { isHeavy = true; } else { isHeavy = false; } } if(isHeavy) { trace("Odd num position is ",changePos," Which is greater than others"); } else { for(var j:int = 1; j arr[j]) { a = arr[j]; changePos = j; } } trace("Odd num position is ",changePos," Which is lesser than others"); }