This is a verified interview question from Adobe-hackthon-2026-discussion. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Design an Expression Parser - Adobe Hackathon 2026" covers key patterns like Other.
"### **Problem Statement** You are given a 2D grid composed of different characters, representing a maze. Each character in the grid represents a cell that can either be open or blocked. You need to determine the characters that are trapped in the maze. A character is considered trapped if it is surrounded by 'X' on all four sides (up, down, left, right). If a character 'A' is adjacent to another character 'B' (up, down, left, or right), they form a group and will not be considered trapped. You need to find and list all the characters that are trapped along with their positions in the grid. ### **Input Format** * The first line contains two space-separated integers **N** and **M**, representing the dimensions of the grid. * The next **N** lines contain **M** characters each, representing the grid. ### **Output Format** * Print a single integer representing the number of unique trapped characters. * Print each trapped character followed by its position in the format `char row column` on a new line. ### **Constraints** * $0 \leq N \leq 10^2$ * $0 \leq M \leq 10^2$ * $a \leq \text{grid(characters)} \leq z$ * $1 \leq \text{grid(characters)} \leq 9$ * $A \leq \text{grid(characters)} \leq Z$ * Characters on the edge can be trapped if all their adjacent (valid) neighbors are 'X'. --- ### **Sample Testcase 1** **Input:** ```text 5 8 XXXXXXAX XAABXXXD XAAXXXAX XXAXXCX XXXXXXXX ``` **Output:** ```text 2 A 0 6 D 1 7 ``` **Explanation:** The input grid represents a 5x8 grid where 'X' denotes obstacles and letters represent characters. The algorithm identifies groups of connected characters not separated by obstacles and checks if they are entirely surrounded by 'X'. In this case, characters 'A' and 'D' are identified as trapped, resulting in the output showing the number of trapped characters and their positions. --- ### **Sample Testcase 2** **Input:** ```text 6 6 XXXXXX XAAAXX XAXXXX XAXXAX XAXXXX XXXXXX ``` **Output:** ```text 1 A 3 4 ``` **Explanation:** The input grid represents a 6x6 grid with 'X' as obstacles and 'A' as characters. The algorithm identifies groups of connected 'A' characters and checks if they are fully enclosed by 'X'. In this case, only one group of 'A' characters is completely surrounded by obstacles, specifically 'A' at position (3, 4)."
Join thousands of developers practicing for Adobe-hackthon-2026-discussion.