MEDIUMasked at 1 company

Coloring A Border

A medium-tier problem at 50% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at Booking.com and 0 others.

Founder's read

Coloring A Border is a medium-difficulty matrix traversal problem that hits your screen when you're unprepared. You've got an image represented as a 2D array, a starting coordinate, and a new color. The trap is that you need to fill only the connected region of the same color, not the whole grid. Booking.com has asked this. The acceptance rate sits just under 50%, which means half the candidates either miss the boundary condition or pick the wrong traversal method. If this lands in your assessment and you blank on the flood-fill logic, StealthCoder surfaces a working solution in seconds while the proctor sees nothing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
50%

Companies that ask "Coloring A Border"

If this hits your live OA

Coloring A Border is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The core trick is recognizing this as a classic flood-fill problem dressed up in a grid. You start at a coordinate, note the original color, then expand outward to all connected cells with that same color, recoloring them. The gotcha is stopping at the border: you can only move to adjacent cells (up, down, left, right) that share the original color. BFS or DFS both work, but DFS is simpler to code under pressure. Most candidates stumble on handling the base case: checking bounds and whether the current cell already matches the original color before recursing. A second trap is in-place modification: if you recolor as you go, you can't tell which cells you've already visited. The safe path is to mark visited cells or change color only after the entire traversal completes. This problem tests Array, Matrix, and either Depth-First Search or Breadth-First Search, so if you've drilled tree traversals, the pattern transfers directly.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Coloring A Border recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Coloring A Border interview FAQ

Is this harder than standard flood fill?+

Not fundamentally. The core logic is identical to flood-fill on a grid. What makes it medium is the boundary-check discipline and avoiding the pitfall of modifying the grid mid-traversal. The problem statement can be verbose, which throws people off. Once you recognize it as flood-fill, the solution is routine.

Should I use DFS or BFS?+

DFS is faster to code in an interview. Fewer lines, simpler mental model. BFS is fine too if you're comfortable with a queue. Both hit the same O(rows * cols) time complexity. Pick whichever you can implement without bugs under pressure.

What's the main pitfall candidates hit?+

Recoloring the grid during traversal and then losing track of which cells are original color versus new color. The fix: either use a separate visited set or check the original color before recursing. Don't change the grid until you're sure about the boundary.

Does Booking.com ask this often?+

It's reported from Booking.com, but the company count is low. This suggests it appears in their rotation but isn't a staple like two-pointer or hash-map problems. Still worth knowing if you're targeting them.

How does this connect to matrix and graph problems?+

It's the intersection of all three: you treat a matrix as a graph and traverse it using DFS or BFS. If you're weak on grid traversal or graph adjacency, this exposes it fast. It's a foundation skill for island counting and water trapping variants.

Want the actual problem statement? View "Coloring A Border" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.