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
xinnums. - If there are multiple occurrences of the minimum value, select the one that appears first.
- Replace the selected minimum value
xwithx * 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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code