Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Minimum Time to Activate String

XPChallenge Points: 20
levelLevel: Medium

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.

Example 1:

Input: s = "code" order = [2, 0, 3, 1] k = 3

Output: 0

Example 2:

Input: s = "game" order = [1, 3, 2, 0] k = 7

Output: 2

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result