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

Word Path Moving Only Right or Down

Compass International Holdings logoCompass International Holdings● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Compass phone screen. The report asks for a coordinate path that moves right or down. We chose how to pick a single path, how rows and columns are numbered, a row-string input with limits, and what to return when there may be no path. Our version is about 95% the same as the reported question.

Find a path spelling word in a rectangular character grid. The word may start at any cell. Each next letter must be in an 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 represent the grid by equal-length lowercase row strings. Both grid and word are nonempty.

For this exercise, assume the lexicographically smallest complete coordinate path must be returned. Compare at the first differing coordinate, row before column. Choose 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 = ["ccxtib","ccatni","acnntt","tcsipt","aoooaa","oaaaoo","kaicki"]word = "cat"return = [[1,0],[2,0],[3,0]]
grid
0123450ccxtib1ccatni2acnntt3tcsipt4aoooaa5oaaaoo6kaicki
→
return
01010120230

The c cells at [0,0] and [0,1] have no a to their right or below. From the c at [1,0], go down to a at [2,0] and down again to t at [3,0].

Example 2

grid = ["ab","cd"]word = "abd"return = [[0,0],[0,1],[1,1]]
grid
010ab1cd
→
return
01000101211

Start at a in [0,0], move right to b, then down to d.

Example 3

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

The only a has no a to its right or below, so no path spells the word and the answer is empty.

Constraints

  • For this exercise, assume height and width are each from 1 through 12, and all row lengths are equal.
  • 1 <= word.length <= height + width - 1.
  • All characters are lowercase English letters.

More Compass International Holdings Phone Screen questions

  • Decode StringPHONE SCREEN · Seen Oct 2026
  • Lowest Common Ancestors in a Parent DAGPHONE SCREEN · Seen Apr 2022
  • Can One Dictionary Word Supply the Target Letters?PHONE SCREEN · Seen Apr 2022
  • Greedy Grid Word Occurrences with No Reused CellsPHONE SCREEN · Seen Apr 2022
  • First Dictionary Word from Note LettersPHONE SCREEN · Seen Mar 2022
  • Word Path Moving Only Up or RightPHONE SCREEN · Seen Feb 2022
  • Top Five Stock Records in a Date RangePHONE SCREEN · Seen Oct 2021
  • Wrap Words from Existing Text LinesPHONE SCREEN · Seen Apr 2021
  • All Common Ancestors in a Parent GraphPHONE SCREEN · Seen Jan 2021
  • Nodes With Zero or Three ParentsPHONE SCREEN · Seen Jan 2021

Similar questions at other companies

  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Fuzzy Word Lookup With One Misspelled LetterMeta · PHONE SCREENMeta interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Group Timestamps into Consecutive-Day IntervalsDuolingo · PHONE SCREENDuolingo interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
All Compass International Holdings interview questionsSee Compass International Holdings hiring insights
Saved
class Solution {
    public int[][] gridPath(String[] grid, String word) {
        // Write your code here.
        return new int[0][0];
    }
}
Checking account…