Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just character at index in the string, and the remaining characters will occur the same number of times. Given a string , determine if it is valid. If so, return YES, otherwise return NO.
For example, if , it is a valid string because frequencies are . So is because we can remove one and have of each character in the remaining string. If however, the string is not valid as we can only remove occurrence of . That would leave character frequencies of .
Complete the isValid function in the editor below. It should return either the string YES or the string NO.
isValid has the following parameter(s):
s: a string
A single string .
Print YES if string is valid, otherwise, print NO.
Sample Input 0
Sample Output 0
Given , we would need to remove two characters, both c and daabb or a and babcd, to make it valid. We are limited to removing only one character, so is invalid.