Order the Queue by Hand

Advanced

For a teaching exercise the queue must be sorted ascending without relying on the built-in sort, to show the underlying comparisons. Implement the ordering yourself.

Implement `solve(List<Integer> nums)` to return the values sorted ascending WITHOUT calling List.sort(). Implement the comparisons yourself.

Examples

Input[5, 2, 9, 1, 7]
Output[1, 2, 5, 7, 9]
Input[3, 1]
Output[1, 3]
Hints
  • Bubble sort: repeatedly swap adjacent out-of-order pairs.
  • Use a temp variable to swap two elements.
Anonymous Apex

Your code runs in a secure sandbox against multiple hidden test cases. The problem is solved only when every test passes. Each run is isolated and any data changes are rolled back automatically.