Maximize Equal Array Length After Contiguous Sum Merges
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Find the maximum length of equal arrays obtainable by merging adjacent positive values into their sums, or report that equality is impossible.
Constraints
- Both arrays are nonempty, with lengths from 1 through 100000.
- Every element is a positive integer from 1 through 1000000000.
- Only contiguous order-preserving sum merges are allowed; elements cannot be split, reordered or removed.
- Return the maximum equal resulting length, or -1 when totals differ.
- Intermediate and total sums are exact; a total is at most 100000000000000.
Examples
Input: ([1, 2, 3, 3], [3, 3, 3])
Expected Output: 3
Explanation: Published sample 1: merging 1 and 2 yields three matching elements.
Input: ([1, 2], [4])
Expected Output: -1
Explanation: Published sample 2: totals differ, and every merge preserves the total.