Search⌘ K
AI Features

Solution: Index Pairs of a String

Explore how to implement a trie to efficiently search substrings in a given text that match any word in a provided list. This lesson teaches you to build the trie, traverse it for matching substrings, and return all index pairs sorted by their positions. You will understand the algorithm's time and space complexity and apply it to optimize substring searches in coding problems.

Statement

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

Return the pairs [i, j] in sorted order, first by the value of i, and if two pairs have the same i, by the value of j.

Constraints:

  • 11 \leq text.length 100\leq 100

  • 11 \leq words.length 20\leq 20 ...