Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created March 1, 2023 20:02
Show Gist options
  • Save abel-masila/3c07535d443e4528a26af627f6dea588 to your computer and use it in GitHub Desktop.
Save abel-masila/3c07535d443e4528a26af627f6dea588 to your computer and use it in GitHub Desktop.
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