Company: Sap_20nov
Difficulty: medium
Task 2 Problem Description You are given an array A of N integers. A segment is a pair of adjacent elements (A[i], A[i + 1]) , and the sum of that segment is A[i] + A[i + 1] . Choose as many segments as possible so that every chosen segment has the same sum , and no two chosen segments share a position (they are pairwise non-intersecting). Return the largest number of segments that can be chosen. Input Format A single line holding the array, either as space-separated integers or in bracketed form: [10, 1, 3, 1, 2, 2, 1, 0, 4] Both forms are accepted; brackets and commas are treated as separators. Output Format Print a single integer: the maximum number of pairwise non-intersecting adjacent segments that all share one sum. Constraints 2 <= N <= 2000 0 <= A[i] <= 10^9 Examples Example 1 Input: [10, 1, 3, 1, 2, 2, 1, 0, 4] Output: 3 Explanation: the segments (1, 3) at positions 1-2, (2, 2) at positions 4-5 and (0, 4) at positions 7-8 all sum to 4 and share no position. No sum