Algorithm · ByteDance · Medium
Given an integer array nums of length n and an integer k, remove exactly k consecutive elements from nums so that the remaining array is balanced: the sum of values at even indices equals the sum of values at odd indices. Return the smallest starting index of a k-length consecutive block whose removal makes the array balanced, or -1 if no valid removal exists. Constraints: 1 ≤ k ≤ n ≤ 10^5 -10^9 ≤ nums[i] ≤ 10^9 Example 1: Input: nums = [2, 1, 6, 4], k = 1 Output: 1…
Checking your access…