Final Array State After K Multiplication Operations I - Problem

You are given an integer array nums, an integer k, and an integer multiplier.

You need to perform k operations on nums. In each operation:

  • Find the minimum value x in nums.
  • If there are multiple occurrences of the minimum value, select the one that appears first.
  • Replace the selected minimum value x with x * multiplier.

Return an integer array denoting the final state of nums after performing all k operations.

Input & Output

Example 1 — Basic Case
$ Input: nums = [2,1,3,5,6], k = 5, multiplier = 2
Output: [8,4,6,5,6]
💡 Note: Operation 1: min=1 at index 1, nums becomes [2,2,3,5,6]. Operation 2: min=2 at index 0, nums becomes [4,2,3,5,6]. Operation 3: min=2 at index 1, nums becomes [4,4,3,5,6]. Operation 4: min=3 at index 2, nums becomes [4,4,6,5,6]. Operation 5: min=4 at index 0, nums becomes [8,4,6,5,6].
Example 2 — Single Element
$ Input: nums = [1], k = 3, multiplier = 4
Output: [64]
💡 Note: Start with [1]. After operation 1: [4]. After operation 2: [16]. After operation 3: [64].
Example 3 — No Operations
$ Input: nums = [3,2,1], k = 0, multiplier = 5
Output: [3,2,1]
💡 Note: With k=0, no operations are performed, so array remains unchanged.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 1 ≤ nums[i] ≤ 100
  • 1 ≤ k ≤ 10
  • 1 ≤ multiplier ≤ 5

Visualization

Tap to expand
Final Array State After K Multiplication OperationsInitial:21356k=5 operations, multiplier=2Find minimum (red), multiply by 2After 5 operations:84656TransformOperations Sequence:Op 1: min=1 (idx 1) → 1×2=2 → [2,2,3,5,6]Op 2: min=2 (idx 0) → 2×2=4 → [4,2,3,5,6]Op 3: min=2 (idx 1) → 2×2=4 → [4,4,3,5,6]Op 4: min=3 (idx 2) → 3×2=6 → [4,4,6,5,6]Op 5: min=4 (idx 0) → 4×2=8 → [8,4,6,5,6]
Understanding the Visualization
1
Input Array
nums = [2,1,3,5,6], k=5, multiplier=2
2
Find & Multiply Min
Repeatedly find minimum and multiply by 2
3
Final Result
Array after k operations: [8,4,6,5,6]
Key Takeaway
🎯 Key Insight: Use min-heap to efficiently find minimum in O(log n) instead of O(n) linear search
Asked in
Amazon 15 Google 12 Microsoft 8
12.5K Views
Medium Frequency
~15 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen