← Unit 4 · all exercises
Saved in this browser only

Count matches in a grid

Return how many times the target appears anywhere in the two-dimensional array.

int count(int[][] grid, int target)

Solution.java
Loading editor…
Results

Examples

  • Solution.count(new int[][]{{1, 2}, {2, 3}}, 2) → 2
  • Solution.count(new int[][]{{1}}, 9) → 0

There are also 2 hidden tests you can't see. Solve the problem, not the examples.