Official algorithmic problem description and constraints.
Rudolf has a string π of length π. Rudolf considers the string π to be ugly if it contains the substringv"pie" or the substring "map", otherwise the string π will be considered beautiful.
For example, "ppiee", "mmap", "dfpiefghmap" are ugly strings, while "mathp", "ppiiee" are beautiful strings.
Rudolf wants to shorten the string π by removing some characters to make it beautiful.
The main character doesn't like to strain, so he asks you to make the string beautiful by removing the minimum number of characters. He can remove characters from any positions in the string (not just from the beginning or end of the string).
Detailed video explanations, mathematical intuition, and clean C++ implementation code.