FastPrepTrapped Characters in a Grid
Problems/Trapped Characters in a Grid

Trapped Characters in a Grid

Adobe logoAdobe● EasyNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source asks for characters and their positions surrounded by X on all four sides, without specifying distance or visibility. This practice version interprets that as four immediate orthogonal X neighbors and authors edge handling, row-major ordering, bounds and a callable output format.

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.

Source note: Screenshots of public Reddit comments describing the reported Adobe OA task and any included author clarification. The practice version adds the details stated in the source note.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public String[] trappedCharacters(String[] grid) {
        // Write your solution here
    }
}
Checking account…