Find a value in the grid
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from 0 to 5. target is a whole number from 0 to 5.
Your tasks
- Create a number
countthat starts at 0. - Use nested loops over every cell. Add 1 to
countfor each cell equal totarget. - Complete
countInGridso it returnscount. Return it, do not print it.
Example
With cells = [[1, 2, 1], [2, 1, 3]] and target = 1, countInGrid returns 3.
Rules
- Count every cell, not just one per row.
Test data
TEST DATA 1: cells is [[1, 2, 1], [2, 1, 3]], target is 1
TEST DATA 2: cells is [[4]], target is 2
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.