FastPrepLargest Same-Letter Grid Component

Largest Same-Letter Grid Component

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

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[]) → String

Examples

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^6 cells.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String largestLetterComponent(String[] grid) {
  // Write your code here.
}
grid["abbcz","ampbg"]
expected"a"
Checking account…