Compute iterative sliding-window sum reduction
Company: Vmware
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
## Problem
Given an integer array `nums` and an integer window size `k`, repeatedly apply the following reduction:
- If `len(nums) > k`: replace `nums` with a new array `next` where
- `next[i] = sum(nums[i : i + k])` for every valid consecutive window of length `k`.
- Thus, `len(next) = len(nums) - k + 1`.
- If `len(nums) <= k`: stop and return `sum(nums)`.
Return the final sum.
### Example
`nums = [1, 1, 1, 2, 1, 2]`, `k = 3`
Round 1 (window size 3):
- `[1,1,1] -> 3`, `[1,1,2] -> 4`, `[1,2,1] -> 4`, `[2,1,2] -> 5`
- New array: `[3, 4, 4, 5]`
Round 2 (window size 3):
- `[3,4,4] -> 11`, `[4,4,5] -> 13`
- New array: `[11, 13]`
Stop because `len([11,13]) = 2 <= 3`, return `11 + 13 = 24`.
### Function Signature
Implement a function like:
- `int reduceSlidingWindowSum(int[] nums, int k)`
### Notes / Constraints (assume)
- `nums.length >= 1`
- `1 <= k`
- Values can be negative; use a wide enough integer type if overflow is possible.
Quick Answer: This question evaluates algorithmic problem-solving and array-manipulation skills, focusing on sliding-window and iterative reduction concepts within the Coding & Algorithms domain.