Reported September 2026
HSBCbreadth first search

Minimum Cleaning Robot Runs

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

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

The mistake that sinks a first attempt on this HSBC problem is counting every room instead of only the dirty ones. It was reported in September 2026, and it's a grid connected-components question dressed up as a robot story. You get a plan of '.', '*' and '#' cells, and you return how many rooms contain at least one dirty field. Example 3 returns 0 for a reason. If you blank on the traversal during the live OA, StealthCoder can sit invisibly on your screen as a safety net, but the logic here is short enough to own tonight.

The problem

A building plan is represented by a rectangular array of strings. Each field contains one of three symbols:
. is clean floor.
* is dirty floor.
# is a wall.
A room is a maximal group of non-wall fields connected in the four cardinal directions. In one run, a cleaning robot starts in one room and cleans every dirty field in that room. It cannot cross a wall or leave the plan.
Return the minimum number of robot runs needed to clean every dirty field.

Function
solution(plan: String[]) → int

Examples
Example 1
plan = ["..#..",".*#*.","..#.."]
return = 2
The vertical wall separates the floor into two rooms. Each room contains a dirty field, so the robot needs one run in each room.
Example 2
plan = ["....",".##.",".*#.","...."]
return = 1
All non-wall fields are connected around the wall block. The single dirty field is therefore cleaned in one run.
Example 3
plan = ["###","#.#","###"]
return = 0
The only floor field is already clean, so no robot run is required.

Constraints
1 <= plan.length and every row has the same positive length.
plan.length * plan[0].length <= 200000.
Every character is., *, or #.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Treat each non-wall cell as a node and connect the four neighbors. Scan the grid once. When you hit an unvisited non-wall cell, flood fill its whole room with BFS or an iterative DFS, and track a flag for whether you saw a '*'. If the flag is set, add one to the answer. The pitfall is counting all components, which fails Example 3 and any grid with clean-only rooms. The second pitfall is recursion depth. With up to 200000 cells, a recursive DFS can overflow the stack, so use an explicit stack or queue. Mark visited in a boolean array or mutate a copy. Time is O(rows*cols). If the traversal slips your mind mid-assessment, StealthCoder is the hedge that hands you the working version in real time.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Minimum Cleaning Robot Runs 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

HSBC reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Cleaning Robot Runs FAQ

What's the trick in the HSBC Minimum Cleaning Robot Runs problem?+

Count connected components of non-wall cells, but only those containing at least one '*'. Clean-only rooms cost nothing. Flood fill each unvisited room, track whether a dirty cell appeared, and increment the answer only when it did.

How hard is this really?+

Easy to medium. It's the classic number-of-islands pattern with one extra flag. If you've written a grid BFS before, it takes about ten minutes. The only real risks are counting clean rooms and blowing the stack with recursion.

Should I use BFS or DFS?+

Either works. Use BFS with a queue or DFS with an explicit stack. With up to 200000 cells, a deep recursive DFS can crash on a snake-shaped room, so avoid plain recursion unless you're sure about the stack limit.

What edge cases should I test?+

A grid with no dirty cells returns 0, like Example 3. Test a single row, a single column, an all-wall grid, and a room wrapped around a wall block like Example 2, where one run covers everything because the floor is connected.

How do I prepare for this in 48 hours?+

Write the grid flood fill from scratch twice. Use a direction array, a visited grid, and a queue. Then add the dirty flag. Run the three examples by hand. That covers this problem and most of its variants.

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

OA at HSBC?
Invisible during screen share
Get it