← Unit 4 · all exercises
Saved in this browser only

Sort it yourself

Return a new array with the same numbers ordered smallest to largest. Write the sort yourself rather than calling a library method.

int[] sorted(int[] values)

Solution.java
Loading editor…
Results

Examples

  • java.util.Arrays.toString(Solution.sorted(new int[]{3, 1, 2})) → [1, 2, 3]
  • java.util.Arrays.toString(Solution.sorted(new int[]{5})) → [5]

There are also 3 hidden tests you can't see. Solve the problem, not the examples.