Largest Same-Letter Grid Component
Problem statement
Cells are connected through shared sides, not diagonals. A component contains cells with the same letter. Return the letter belonging to the largest component; break equal-size ties by lexicographically smallest letter.
Return the empty string for an empty grid.
Function
largestLetterComponent(grid: String[]) → StringExamples
Example 1
grid = ["abbcz","ampbg"]return = "a"The a and b components both have size two, so the lexical tie rule selects a.
Constraints
- The rectangular grid has at most
10^6cells.