You are viewing a single comment's thread. Return to all comments →
Solution in Kotlin:
fun weightedUniformStrings(s: String, queries: Array<Int>): Array<String> { val weights = mutableSetOf<Int>() var lastChar: Char? = null var lastCharWeight = 0 var currentTotalWeight = 0 for(i in s.indices) { if(s[i] == lastChar) { currentTotalWeight += lastCharWeight } else { lastChar = s[i] lastCharWeight = s[i].code - 'a'.code + 1 currentTotalWeight = lastCharWeight } weights.add(currentTotalWeight) } return queries.map { if ( weights.contains(it) ) "Yes" else "No" }.toTypedArray() }
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
Solution in Kotlin: