Hard: Sherlock and valid string
March 7, 2023
Question: Given a string, Sherlock considers it valid if all the characters in the string occur the same number of time. However, a string is also valid if the frequencies are same after removing any one character.
Input: str = “aabbcd”
Input: str = “abcc”
Let's break down the problem statement (opens in a new tab).
Sherlock needs to verify if a given string is valid. A string is valid under 2 conditions:
- All characters of the string have same frequencies
- If you can delete any one character from the string to achieve condition #1.
Try it yourself https://go.dev/play/p/jtD3sCn5LkJ (opens in a new tab)