FastPrepSubstring Match Generator
Problems/Substring Match Generator

Substring Match Generator

Apple logoApple● MediumNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a generator but omits overlap, pattern syntax and boundary rules. The judged core task matches the source at about 80%.

Write a generator that scans text from left to right and yields true whenever a substring equals pattern. Matching is literal and overlapping matches count. The pattern is nonempty.

For this finite function interface, return the collected boolean yields in discovery order. Emit one true for each matching start position and no false values. Return an empty array when there is no match.

Function

substringMatches(text: String, pattern: String) → boolean[]

Examples

Example 1

text = "aaaa"pattern = "aa"return = [true,true,true]

Matches start at indices 0, 1 and 2. Overlapping matches each yield true.

Example 2

text = "abc"pattern = "d"return = []

No substring equals the pattern, so the generator yields nothing.

Constraints

  • 0 <= text.length <= 20000
  • 1 <= pattern.length <= 10000
  • text and pattern contain only lowercase English letters.

More Apple problems

  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
All Apple interview questionsSee Apple hiring insights
Saved
public boolean[] substringMatches(String text, String pattern) {
    // Write your code here.
}
Checking account…