Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Sort a String

Try to solve the Minimum Operations to Sort a String problem.

Statement

You are given a string s consisting of lowercase English letters.

In one operation, you can choose any proper substring of s (a contiguous substring of length strictly less than the length of s) and sort its characters in ascending order.

Return the minimum number of operations needed to sort the entire string s in ascending order. If it is impossible to sort the string, return −1-1.

Constraints:

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

  • s consists of only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Sort a String

Try to solve the Minimum Operations to Sort a String problem.

Statement

You are given a string s consisting of lowercase English letters.

In one operation, you can choose any proper substring of s (a contiguous substring of length strictly less than the length of s) and sort its characters in ascending order.

Return the minimum number of operations needed to sort the entire string s in ascending order. If it is impossible to sort the string, return −1-1.

Constraints:

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

  • s consists of only lowercase English letters.