Index Pairs of a String

Given a string text and an array of strings words, return all index pairs [i, j] such that the substring text[i...j] (inclusive) is exactly equal to some string in words.

Return the pairs sorted by i in ascending order, and for pairs with the same i, sorted by j in ascending order.

Input: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]

Output: [[3,7],[9,13],[10,17]]

Input: text = "ababa", words = ["aba","ab"]

Output: [[0,1],[0,2],[2,3],[2,4]]

  • 1 <= text.length <= 100
  • 1 <= words.length <= 20
  • 1 <= words[i].length <= 50
  • text and words[i] consist of lowercase English letters
  • All strings in words are distinct
Examples
Input: []
Output: 0
Hints

Index Pairs of a String

Given a string `text` and an array of strings `words`, return all index pairs `[i, j]` such that the substring `text[i...j]` (inclusive) is exactly equal to some string in `words`.