## Raj

BAN USER- 0of 0 votes

AnswersGiven an input array. Write an Algorithm to

- Raj in United States

print all possible combinations in the array that

sum up to given input K.

Eg : If input array is {1,2,3,4,5} and K is 7

then O/P should be

1 6

3 4

2 5| Report Duplicate | Flag | PURGE

CGI-AMS Senior Software Development Engineer - 0of 0 votes

AnswersWrite a program to swap every two nodes in a linked list . IF the number of nodes is odd then retain the last node.

- Raj in United States| Report Duplicate | Flag | PURGE

Assuming the number of elements in the array is even and the sum of elements is also even.

1) Sort the array.

2) Use two variables. One to store the sum of elements at indexes that leave a remainder of 0 or 4 when divided by 4. The other to store the sum of elements at indexes that leave a remainder of 1 or 2 when divided by 4.

3) If the two variables are equal then the array can be divided into two halfs with equal sum.

TC : O(n)

RepSpent several months writing about boyfriend ki shadi todne ke upay .Spent 2001-2007 donating carp in Las Vegas, NV. My ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

It is just not the pairs. 1 2 4 should also get printed when K is 7.

- Raj October 15, 2013