Company: exxonmobil_5sep
Difficulty: medium
Equal Sum Halves Substring Problem Description You are given a string s of length n made up of the digits 0-9. Determine and print the length of the longest substring s' of even length such that, writing that length as 2k digits, the sum of its first k digits equals the sum of its last k digits. Note: Print 0 if no substring satisfies this balanced-sum condition. Input Format The input consists of two lines: The first line contains an integer denoting n . The second line contains a string denoting s . Input will be read from the STDIN by the candidate Output Format Print the length of the longest even length substring. The output will be matched to the candidate's output printed on the STDOUT Constraints 1 <= n <= 10^3 0 <= s_i <= 9 (where s_i is a digit in string s ) Examples Example 1: Input: 7 1241424 Output: 6 Explanation: s : 1241424. The longest even-length substring whose two halves sum equally is 124142. The first half (124) sums to 7, and the second half (142) also