Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make String Sorted

med
30 min
Try to solve the Minimum Number of Operations to Make String Sorted problem.

Statement

You are given a 00 indexed string s. In one operation, you can perform the following steps:

  1. Find the largest index i such that 1≤i<1 \leq i < s.length and s[i - 1] > s[i].

  2. Find the largest index j such that i≤j<i \leq j < s.length and s[i - 1] > s[j].

  3. Swap the characters s[i - 1] and s[j].

  4. Reverse the suffix of s starting at index i.

Return the number of operations needed to make s sorted in ascending order. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq s.length ≤3000\leq 3000

  • s consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make String Sorted

med
30 min
Try to solve the Minimum Number of Operations to Make String Sorted problem.

Statement

You are given a 00 indexed string s. In one operation, you can perform the following steps:

  1. Find the largest index i such that 1≤i<1 \leq i < s.length and s[i - 1] > s[i].

  2. Find the largest index j such that i≤j<i \leq j < s.length and s[i - 1] > s[j].

  3. Swap the characters s[i - 1] and s[j].

  4. Reverse the suffix of s starting at index i.

Return the number of operations needed to make s sorted in ascending order. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq s.length ≤3000\leq 3000

  • s consists only of lowercase English letters.