- This event has passed.
6 PM – USACO Bronze – Gamas
April 25, 2025 @ 6:00 pm - 7:00 pm
Today We Did
- We went over the homeworks
- printForwardEveryOtherElement(int[])
- findMax(int[])
- printForwardUntilMiddleUsingList(List<Integer>)
- printReverse(List<Integer>)
- reverseArray(int[])
Homework
Inside Apr25InsertMiddleOfArray.java
- Finish the implementation of below
-
public String[] createNewArrayWithAdditional(String[] original, int index, String word) { /** * String[] original = new String[]{"a", "c", "d", "e"}; * String[] newArray = createNewArrayWithAdditional(original, 3, "z"); * * newArray = a,c,d,e,z * original = a,c,d,e */ String[] result = new String[original.length+1]; int originalIndex = 0; int newIndex = 0; while(originalIndex < original.length) { /** * 1. copy each element from the original to the result one element every loop. * 2. when originalIndex == index, insert word into result array. * 3. everytime it loops, you need to increment originalIndex and newIndex. * Except when originalIndex == index. */ } return result; }
-
- Add a new method and finish the implementation like below
-
public static String[] copyAndDeleteInTheMiddle(String[] arr, int index) { // Write a method that returns a new array that contains all the elements of the input // array arr, except for the element at the specified index, which is removed. // The elements after the specified index are shifted to fill the gap. // Example: // String[] letters = {"a", "b", "c", "d", "e"}; // String[] newArr = removeAtIndex(letters, 2); // newArr = ["a", "b", "d", "e"] }
-