Reorder List

LINKED LIST
RECURSION

Problem

Rearrange a list so that the order is the first element, then the last element, followed by the second element, then the second-last element, and so on.

Examples

reorderList([1,2,3,4]) // returns [1,4,2,3] /* Input: 1 -> 2 -> 3 -> 4 Output: 1 -> 4 -> 2 -> 3 */ reorderList([1,2,3]) // returns [1,3,2] /* Input: 1 -> 2 -> 3 Output: 1 -> 3 -> 2 */
Loading...
1
2
3
4