You are given a string word of length n and an integer array sequence, which is a permutation of numbers in the range [0, n - 1].
Starting from time t = 0, at each time step you replace the character at index sequence[t] in word with '#'.
• A substring is valid if it contains at least one #.
• The word is activated if the total number of valid substrings is greater than or equal to target.
Return the minimum time t at which the word becomes activated.
If it’s impossible to activate the word, return -1.
Input: s = "code" order = [2, 0, 3, 1] k = 3
Output: 0
Input: s = "game" order = [1, 3, 2, 0] k = 7
Output: 2
Accepted:
Submission: