Count deletions making array fair
Company: TikTok
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency with array manipulation, parity-aware summation, and combinatorial counting when elements are removed, situating it in the Coding & Algorithms domain.
Constraints
- 1 <= len(nums) <= 200000
- -10^9 <= nums[i] <= 10^9
- Use 64-bit integer arithmetic for sums
- Target time complexity: O(n)
- Target extra space: O(1)
Hints
- Compute total sums at even and odd indices once.
- Scan left-to-right maintaining prefix sums left_even and left_odd.
- When removing index i, the suffix elements shift left by one, flipping their parity. New even sum = left_even + suffix_odd; new odd sum = left_odd + suffix_even.