Keep it simple ….

Random Musings

Archive for the ‘Programming’ Category

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