Outside In
Rearrange nums by taking items from the two ends in turns: first the leftmost item, then the rightmost, then the second from the left, then the second from the right, and so on until every item has been taken once. For [1, 2, 3, 4, 5] this gives [1, 5, 2, 4, 3].
Return the new list. An empty nums gives an empty list. Do not change nums.
Example 1
nums [1,2,3,4,5]
returns [1,5,2,4,3]
Left end 1, right end 5, then 2, then 4, and the middle item 3 comes last.
Example 2
nums [1,2,3,4]
returns [1,4,2,3]
With an even count the two middle items 2 and 3 are taken in that order.
Constraints
0 <= len(nums) <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.