Is It Hidden Inside
A word is hidden inside a text when you can find its letters in the text in the same order, though not necessarily next to each other: you may skip any letters of the text in between. Given the strings word and text, return true if word is hidden inside text, and false if not.
Each letter of the text can be used for only one letter of the word. An empty word is hidden inside any text.
Examples
word = "ace", text = "abcde" → true
word = "aec", text = "abcde" → false
word = "", text = "anything" → true
word = "cat", text = "concatenate" → trueIn the second example the text has an a, an e and a c, but the c comes before the e.
Constraints
- Each string holds between 0 and 20,000 characters.
- Aim for O(n + m): read each string once.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.