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}
1 public int[] makePerfect(int[] arr)
2{
3
4
5}
X424: ArrayList - Coding Practice
Write a method that reverses the contents of any given string array, then return the reversed conents as an arraylist.
If the given array list is empty, return an empty array list.
Examples:
reverseContents({1, 2, 3, 4}) -> new java.util.ArrayList<Integer>() {{add(4); add(3); add(2); add(1);}}
1 public ArrayList<Integer> reverseContents(int[] contents) {
2
3}
4