L-shapes
An L-shape is exactly three shaded cells (*) arranged as a 2 by 2 square with one cell removed. It may be rotated in any of the four ways.
Given a rectangular grid of . and *, decide whether the shaded cells form a collection of L-shapes that never touch each other, not even at a corner. Formally:
- Every shaded cell belongs to exactly one L-shape.
- No two L-shapes are adjacent by an edge or by a corner.
Return true when the grid satisfies both conditions, otherwise return false. A grid with no shaded cells is vacuously valid.
Examples
Input: ["........**",".**......*","..*..*....",".....**...","...*.....*","..**....**"]
Output: true
Input: [".....*...*",".**......*","..*..*....",".....**...","...*.....*","..**....**"]
Output: false
Hints
Under 8-direction adjacency, every L-shape is a connected component of exactly three cells whose bounding box is 2 by 2.
Two L-shapes that touch by an edge or a corner would merge into one larger component, so a component-size check catches both violations.
As an alternative, every shaded cell in a valid grid has exactly two shaded neighbors, and those two neighbors are themselves adjacent.
Related Problems
L-shapes
An L-shape is exactly three shaded cells (`*`) arranged as a 2 by 2 square with one cell removed. It may be rotated in any of the four ways.