Move Units Left to Minimize the Largest Array Value

Quick Overview

Minimize an array’s largest value by transferring units only to the immediately preceding position, with any number of operations.

Move Units Left to Minimize the Largest Array Value

Company: Visa

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem One operation chooses i>0 with nums[i]>0, decreases nums[i] by 1, and increases nums[i-1] by 1. Starting from nonnegative `nums`, return the smallest possible maximum entry after any number of such leftward transfers. ```cpp class Solution { public: int minimizeArrayValue(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text Input: nums = [0,6] Output: 3 Explanation: Move three units left to obtain [3,3]; the total6 over two entries rules out a maximum below3. ``` **Example 2:** ```text Input: nums = [5,0,0] Output: 5 Explanation: The leading5 cannot move right, so it can never decrease. ``` ### Constraints - `2 <= nums.length <= 100000`. - `0 <= nums[i] <= 10^9`. ### Clarifying Questions - Can units move right? No; each operation transfers one unit to the immediate left. - Can an entry become negative? No; transfer only from a positive entry. - Are operations optional? Yes. - Must the final array be returned? No; return only its smallest achievable maximum. ```hint Check the boundary Consider what can happen to the first entry, which has no position to its left. ```

Overview: Minimize an array’s largest value by transferring units only to the immediately preceding position, with any number of operations.

Visa logo
Visa
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

One operation chooses i>0 with nums[i]>0, decreases nums[i] by 1, and increases nums[i-1] by 1. Starting from nonnegative nums, return the smallest possible maximum entry after any number of such leftward transfers.

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

Examples

Example 1:

Input: nums = [0,6]
Output: 3
Explanation: Move three units left to obtain [3,3]; the total6 over two entries rules out a maximum below3.

Example 2:

Input: nums = [5,0,0]
Output: 5
Explanation: The leading5 cannot move right, so it can never decrease.

Constraints

  • 2 <= nums.length <= 100000 .
  • 0 <= nums[i] <= 10^9 .

Clarifying Questions Guidance

  • Can units move right? No; each operation transfers one unit to the immediate left.
  • Can an entry become negative? No; transfer only from a positive entry.
  • Are operations optional? Yes.
  • Must the final array be returned? No; return only its smallest achievable maximum.