One possible solution i can think of is divide the array in two parts , odd and even , sort them and use be.low algo , like if we have the array say N=10 and array is 3 10 2 7 5 3 4 6 9 8 1 after dividing and sorting
array will be 1 3 5 7 9 2 4 6 8 10
now calculate length of even and odd list ,if length is odd,then divide it into 2 equal parts and align alone one middle value like
1 3 5 7 9 2 4 6 8 10
now swap all values of two list except first value based on middle if each sub-list
1 7 5 3 9 2 8 6 4 10
i have not coded it yet so feel free to comment if it fails for any test case :)
2 comments :
Do you have a solution to this problem?
If you find the solution please update it. I will be looking for solution to this puzzle.
Anyways, can you give me link to Paypal Puzzles. I have paypal interview after 3 days.
Post a Comment