Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 579 |
@sriramgoparaju99 | 532 |
@yashkaril4 | 517 |
@praveenbgp6 | 517 |
@prankursharma31 | 489 |
@rdakka | 465 |
@sonamnigam1999 | 441 |
@purohitmn02 | 427 |
@sonamkumari63928 | 426 |
@ShubhankarPandey | 419 |
Complete Leaderboard |
Given a singly linked list: A0→A1→…→An-1→An, reorder it to: A0→An→A1→An-1→A2→An-2→…
For example: Given 1->2->3->4->5 its reorder is 1->5->2->4->3.
Note: It is recommended do this in-place without altering the nodes' values.
Example 1:
Input: LinkedList: 1->2->3 Output: 1 3 2
Example 2:
Input: LinkedList: 1->7->3->4 Output: 1 4 7 3.
Your Task:
The task is to complete the function reorderList() which should reorder the list as required. The reorder list is automatically printed by the driver's code.
Note: Try to solve without using any auxilliary space.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes