Data Structures19 sections · 729 units
Open in Course

Problem - Reorder List

Combine multiple techniques

Given a list L0L1...Ln1LnL_0 \to L_1 \to ... \to L_{n-1} \to L_n, reorder it to L0LnL1Ln1L2Ln2...L_0 \to L_n \to L_1 \to L_{n-1} \to L_2 \to L_{n-2} \to ... Example: 12341 \to 2 \to 3 \to 4 becomes 14231 \to 4 \to 2 \to 3. This problem combines three techniques you've learned:

1.1. Find the middle of the list

2.2. Reverse the second half

3.3. Merge the two halves alternately It's a great test of whether you can combine basic building blocks. Constraints: up to 51045 \cdot 10^4 nodes, values from 11 to 10001000.