Official algorithmic problem description and constraints.
For the lowercase English letter α, let ord(α) denote the order of α in the alphabet, under the standard ordering a,b,c,…,z.
For example, ord(b)=2,ord(j)=10,0, and ord(z)=26.
You are given a string S containing N lowercase English letters.
You can perform the following 2 operations on it:
You may perform these two operations as many times as you like (possibly, zero), and in any order.
Find the minimum possible length of the final string after doing so.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.