function swapFirstLastRow(matrix) if (matrix.length > 1) let temp = matrix[0]; matrix[0] = matrix[matrix.length - 1]; matrix[matrix.length - 1] = temp;

function rotateClockwise(matrix) let result = []; let rows = matrix.length; let cols = matrix[0].length;

This algorithm searches the entire grid to count how many times a target value appears.

The 8.1.5 exercise usually asks you to take a provided 2D array—often representing a grid of numbers—and manipulate it in some way. Common tasks include: Adding a specific value to every element. Multiplying every element by a factor.

After passing 8.1.5, challenge yourself to implement a transpose (swap rows and columns) without using extra space, or try a spiral traversal of a 2D array. These variations will cement your knowledge for the AP exam and beyond.

Examples of practical tasks

Master Thorne stared at the grid, then at her. He didn’t smile. He never smiled. But he nodded once, slowly.

To help you clear any specific errors you are running into, tell me: