FastPrepWord Path Moving Only Right or Down
Problems/Word Path Moving Only Right or Down

Word Path Moving Only Right or Down

Wayfair logoWayfair● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported right-and-down word search that returns a path matches at about 90%. The coordinate format, which path to pick, the output when the word is absent, the alphabet, not changing the input and finite limits are our assumptions. The original gives no complete example, so every example shown is ours.

Find a path spelling word in a rectangular character grid. The word may start at any cell. Each next letter must be in the immediately adjacent cell to the right or directly below.

Return one coordinate [row,column] for every letter, in word order. For this exercise, assume zero-based coordinates and equal-length lowercase row strings. Do not modify the input.

In this exercise, return the smallest complete path in lexicographic order: compare the first coordinate where two paths differ, first by row and then by column. Try starting cells in row-major order and prefer right before down only when that continuation can complete the word.

For this exercise, assume the word may be absent. Return an empty coordinate array when no permitted path spells it.

Function

gridPath(grid: String[], word: String) → int[][]

Examples

Example 1

grid = ["ab","bd"]word = "abd"return = [[0,0],[0,1],[1,1]]
grid
010ab1bd
→
return
01000101211

Both a-right-b-down-d and a-down-b-right-d work. The right continuation gives the lexicographically smaller coordinate path.

Example 2

grid = ["ax","bc"]word = "abc"return = [[0,0],[1,0],[1,1]]
grid
010ax1bc
→
return
01000110211

The path moves down and then right; the right neighbor of the start cannot supply b.

Example 3

grid = ["ab","cd"]word = "acb"return = []
grid
010ab1cd

The letter a can move down to c, but no permitted next cell contains b, so no complete path exists.

Constraints

  • For this exercise, assume grid height R and width C are each from 1 through 12, with all rows equally long.
  • For this exercise, assume 1 <= word.length <= 23. A target longer than any possible right/down path is valid and returns an empty result.
  • For this exercise, assume all grid and word characters are lowercase English letters.

More Wayfair interview questions

  • Container With Most WaterPHONE SCREEN · Seen Sep 2026
  • Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
  • First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
  • Time of Maximum Mall OccupancyPHONE SCREEN · Seen Apr 2022
  • Longest Common Contiguous User ActionsPHONE SCREEN · Seen Apr 2022
  • Count a Person’s Distinct FriendsPHONE SCREEN · Seen Mar 2022
  • Tree Nodes with Zero or One ParentPHONE SCREEN · Seen Sep 2021
  • UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
  • Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
  • DFS Subsequences of a String (For MLE)OA · Seen Sep 2024

Similar questions at other companies

  • Word Path Moving Only Right or DownIndeed · PHONE SCREENIndeed interview questions
  • Enumerate Right-and-Down Matrix PathsBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
  • Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
  • Count Eight-Neighbor Unlock PatternsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Unique Grid PathsMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
  • Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
  • Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
All Wayfair interview questionsSee Wayfair hiring insights
Saved
class Solution {
    public int[][] gridPath(String[] grid, String word) {
        // Write your code here.
        return new int[0][0];
    }
}
Checking account…