Min Deletions To Obtain String in Right Format - Company-specific OAs / Microsoft OA

Given a string with only characters X and Y. Find the minimum number of characters to remove from the string such that there is no interleaving of character X and Y and all the Xs appear before any Y.

This is a companion discussion topic for the original entry at https://algo.monster/problems/min_deletions_to_obtain_string_in_right_format/