Explanation of the 2018 AP CSA FRQ - Question 4 (Part B)

Prior Knowledge

  1. Helper Methods in the Problem

    • getColumn(int[][] arr2D, int c): Returns an array containing all elements in column c of a 2D array.

    • containsDuplicates(int[] arr): Returns true if the array contains duplicate values.

    • hasAllValues(int[] arr1, int[] arr2): Returns true if all elements in arr1 are present in arr2.

  2. Latin Square Definition

    • The first row has no duplicate values.

    • All values in the first row appear in every row of the square.

    • All values in the first row appear in every column of the square.

  3. Preconditions

    • The input array is guaranteed to be square (equal number of rows and columns).

    • At least one row exists in the array.

Solution