Maximum Words in Disjoint Grid Paths
Updated
Problem statement
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[]) → intExamples
Example 1
grid = ["aa","ba"]words = ["aa","ab"]return = 2Put 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 = 2Identical 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 = 1The 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
1through3; there are at most9cells. - For this exercise, assume
0 <= words.length <= 6, and each word has length from1throughheight + 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