Find a Word in Eight Straight Directions
Updated
Problem statement
You are given a rectangular grid of letters and a word. Find each starting cell from which word can be read in a straight line in any of the eight directions: horizontal, vertical, or diagonal. Pick one direction and keep it for the whole word. No turns and no wrapping around the edges are allowed. Return every matching zero-based [row,column] once, sorted by row and then by column, even if several directions match from the same start.
Function
findWord(grid: String[], word: String) → int[][]Examples
Example 1
grid = ["ABC","DEF","GHI"]word = "AEI"return = [[0,0]]Start at the top-left cell and go down and to the right. The letters on the way spell the word, so that cell is the only start.
Example 2
grid = ["AAA","AAA"]word = "AA"return = [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2]]Every cell holds the same letter and the word has two letters, so every cell has at least one direction that fits. Each cell is listed only once, even when several directions work. All six cells are returned.
Constraints
- The grid is not empty and is rectangular, at most 50 by 50, and 1 <= word.length <= 20.
gridis an array of strings of equal length, with uppercase ASCII letters. Matching is case-sensitive.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Repair One Movement InstructionOpenAI · OAOpenAI interview questions
- Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
- Count Straight-Line Word Occurrences in a GridVisa · OAVisa interview questions
- Count Grid Words with One TurnCapital One · OACapital One interview questions
- Count Right-or-Down Word Paths with One TurnZipRecruiter · OAZipRecruiter interview questions
- Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
- Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
- Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions