FastPrepStraight-Line Word Search
Problems/Straight-Line Word Search

Straight-Line Word Search

Reddit logoReddit● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report contrasts a general path-based word search with the interviewer's intended word-search-game rule: once a direction is chosen, the match continues straight. This practice contract makes the eight conventional word-search directions and no-wrap boundary explicit.

Given a rectangular grid of characters and a nonempty word, return true when the word appears in one straight line.

You may start at any cell and choose one of the eight horizontal, vertical, or diagonal directions. After choosing the direction, every next character must be in the next cell along that same direction. The direction cannot change and the grid does not wrap.

Function

containsStraightWord(board: String[], word: String) → boolean

Examples

Example 1

board = ["CAT","XXX","DOG"]word = "CAT"return = true

CAT appears left to right in the first row.

Example 2

board = ["AXX","XBX","XXC"]word = "ABC"return = true

ABC appears on the main diagonal.

Example 3

board = ["AB","CD"]word = "ACB"return = false

The letters require a direction change, which is forbidden.

Constraints

  • 1 <= board.length, board[i].length <= 200.
  • All rows have equal length.
  • 1 <= word.length <= 200.
  • The grid and word contain case-sensitive English letters.

More Reddit problems

  • Billing Log with Undo and RedoPHONE SCREEN · Seen Nov 2026
  • Filter Undesired Comments and Their DescendantsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Tennis Game and Set ScoringPHONE SCREEN · Seen Oct 2026
All Reddit interview questionsSee Reddit hiring insights
Saved
class Solution {
    public boolean containsStraightWord(String[] board, String word) {
        // Write your solution here.
    }
}
Checking account…