Count Deletions that Balance Index-Parity Sums

Quick Overview

Count Deletions that Balance Index-Parity Sums. Delete exactly one entry from nums and close the gap, giving the remaining entries new zero-based indices. Count the original indices whose deletion makes the new even-index sum equal to the new odd-index sum.

Count Deletions that Balance Index-Parity Sums

Company: GoDaddy

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Delete exactly one entry from `nums` and close the gap, giving the remaining entries new zero-based indices. Count the original indices whose deletion makes the new even-index sum equal to the new odd-index sum. ```cpp class Solution { public: int waysToMakeFair(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [4,4,4] Output: 3 Explanation: Each deletion leaves [4,4], whose parity sums match. ``` **Example 2:** ```text nums = [2,2,5] Output: 1 Explanation: Only deleting the final 5 leaves equal parity sums. ``` ### Constraints - `1 <= nums.length <= 10^5`. - `1 <= nums[i] <= 10^4`. ### Clarifying Questions Exactly one entry is removed. Entries to its right shift left one position, reversing their index parity; entries to its left keep their parity. ```hint Inspect the structure How do positions to either side of a deletion acquire their new zero-based indices? ``` ### Reasoning checkpoints - Exclude the deleted value from both sides. - Flip suffix parity before checking equality. ### Optional extensions What answer follows for a single-element input, where the remaining array is empty?

Overview: Count Deletions that Balance Index-Parity Sums. Delete exactly one entry from nums and close the gap, giving the remaining entries new zero-based indices. Count the original indices whose deletion makes the new even-index sum equal to the new odd-index sum.

GoDaddy logo
GoDaddy
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

Delete exactly one entry from nums and close the gap, giving the remaining entries new zero-based indices. Count the original indices whose deletion makes the new even-index sum equal to the new odd-index sum.

class Solution {
public:
    int waysToMakeFair(vector<int>& nums);
};

Examples

Example 1:

nums = [4,4,4]
Output: 3
Explanation: Each deletion leaves [4,4], whose parity sums match.

Example 2:

nums = [2,2,5]
Output: 1
Explanation: Only deleting the final 5 leaves equal parity sums.

Constraints

  • 1 <= nums.length <= 10^5 .
  • 1 <= nums[i] <= 10^4 .

Clarifying Questions Guidance

Exactly one entry is removed. Entries to its right shift left one position, reversing their index parity; entries to its left keep their parity.

Reasoning checkpoints

  • Exclude the deleted value from both sides.
  • Flip suffix parity before checking equality.

Optional extensions

What answer follows for a single-element input, where the remaining array is empty?