Palindrome Index | HackerRank

can anyone help me how to optimise this solution.
I’m getting tle.
i have used brute force solution.

there is discussion tab in which u can find the logic or approach to the problem.

Palindrome Index Discussions | Algorithms | HackerRank