word. Pick three of its letters, keeping their order (they need not be adjacent), so that they form a palindrome: a string that reads the same forwards and backwards, such as "pop" or "eee".
Return how many **distinct** three-letter palindromes can be formed this way. If the same palindrome can be picked in different ways, it still counts once.word="rotor" → 3
The matches are "ror", "rtr" and "oto". For instance, "ror" uses letters 0, 1 and 4.
word="banana" → 3
"aaa", "ana" and "nan". The palindrome "ana" can be picked in several ways but counts only once.
word="abc" → 0
All letters differ, so the outer letters of a palindrome can never match: the answer is 0.
word consists of lowercase English lettersword="rotor"
3
Run checks the first 3 tests in your browser. Submit checks all 78 tests on the server, hidden ones included.