Sherlock's Code
Can someone please help me with the below code. 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 1 character at 1 index in the string, and the remaining characters will occur the same number of times. Given a string s, determine if it is valid. For example s=abc, if , it is a valid string because frequencies are {a:1,b:1,c:1} . So is s = abcc because we can remove one c and have 1 of each character in the remaining string. If s =abccc however, the string is not valid as we can only remove one occurrence of c . That would leave character frequencies of . Input Format : A single string s. Output Format : Print YES if string is valid, otherwise, print NO . Sample Input : aabccc Sample Output: NO Given s = aabccd ,we would have to remove a and c from the string to be valid but we limited to remove only one character. Hence s is invalid. https://code.sololearn.com/cY4WJnS353RS/?ref=app