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 Operations INPUT Initial Array: nums 2 i=0 1 i=1 3 i=2 5 i=3 6 i=4 k = 5 multiplier = 2 Perform k operations: 1. Find minimum value 2. Select first occurrence 3. Multiply by multiplier Use Min Heap for efficient minimum finding ALGORITHM STEPS 1 Op 1: min=1 at i=1 [2,1,3,5,6] --> [2,2,3,5,6] 2 Op 2: min=2 at i=0 [2,2,3,5,6] --> [4,2,3,5,6] 3 Op 3: min=2 at i=1 [4,2,3,5,6] --> [4,4,3,5,6] 4 Op 4: min=3 at i=2 [4,4,3,5,6] --> [4,4,6,5,6] 5 Op 5: min=4 at i=0 [4,4,6,5,6] --> [8,4,6,5,6] Min Heap stores (value, index) Heap: [(val, idx), ...] Pop min, multiply, push back Time: O(k log n) FINAL RESULT Output Array: 8 4 6 5 6 [8, 4, 6, 5, 6] Verification: 2*2*2 = 8 (3 ops on i=0) 1*2*2 = 4 (2 ops on i=1) 3*2 = 6 (1 op on i=2) 5 unchanged (0 ops) 6 unchanged (0 ops) Total: 3+2+1 = 6? No, 5 ops OK Key Insight: Use a Min Heap storing (value, index) pairs to efficiently find and update the minimum element. The index is stored to handle ties (first occurrence rule) and to update the result array correctly. Time Complexity: O(k log n) | Space Complexity: O(n) for the heap TutorialsPoint - Final Array State After K Multiplication Operations I | Optimal Solution
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