#3639

Minimum Time to Activate String

specialist · 890 · lc medium +31 · 49.2% accepted · 120 likes · top 36%

Description

A string s of length n and a permutation array order are given. At each time step t (starting from 0), the character at position order[t] in s is overwritten with '*'. A substring is valid once it contains at least one '*'. The string becomes active when the total count of valid substrings reaches at least k. Return the smallest time t when s becomes active, or -1 if impossible.

Code

1
2
3