0

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

19th Sep 2019, 2:08 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
3 Answers
+ 2
It seems you are modifying the string and you're checking for two consecutive similar characters. These constraints are not mentioned.
20th Sep 2019, 4:41 PM
Manoj
Manoj - avatar
0
PETA4life can you please help?
19th Sep 2019, 7:09 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
- 1
Jay Matthews John Wells ODLNT Sir Can you please help
19th Sep 2019, 3:41 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar