Implementing 2D Array Algorithms FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A signal mast stores integers in a rectangular grid. Write a method that reverses one entire column in place.

public static void reverseColumn(int[][] grid, int col)
{
    /* complete the method */
}

(a) State the first pair of rows that should swap when the grid has 4 rows. (b) Write a loop that swaps from the top and bottom toward the middle. (c) Give column 0 after reversing {8, 3, 5, 1} from top to bottom.

Question 2 of 5

A cider loft stores barrel counts. Complete maxInSection so it returns the maximum in the inclusive rectangular subsection from (r1, c1) to (r2, c2).

public static int maxInSection(int[][] grid, int r1, int c1, int r2, int c2)
{
    int max = grid[r1][c1];
    /* write the remaining statements */
    return max;
}

Use {{4, 11, 2}, {9, 3, 8}} with r1 = 0, c1 = 1, r2 = 1, c2 = 2.

(a) List the cells that belong to the subsection. (b) Write the nested loops that update max. (c) State the returned value.

Question 3 of 5

A dock inspector checks whether every value in one row is at least a safety floor.

(a) Write boolean rowAllAtLeast(int[][] grid, int row, int floor) that returns true only if every entry in that row is >= floor. (b) Explain one way the method can return false early. (c) Using row {6, 4, 9} and floor 5, state the return value and identify the cell that decides it.

Question 4 of 5

A carousel shelf rotates one row to the right: the last value moves to index 0, and every other value in that row shifts one place right.

public static void rotateRowRight(int[][] grid, int row)
{
    /* complete the method */
}

Row 1 starts as 7, 0, 4, 2.

(a) Identify which value must be saved first. (b) Write the shift loop from the right end toward the left. (c) List the row after the rotate.

Question 5 of 5

A stamp sheet looks for a duplicated value inside a single row of a rectangular grid.

(a) Write boolean rowHasDuplicate(int[][] grid, int row) that returns true if two different columns in that row store the same integer. (b) Explain why comparing a cell with itself must not count as a duplicate. (c) Using row {4, 9, 4, 1}, state the return value and name one pair of columns that match.