Reported August 2020
Bloombergbreadth first search

Largest Same-Letter Grid Component

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Bloomberg OA, reported in August 2020, is counting total letters instead of connected letters. Two a's sitting apart don't make a size-two component. This is a grid flood fill with a tie-break twist: find the biggest 4-directionally connected region of one letter, then return that letter, smallest alphabetically on a tie. The grid can hit 10^6 cells, so sloppy recursion bites. If you blank on the iterative traversal during the live OA, StealthCoder sits invisibly on your screen as a safety net.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is BFS or DFS over a character grid. Scan every cell. When you hit an unvisited one, flood fill its same-letter neighbors up, down, left and right, and count the size. Track the best size and best letter. On equal size, keep the smaller letter. The pitfalls are concrete. First, diagonals don't connect. Second, a recursive DFS can overflow the stack with up to 10^6 cells, so use an explicit stack or a queue. Third, track the best letter per component, not per letter total, because the same letter can form several separate components and only the largest single one counts. Fourth, return the empty string for an empty grid before you touch grid[0]. Mark cells visited when you enqueue them, not when you pop them, or you'll double count. Time is O(cells). StealthCoder is the hedge if the iterative version slips under pressure.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Largest Same-Letter Grid Component cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Largest Same-Letter Grid Component FAQ

What's the trick in the Bloomberg largest letter component problem?+

It's connected components on a grid. Flood fill each unvisited cell with BFS, count the size, and compare against the best so far. The twist is the tie rule: when sizes match, keep the lexicographically smaller letter. Don't aggregate counts by letter, since one letter can have many separate components.

Should I use BFS or DFS here?+

Use BFS with a queue or an iterative DFS with a stack. With up to 10^6 cells, recursive DFS risks a stack overflow in many languages. Both run in O(cells) time, so pick whichever you can write cleanly without bugs.

What edge cases should I test?+

Test the empty grid, which returns the empty string. Test a single cell, a grid of all one letter, and a grid where every cell differs. Also test the tie case from the example, where a and b both have size two and a wins.

Do diagonal neighbors count as connected?+

No. The problem says cells connect through shared sides only. Use four directions: up, down, left, right. Adding diagonals is the most common way to get wrong answers on the sample.

How do I prepare for this in 48 hours?+

Write a grid flood fill from scratch twice, once with BFS and once with an iterative stack. Then add the max-size tracking and tie-break logic. Keep a visited array and mark cells when enqueued. If you can do it without looking anything up, you're ready.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it