X482: Make Perfect Array

The mere presence of oversized arrays makes Priscilla Perfect sick to her stomach. Such wasted space is an imperfection she cannot bear. As her oldest and dearest friend this worries you greatly. If you were a doctor you might try to find a cure to her sickness, but you are a programmer. A program must be written to alleviate her pain!

For any array given that has empty slots create a new array that is perfect. Unused slots will have a value of 0. All unused slots are guaranteed to be at the end of the array. There will never be unused slots in the middle.
java.util.Arrays has been enabled.

Examples:

makePerfect({1, 1, 4, 5, 6, 0, 0, 0, 0}) -> {1, 1, 4, 5, 6}
makePerfect({1, 3, 4, 2, 6, 0, 0, 0, 0}) -> {1, 3, 4, 2, 6}

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.