Reported April 2024
Motivebacktracking

Eight-Direction Word Search

Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Motive OA. Under 2s to a working solution.
Founder's read

Motive reported this one in April 2024, and the grid size is the first thing to check. A 50 by 50 board with a word up to 50 letters means naive path enumeration with no pruning can blow up fast, since each step has eight neighbors. It's a word search with diagonals added, and it's a backtracking problem, not a binary search one, whatever the tag says. If the OA is in your inbox, learn the DFS shape cold. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below is short enough to carry in your head.

The problem

Given a rectangular grid of characters encoded as equal-length strings and a word, return whether the word can be formed from sequentially adjacent cells. Each step may move horizontally, vertically, or diagonally, and one cell cannot be reused within a path.

Function
wordExistsEightDirections(board: String[], word: String) → boolean

Examples
Example 1
board = ["ABCE","SFCS","ADEE"]
word = "ABCCED"
return = true
Example 2
board = ["AB","CD"]
word = "AD"
return = true
The diagonal move is allowed.

Constraints
1 <= board.length, board[i].length <= 50.
1 <= word.length <= 50.
Board cells and the word contain English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is DFS with backtracking from every cell that matches word[0]. At each step, mark the current cell visited, try all eight directions, then unmark it on return. Prune hard: stop the moment a cell is out of bounds, already used, or doesn't match the next letter. That pruning is what keeps 50 by 50 fast, because mismatches kill branches early. Common pitfalls: forgetting to unmark the cell, which breaks other paths, and using only four directions out of habit from the classic version. Also check early exits: if the word is longer than rows times columns, return false. A letter-count check against the board helps too. Board is given as strings, so index with board[r].charAt(c). If you freeze on the recursion, StealthCoder can surface a working solution during the live OA, but practice writing the eight-direction array once.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Eight-Direction Word Search cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Motive's OA.

Motive reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Eight-Direction Word Search FAQ

What's the trick for Motive's Eight-Direction Word Search?+

Run DFS with backtracking from every cell matching the first letter. Try eight neighbor offsets, mark the cell visited before recursing, and unmark after. Return true as soon as the index reaches the end of the word. Prune on bounds, visited, and letter mismatch.

Is this really a binary search problem?+

No. The hinted tag doesn't fit. Nothing is sorted and there's no monotonic answer to search over. It's grid DFS with backtracking. Spend your prep time on recursion and visited-state handling, not on binary search templates.

How is it different from the classic word search?+

The classic version allows four moves. This one allows eight, so diagonals count. Example 2 shows it: AB over CD, and A to D is valid diagonally. You just extend the direction array with the four diagonal offsets. Everything else stays the same.

Will brute force time out with a 50 by 50 grid?+

Unpruned enumeration can, since branching is up to eight per step. With early exits on mismatch, bounds, and visited cells, DFS usually runs fine. Add quick checks like word length versus board size and letter counts to cut obvious failures.

How do I prepare in 48 hours?+

Write the DFS solution from scratch twice without looking. Test it on both examples and on a single-cell board. Check that you unmark visited cells on every return path. Then do one run where the word needs a diagonal turn to confirm your offsets are right.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Motive.

OA at Motive?
Invisible during screen share
Get it