PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving and array-manipulation skills, focusing on sliding-window and iterative reduction concepts within the Coding & Algorithms domain.

  • medium
  • Vmware
  • Coding & Algorithms
  • Software Engineer

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.

Repeatedly replace the array by all k-window sums until its length is at most k, then return the final sum.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([1,1,1,2,1,2], 3)

Expected Output: 24

Explanation: The example reduces to [11,13] and returns 24.

Input: ([1,2], 3)

Expected Output: 3

Explanation: Already short enough, so return sum.

Input: ([1,-1,2,-2], 2)

Expected Output: 2

Explanation: Negative values are allowed.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.