633. Index Pairs of a String

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

Return the pairs [i, j] in sorted order (i.e., sort them by their first coordinate, and in case of ties, sort them by their second coordinate).

Example 1:

Input: text = "codingisfun", words = ["code", "fun", "is"]

Output: [[6,7],[8,10]]

Explanation:

"is" is found at index [6,7]

"fun" is found at index [8,10]

Example 2:

Input: text = "programmingrocks", words = ["pro", "rock", "ram", "ing"]

Output: [[0,2],[4,6],[7,9],[11,14]]

Explanation:

"pro" is found at index [0,2]

"ram" is found at index [4,6]

"ing" is found at index [7,9]

"rock" is found at index [11,14]

Now Your Turn!

Pick the correct output for the given input

Input: text = "bananaapple", words = ["ban", "apple", "ana"]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= text.length <= 100
  • 1 <= words.length <= 20
  • 1 <= words[i].length <= 50
  • text and words[i] consist of lowercase English letters.
  • All the strings in words are unique.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<vector<int>> indexPairs(string text, vector<string>& words) {
// Your code goes here
}
};
Test Case

Input:

Text
Words