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.
My answer with Typescript, can be increase [point] to increase number of character can be remove
functionisValid(s:string):string{// 0. count every char in [s]lethash=newMap<string,number>()for(letcofs)hash.set(c,(hash.get(c)||0)+1)// 1. define a [value_average] and [point] that can be decreateletvalues=Array.from(hash.values())letvalue_average=values[0]letpoint=1// 2. loop from 1 to end, check value gap and decreate point// -> if [point] is out, return 'NO'// -> orelse return 'YES'for(leti=1;i<values.length;i++){letvalue=values[i]if(value!=value_average){if(point==0)return'NO'point--}}return'YES'}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →
My answer with Typescript, can be increase [point] to increase number of character can be remove