Skip to content

Instantly share code, notes, and snippets.

@CompSciRocks
Created November 27, 2018 13:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save CompSciRocks/ec22fce724fe4cf9e8eed09d543f517d to your computer and use it in GitHub Desktop.
Working solution for the 2018 AP Computer Science ArrayTester Free Response question https://compsci.rocks
public static int[] getColumn(int[][] arr2D, int c) {
int[] out = new int[arr2D.length];
for (int r=0; r<arr2D.length; r++)
out[r] = arr2D[r][c];
return out;
}
public static boolean isLatin(int[][] square) {
int[] firstRow = square[0];
if (containsDuplicates(firstRow))
return false;
for (int r=1; r<square.length; r++)
if (!hasAllValues(firstRow, square[r]))
return false;
for (int c=0; c<square[0].length; c++)
if (!hasAllValues(firstRow, getColumn(square, c))
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment