FastPrepGreedy Grid Word Occurrences with No Reused Cells
Problems/Greedy Grid Word Occurrences with No Reused Cells

Greedy Grid Word Occurrences with No Reused Cells

Compass International Holdings logoCompass International Holdings● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported no-reuse coordinate follow-up matches at about65%; global scope across repeated occurrences, right/down movement, greedy lexicographic selection, grouping and bounds are explicit practice interpretations. The report supplies no maximum-packing objective or original example.

Find repeated occurrences of word in a rectangular character grid. Return their coordinates without using a cell in more than one selected occurrence.

No cell may be used by more than one completed occurrence. Each path starts anywhere and moves only to an adjacent cell to the right or directly below.

For this exercise, follow these steps:

  1. Find the paths that spell the whole word using only unused cells.
  2. Select the lexicographically smallest coordinate sequence.
  3. Mark every cell in that path as permanently used.
  4. Repeat until no complete path remains.

Compare coordinates by row then column, using zero-based indices. A failed exploratory branch never consumes a cell.

This greedy procedure is the required rule; it need not maximize the number of occurrences.

Return all selected coordinates in one int[][]. For this exercise, assume each consecutive block of word.length rows represents one path, and blocks appear in selection order. If no path exists, return an empty array.

Function

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

Examples

Example 1

grid = ["abab","abab"]word = "ab"return = [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3]]
grid
01230abab1abab
→
return
01000101202303410511612713

This example selects four consecutive two-cell paths and uses each cell once.

Example 2

grid = ["aa","aa"]word = "aa"return = [[0,0],[0,1],[1,0],[1,1]]
grid
010aa1aa
→
return
01000101210311

This example selects the top horizontal path before the bottom horizontal path.

Example 3

grid = ["aaa","abb","aaa"]word = "aab"return = [[0,0],[0,1],[1,1]]
grid
0120aaa1abb2aaa
→
return
01000101211

This example selects [0,0],[0,1],[1,1] and stops. A different choice could produce two paths, but maximizing their number is not the stated rule.

Constraints

  • For this exercise, assume grid height and width are each from 1 through 10, and row strings have equal length.
  • 1 <= word.length <= height + width - 1.
  • All characters are lowercase English letters.
  • No coordinate occurs twice in the result.

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
  • Word Path Moving Only Right or DownPHONE 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[][] disjointWordPaths(String[] grid, String word) {
        // Write your code here.
        return new int[0][0];
    }
}
Checking account…