ACSA Exam Prep
← All free-response questions
Question 4 · 2D Array · 6 points

Heat Map

A weather service stores temperature readings for a region in a 2D array. Each cell is one square of the map.

public class HeatMap
{
    /** The temperature readings; rectangular, at least 1 x 1 */
    private double[][] temps;

    /** Returns the number of hot spots in temps, as described
     *  below.
     */
    public int countHotSpots()
    { /* to be implemented */ }

    // There may be instance variables, constructors,
    // and methods that are not shown.
}

Your class

6 points

Write countHotSpots. A cell is a hot spot if its temperature is strictly greater than the temperature of each of its neighbors directly above, below, left, and right. Neighbors that would be outside the array are ignored, so a cell on an edge has fewer neighbors.

col 0col 1col 2col 3
row 071687075
row 165726974
row 280707360

The hot spots are in bold, so countHotSpots() returns 5. For example, 72 is greater than 68, 70, 65, and 69. The 74 is not a hot spot because 75 is above it.

Tab inserts spaces. Drafts save as you type.
Self-score
0 / 6