Loading...
Loading...
Loading...
A parcel counter sorts parcel weights so that all even weights come first and all odd weights after them. Inside each group, weights go from smallest to largest.
Example 1
Input
7 5 2 8 1 4 7 3
Output
2 4 8 1 3 5 7
Evens 2 4 8, then odds 1 3 5 7.
Example 2
Input
4 -3 -4 0 9
Output
-4 0 -3 9
A negative odd number gives remainder -1, not 1.
Try the problem first. Open one hint at a time.
Sort the whole array first with Arrays.sort.
Then print the even ones in order, and in a second loop the odd ones.
Test for odd with w % 2 != 0, which also works for negatives.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor