Trapped Characters in a Grid
Reported by candidates from Adobe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Adobe OA reported in August 2026 looks like a grid problem, and the hinted pattern says BFS, but don't reach for a queue. Trapped Characters in a Grid is a plain neighbor scan, and the whole question is whether you respect the boundary rule. A cell on the edge never counts, even when everything around it is X. If you blank on the indexing or the output format in the live OA, StealthCoder runs invisibly as a safety net and gives you the working solution. Still, this one is short enough to write from memory once you see the trick.
The problem
Given a rectangular character grid, a cell is a trapped character when all of the following hold: The cell is not X. It has four in-bounds orthogonal neighbors: up, down, left, and right. All four of those neighbors contain X. Return one string for every trapped character in row-major order. Format each string as character row column, using zero-based indices and single spaces. Function trappedCharacters(grid: String[]) → String[] Examples Example 1 grid = ["XXXXX","XAX1X","XXXXX"] return = ["A 1 1","1 1 3"] Both interior non-X cells have X directly above, below, left, and right. Row-major order reports A first. Example 2 grid = ["AXX","XXX","XXB"] return = [] The two characters lie on the boundary and therefore do not have four in-bounds neighbors. Constraints 1 <= grid.length <= 200 1 <= grid[i].length <= 200 Every row has the same length. Each cell is X, an ASCII letter, or a decimal digit.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there's no search at all. Loop rows 1 to n-2 and columns 1 to m-2, so boundary cells are skipped by construction. For each interior cell, skip it if it's X. Otherwise check up, down, left and right. If all four are X, append the string char + space + row + space + col. Row-major iteration gives the required order for free, so no sorting. The common pitfalls are checking bounds wrong on 1-row or 1-column grids (the loop ranges handle it, they just don't run), forgetting that digits count as characters, and building the string with the wrong index order. Example 2 is the edge case that kills naive solutions that only test neighbors without bounds checks. Complexity is O(n*m) time and O(k) output space. If you blank during the live OA, StealthCoder can hand you this loop in seconds.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Trapped Characters in a Grid 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Adobe's OA.
Adobe 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.
Trapped Characters in a Grid FAQ
What's the trick in Trapped Characters in a Grid?+
There's no real search. Scan only interior cells, skip X, and check the four orthogonal neighbors for X. Boundary cells can never be trapped because they lack four in-bounds neighbors. Iterating row by row gives row-major output automatically.
Is this really a BFS problem?+
No. Despite the BFS hint, nothing needs to be traversed or connected. Each cell is judged only by its four direct neighbors, so a double loop is enough. Using BFS or DFS here adds complexity and risk without any benefit.
What edge cases should I test before submitting?+
Test a grid with 1 row, a grid with 1 column, and a 2x2 grid, since none have interior cells and should return an empty list. Also test a digit as the trapped character, like the 1 in Example 1, and a grid of all X, which returns nothing.
How should I format the output strings?+
Each string is the character, a space, the zero-based row, a space, then the zero-based column, like "A 1 1". Mixing up row and column order is the easiest way to fail hidden tests, so check against Example 1 before submitting.
How do I prepare for this in 48 hours?+
Practice neighbor-check grid problems until bounds handling is automatic. Write the interior loop with ranges 1 to n-2 and 1 to m-2 from memory. Then run the two examples by hand. With a 200 by 200 limit, O(n*m) is comfortably fast.