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
|
2070 Discussions
|
Please Login in order to post a comment
solution in Ruby:
Here is solution in python, java, c++, c and javascript programming - https://programmingoneonone.com/hackerrank-sherlock-and-the-valid-string-solution.html
Possible issue in test case validation
For the input
aaaabbbbccc, frequencies area=4, b=4, c=3. Removing any single character results in frequencies(4,4,2),(3,4,3), or(4,3,3), none of which are equal.So by the problem statement (“remove exactly one character to equalize frequencies”), this string should be invalid. However, it is accepted because the checker only verifies “two frequencies with difference 1 and one occurring once”, which is not sufficient in this case.
This looks like a test-case or validation logic issue rather than a solution bug.
Python solution with Collections.Counter. Time: O(N), Space: O(1)