Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Index Pairs of a String

Problem Statement

Given a string text and a list of strings words, identify all [i, j] index pairs such that the substring text[i...j] is in words.

These index pairs should be returned in ascending order, first by the start index, then by the end index. Find every occurrence of each word within the text, ensuring that overlapping occurrences are also identified.


    • Input: text = "bluebirdskyscraper", words = ["blue", "bird", "sky"]
    • Expected Output: [[0, 3], [4, 7], [8, 10]]




Like the course? Get enrolled and start learning!