Oracle Interview Question

Anonymous User
1453
Oct 07, 2021

Given a Single Linked list of length N ( N is always even).

Perform the following operation:

  1. Reverse the linked list
  2. Delete the nodes at the end and carry the operation again.

Note : No extra memory and number of nodes is 10^5

ex:
i/p
1->2->3->4->5->6

o/p
6->2->4->3->5->1

Explanation:

1 2 3 4 5 6 -> 6 5 4 3 2 1 -> 6 2 3 4 5 1 -> 6 2 4 3 5 1

first we reverse the list we get 6 5 4 3 2 1. we then delete the node 6 and 1 so our linkedList looks something 5 4 3 2

we reverse it 2 3 4 5. delete end 3 4

reverse it 4 3 and delete the ends.

so effectively list is 6 2 4 3 5 1.

I could not solve it.

Comments (4)