Longest even length palindromic sum substring

Find the length of longest contiguous substring of a string, such that the length of the substring is 2 * N digits and the sum of the leftmost N digits is equal to the sum of the rightmost N digits. If there is no such substring, return 0.

Example Solution

Imagine the solution function is given the number sequence 13267224. For this sequence, the longest palindromic substring which satisfies the constraints is 326722. The length of 326722 is 6.

(3 + 2 + 6) = (7 + 2 + 2) = 11

The solution function should return 6 as the correct answer.

Contributed by Murat Sütunç