Final Array State After K Multiplication Operations I
You are given an integer array `nums`, an integer `k`, and an integer `multiplier`. Perform `k` operations on `nums`. In each operation, find the minimum value `x` in `nums` (if it appears more than once, take the one that appears first) and replace it with `x * multiplier`. Return the array after all `k` operations.
30:00
Final Array State After K Multiplication Operations I
You are given an integer array nums, an integer k, and an integer multiplier. Perform k operations on nums. In each operation, find the minimum value x in nums (if it appears more than once, take the one that appears first) and replace it with x * multiplier. Return the array after all k operations.
Example 1:
Input: {"nums":[2,1,3,5,6],"k":5,"multiplier":2}
Output: [8,4,6,5,6]
Constraints:
1≤nums.length≤100
1≤nums[i]≤100
1≤k≤10
1≤multiplier≤5
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[2,1,3,5,6],"k":5,"multiplier":2}
operation 0 / 5
multiplier x2
nums (bar height on a log scale, dots = times multiplied)
2
0
1
1
3
2
5
3
6
4
min-heap of (value, index), smallest first
(1, 1)
(2, 0)
(3, 2)
(5, 3)
+1 more
Put every (value, index) pair in a min-heap. Comparing by value, then by index, makes the heap's top the smallest value that appears first.