Daily challenge for 2026-10-26
664. Same-Color Component Perimeter
Given a 2D grid of single-character strings grid and starting coordinates (r, c), determine the perimeter of the connected same-color region containing (r, c).
Two cells are connected if they are adjacent horizontally or vertically and share the same color (character). The perimeter of the region is the total number of cell edges that border either the grid boundary or a cell of a different color.
Constraints:
The grid is a non-empty rectangular array with 1–30 rows and 1–30 columns. Each cell is one lowercase ASCII letter. The starting row and column are valid zero-based indices. Adjacency is horizontal or vertical only.
Example:
Input: grid = [["a", "a", "b"], ["a", "b", "b"]], r = 0, c = 0
Output: 8
Run this challenge interactively in Python or JavaScript when the app loads.