Repeatedly pick the smallest array element, multiply it by a given factor, and return the final array state after operations.
Problem
You are given an integer array nums, an integer k, and an integer multiplier.
Perform exactly k operations. In each operation:
- Find the smallest value in the array. If multiple elements are equally small, choose the one with the smallest index.
- Multiply that chosen value by
multiplier.
After all operations, return the resulting array.
The array is updated in place after every operation, so later choices use the latest values.
Goal
Simulate the process efficiently and return the final array state.
Input Format
nums: integer arrayk: number of operations to performmultiplier: integer factor applied to the chosen element each step
Output Format
- Return the final state of
numsafter exactlykoperations.
Constraints
- The array length is at least 1.
- Perform exactly
kupdates. - If there are ties for the minimum value, pick the leftmost occurrence.
- Values may change after each multiplication, so each step depends on the previous one.
Example 1
Input
nums = [2, 1, 3], k = 2, multiplier = 3
Output
[6, 3, 3]
Explanation
Step 1: the minimum is 1 at index 1, so it becomes 3. Array becomes [2, 3, 3]. Step 2: the minimum is 2 at index 0, so it becomes 6. Final array is [6, 3, 3].
Example 2
Input
nums = [5], k = 4, multiplier = 2
Output
[80]
Explanation
There is only one element, so it is chosen every time: 5 -> 10 -> 20 -> 40 -> 80.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.