Created
March 1, 2023 20:02
-
-
Save abel-masila/3c07535d443e4528a26af627f6dea588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function palindromeChecker(s, startindex, endindex, subs) { | |
let result = ''; | |
for (let i = 0; i < startindex.length; i++) { | |
let sub = s.substring(startindex[i], endindex[i] + 1); | |
let count = new Array(26).fill(0); | |
for (let j = 0; j < sub.length; j++) { | |
count[sub.charCodeAt(j) - 97]++; | |
} | |
let oddCount = 0; | |
for (let j = 0; j < 26; j++) { | |
if (count[j] % 2 !== 0) { | |
oddCount++; | |
} | |
} | |
if (oddCount <= subs[i] * 2 + 1) { | |
result += '1'; | |
} else { | |
result += '0'; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment