We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Sherlock and the Valid String
- Discussions
Sherlock and the Valid String
Sherlock and the Valid String
Sort by
recency
|
92 Discussions
|
Please Login in order to post a comment
Hi :) My solution in Python 3:
If the frequency of the characters is all the same, then return Yes.
Or if there's only 2 types of numbers representing the frequency of characters, and if by removing one character, all of them have the same frequency, return Yes. This can be represented in two ways:
1. n n n ... n 1, where removing the char with frequency 1 restores our condition, or 2. n n n ... n n+1 where removing the char with frequency n+1 restores the condition required.
Anything else gives us No.
Python3:
C++ without map:
string isValid(string s) { if (s.size() == 1) return "YES";
}
PYTHON 3 CODE