Skip to main content

Practice · 4 of 5

Halves swap

CHALLENGE
Difficulty: intermediate+25 XP

Implement void swapHalves(ArrayList<Integer> list): swap the halves in place. For odd sizes the middle element belongs to the SECOND half: [1, 2, 3, 4, 5] → [3, 4, 5, 1, 2]. Work the index mapping on paper for sizes 4 and 5 before coding.

Back to lesson: Practice: ArrayList lab