Keep it simple ….

Random Musings

Archive for the ‘Puzzles’ Category

RED/GREEN/BLUE balls

with 2 comments

You are a vendor having some balls:-

1) 1994 RED balls
2) 1995 GREEN balls
3) 1996 BLUE balls

now if you tak two balls of different colors , then you can convert them to 1 ball of the third color

eg. one RED and one GREEN ball combine to form one BLUE ball

now you have to convert all the balls into one single color.

How will you do this ?

Written by Abhinav Jain

March 16, 2007 at 10:17 am

Posted in Logical, Puzzles

Sum of two numbers in an array to be equal to K

with one comment

You are given an array of numbers, and a constant K.

You need to find two elements from the array whose SUM is equal to K . (all such pairs)
Eg .

Let the array be

1 2 3 4 and the constant be 7 ,

then your output should be 3 and 4

Written by Abhinav Jain

March 16, 2007 at 10:08 am

Posted in Programming, Puzzles

Finding the non duplicate number in an array of 2n+1 numbers

with 4 comments

Programming :-

You are given an array of numbers, of size 2n + 1 . Now n of them are repeated, i.e there are n pairs of same number and a single number that does not have any pair. Find the number that does not have any pair. Try to keep the complexity to O(n) .

Eg .

The elements in the array can be :-

1 2 3 2 1 3 5

You want to output to be

5

Written by Abhinav Jain

March 16, 2007 at 10:05 am

Posted in Programming, Puzzles