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
Sherlock and the Valid String
Sort by
recency
|
2044 Discussions
|
Please Login in order to post a comment
My answer with Typescript, can be increase [point] to increase number of character can be remove
PYTHON :
Less Spoiler: Possible scenarios: case1: aaabbbcccddd case2.abbbcccddd case3:aaaabbbcccdddd
Spoiler: // case 1: uniqueFreqs == 1 means: All characters have the same frequency // example: "aabbccdd" all appear twice. The only distinct frequency is 2. // case 2: There are 2 distinct values and one of them is "1" and it occurs only once // example: aaaabbbbc the occurance of 4 (a and b) is 2 and the occurance of 1 is(c) is one. Remove the only letter which appears once // case 3: Frequencies differ by 1, and the higher frequency appears only once example: aaaabbbbccccc
Java with array Hashmap is also an option I guess.
here f1==1 is for edge case - where only single alphabet is in string while all other have same frequency