Problem 258817 · easy · Phase 02 Linear Data Structures

Count Solid 2x2 Blocks

2d-lists · nested-loops · windows

Given a grid of integers grid, count the 2x2 sub-grids whose four cells all hold the same value. Blocks may overlap.

Examples

Input:  grid = [[1, 1, 2],
                [1, 1, 2],
                [3, 2, 2]]
Output: 1
Explanation: only the block in the top-left corner is solid.

Input:  grid = [[5, 5],
                [5, 5]]
Output: 1

Input:  grid = [[1, 1, 1]]
Output: 0

Constraints

  • 1 <= rows, cols <= 100

Goals

  • Enumerate every 2x2 window without going out of bounds
  • Check that four cells share one value
Starting Python…