PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This Coding & Algorithms question evaluates algorithmic problem-solving skills in array manipulation and constrained optimization, testing competency in reasoning about value distribution, large numeric bounds, and performance under tight complexity limits.

  • easy
  • MathWorks
  • Coding & Algorithms
  • Software Engineer

Maximize minimum after K decrements

Company: MathWorks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given an integer array `A` of length `N` and an integer `K`. You must perform exactly `K` operations. In each operation, choose any index `i` and do `A[i] = A[i] - 1`. After all `K` operations, let `min(A)` be the minimum value in the array. Your goal is to choose the operations to **maximize** `min(A)`. Return the maximum possible value of `min(A)` after exactly `K` operations. **Input** - `A`: array of `N` integers - `K`: non-negative integer **Output** - An integer: the maximum achievable minimum value. **Notes / Constraints (reasonable for interviews)** - `1 <= N <= 2e5` - `-1e9 <= A[i] <= 1e9` - `0 <= K <= 1e18` **Example** - `A = [5, 1, 7]`, `K = 3` - One optimal strategy is to decrement `7` three times → `[5, 1, 4]`, so `min(A) = 1`. - The answer is `1`.

Quick Answer: This Coding & Algorithms question evaluates algorithmic problem-solving skills in array manipulation and constrained optimization, testing competency in reasoning about value distribution, large numeric bounds, and performance under tight complexity limits.

Perform exactly K decrements on array elements and maximize the final minimum value.

Constraints

  • 1 <= len(A)
  • K >= 0

Examples

Input: ([5, 1, 7], 3)

Expected Output: 1

Explanation: Decrement values above the minimum.

Input: ([1, 1], 1)

Expected Output: 0

Explanation: Once all values equal the minimum, one decrement lowers the minimum.

Input: ([4, 4, 4], 5)

Expected Output: 2

Explanation: Distribute decrements evenly after equalization.

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

Expected Output: -2

Explanation: Handles negative values.

Hints

  1. First spend decrements on elements above the current minimum; only extra decrements force the minimum lower.
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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimize shortest path by adding weight-1 edges - MathWorks (easy)
  • How to maximize rewards with exactly k tasks - MathWorks (easy)
  • Maximize minimum value after k decrements - MathWorks (medium)
  • Determine Whether P's Position Is Unique - MathWorks (medium)
  • Minimize reduction cost and validate equal-sum pairs - MathWorks (medium)