FastPrepMaximum Words in Disjoint Grid Paths
Problems/Maximum Words in Disjoint Grid Paths

Maximum Words in Disjoint Grid Paths

Indeed logoIndeed● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Indeed phone screen. The report describes a search for several words that go right or down, where no cell can be used twice across words. Our version is about 75% the same. The author could not recall the goal. This exercise picks the most words found. Duplicate requests are separate, the limits are small, and the result is only a count. All examples are ours.

Given a rectangular character grid and an array words, assign paths to as many word entries as possible.

Each path may start at any cell and spells its word by moving to an immediately adjacent cell to the right or directly below. Every cell may belong to at most one selected path across the entire assignment.

For this exercise, assume you return the maximum number of selected word entries, rather than paths or indices. Each array index is a separate request and can be selected at most once. Repeated spellings count separately only when assigned disjoint paths.

For this exercise, assume a nonempty rectangular board represented by equal-width lowercase row strings. Words are nonempty lowercase strings; an entry need not be present. An empty word list returns 0. Do not modify the inputs.

Function

maxDisjointWords(grid: String[], words: String[]) → int

Examples

Example 1

grid = ["aa","ba"]words = ["aa","ab"]return = 2
grid
010aa1ba

Put aa at [0,1],[1,1] and ab at [0,0],[1,0]. A first-path greedy choice for aa would block ab.

Example 2

grid = ["aa"]words = ["a","a","a"]return = 2
grid
010aa

Identical entries are separate requests. Two different cells satisfy two entries; the third cannot share a cell.

Example 3

grid = ["ab","cd"]words = ["abd","ac","zz"]return = 1
grid
010ab1cd

The words abd and ac both need [0,0], and zz is absent. Exactly one entry can be selected.

Constraints

  • For this exercise, assume grid height and width are each from 1 through 3; there are at most 9 cells.
  • For this exercise, assume 0 <= words.length <= 6, and each word has length from 1 through height + width - 1.
  • Every grid and word character is a lowercase English letter.

More Indeed Phone Screen questions

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
  • Rotting Orange PropagationPHONE SCREEN · Seen May 2025
  • Courses Shared by Every Student PairPHONE SCREEN · Seen Aug 2022
  • First and Last Access Time per UserPHONE SCREEN · Seen Jul 2022
  • Most Accessed Resource in Five MinutesPHONE SCREEN · Seen Jul 2022
  • Resource Transition GraphPHONE SCREEN · Seen Jul 2022
  • Count Disappearing Connected TilesPHONE SCREEN · Seen Jul 2022
  • First Dictionary Word from Note LettersPHONE SCREEN · Seen Jul 2022

Similar questions at other companies

  • Count Eight-Neighbor Unlock PatternsGoogle · ONSITE INTERVIEW
  • Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
  • Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEW
  • Boggle GameAirbnb · PHONE SCREEN
  • Enumerate Right-and-Down Matrix PathsBloomberg LP · PHONE SCREEN
  • Word Path Moving Only Right or DownWayfair · PHONE SCREEN
  • Optimal Account BalancingAmazon · ONSITE INTERVIEW
  • Count and Score Distinct Hat AssignmentsRoblox · ONSITE INTERVIEW
  • Maximize Valid TrainsBNSF Railway · ONSITE INTERVIEW
  • Empty ShelfSquarepoint Capital · OA
See Indeed hiring insights
Saved
class Solution {
    public int maxDisjointWords(String[] grid, String[] words) {
        // Write your code here.
        return 0;
    }
}
Checking account…