I am trying to face a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm struggling to optimize it.

For example, the chain "cacbbba" would rotate 6 times and would have 3 palindromes in each chain.

- cacbbba (3 palindromes)
- acbbba
**do**(3 palindromes) - cbbba
**California**(3 palindromes) - bbba
**cac**(3 palindromes) - bba
**cacb**(3 palindromes) - licensed in letters
**cacbb**(3 palindromes) - a
**cacbbb**(3 palindromes)

```
circular functionPalindromes (s) {
const k = s.length;
result of const = [];
const isPalindrome = (str) => {
const len = str.length;
for (be i = 0; i < len / 2; i++) {
if (str[i] !== str[len - 1 - i]) {
return false;
}
}
return true;
};
const subs = (s) => {
leaves max = 0;
for (be i = 0; i <s.length; i ++) {
for (be j = 1; j <= s.length - i; j ++) {
const sub = s.substring (i, i + j);
if (sub.length < 2) continue;
if (isPalindrome(sub) && sub.length > max) {
max = sub.length;
}
}
}
return max;
};
for (be i = 0; i <k; i ++) {
result.push (subs (s.substring (i, k) + s.substring (0, i)));
}
return result
}
console.log (circularPalindromes (& # 39; cacbbba & # 39;));
```