American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

6 PM – USACO Bronze – Gamas

April 25 @ 6:00 pm - 7:00 pm

Today We Did
  1. We went over the homeworks
    1. printForwardEveryOtherElement(int[])
    2. findMax(int[])
    3. printForwardUntilMiddleUsingList(List<Integer>)
    4. printReverse(List<Integer>)
    5. reverseArray(int[])
Homework

Inside Apr25InsertMiddleOfArray.java

  1. Finish the implementation of below
    1. 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;
      }
  2. Add a new method and finish the implementation like below
    1. 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"]
      }

Details

Date:
April 25
Time:
6:00 pm - 7:00 pm
Verified by MonsterInsights