Fundamentals/Min Deletions To Obtain String In Right Format
← PrevNext →
Given a string s containing only the characters X and Y, return the minimum number of deletions needed so that all X's appear before any Y (no interleaving).
Input
s: a string of characters (X and Y in the canonical version)
Output
The minimum number of characters to delete so the result has the form X*Y* (zero or more X's followed by zero or more Y's).
Examples
Example 1
Inputs = "hello"
Output0
Example 2
Inputs = "a"
Output0
Constraints
A string with no X's or no Y's is already valid (returns 0).
Process characters left to right, tracking Y count and a running deletion minimum.