Easy as ABC
Time limit2sMemory limit1024 MB
Find the lexicographically smallest 3-letter word spelled by three distinct cells in a 3x3 grid of A, B, and C, where each consecutive pair of cells is adjacent.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
You are playing a word puzzle. The puzzle starts with a by grid, where each cell contains either the letter A, B, or C.
The goal is to find the lexicographically smallest word of length that you can form in the grid. Choose three different cells. The cell holding the first letter must be adjacent to the cell holding the second letter, and the cell holding the second letter must be adjacent to the cell holding the third letter.
Two cells are adjacent if they share a border or a corner, as shown in the following illustration. Formally, cell is adjacent to cells , , , , , , , and .

Input
The input consists of three lines. Each line contains three letters that represent the grid. Every letter is A, B, or C.
Output
Output the lexicographically smallest word of length that you can find in the grid.