A “valid” string is a string S such that for all distinct characters in S each such character occurs the same number of times in S. For example, aabb is a valid string because the frequency of both characters a and b is 2, whereas aabbc is not a valid string because the frequency of characters a, b, and c is not the same. Watson gives a string S to Sherlock and asks him to remove some characters from the string such that the new string is a “valid” string. Sherlock wants to know from you if it’s possible to be done with less than or equal to one removal..
I tried to solve this specific challenge in Hackerank and I can’t pass all the test cases. 2 is the minimum number of removals required to make it a valid string. It can be done in following two ways:
input = aabbcd…
Sample Output must be NO.
Explanation
Remove c and d to get aabb. Or remove a and b to get abcd.
—————————————————–here is my code—————————————————-
[CODE]function processData(input) {
//Enter your code here
var i =0;
var m = string.match(/string[i]/);
if (m && m.length > 2) {
console.log(“yes”);
} else {console.log (“NO”);}
console.log(m);
The thing is that match() returns null…..
Please if you find time answer my question!
Thank you so much