Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Activate String

med
30 min
Try to solve the Minimum Time to Activate String problem.

Statement

You are given a string s of length n, an integer array order of length n which is a permutation of integers from 00 to n−1n - 1, and an integer k.

At each second t starting from 00, the character at index order[t] in s is replaced with the character '*'.

A substring of s is considered valid if it contains at least one '*'.

The string s becomes active when the total number of valid substrings is greater than or equal to k.

Return the minimum time t at which s becomes active. If it is impossible for s to become active after all replacements, return −1-1.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • order.length ==n== n

  • 0≤0 \leq order[i] ≤n−1\leq n - 1

  • s consists of lowercase English letters.

  • order is a permutation of integers from 00 to n−1n - 1.

  • 1≤k≤1091 \leq k \leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Activate String

med
30 min
Try to solve the Minimum Time to Activate String problem.

Statement

You are given a string s of length n, an integer array order of length n which is a permutation of integers from 00 to n−1n - 1, and an integer k.

At each second t starting from 00, the character at index order[t] in s is replaced with the character '*'.

A substring of s is considered valid if it contains at least one '*'.

The string s becomes active when the total number of valid substrings is greater than or equal to k.

Return the minimum time t at which s becomes active. If it is impossible for s to become active after all replacements, return −1-1.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • order.length ==n== n

  • 0≤0 \leq order[i] ≤n−1\leq n - 1

  • s consists of lowercase English letters.

  • order is a permutation of integers from 00 to n−1n - 1.

  • 1≤k≤1091 \leq k \leq 10^9