Final Array State After K Multiplication Operations II - 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.

After the k operations, apply modulo 10⁹ + 7 to every value in nums.

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

Input & Output

Example 1 — Basic Operations
$ 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, [2,2,3,5,6]. Operation 2: min=2 at index 0, [4,2,3,5,6]. Operation 3: min=2 at index 1, [4,4,3,5,6]. Operation 4: min=3 at index 2, [4,4,6,5,6]. Operation 5: min=4 at index 0, [8,4,6,5,6].
Example 2 — Small Array
$ Input: nums = [1,2], k = 3, multiplier = 4
Output: [16,8]
💡 Note: Operation 1: min=1 at index 0, [4,2]. Operation 2: min=2 at index 1, [4,8]. Operation 3: min=4 at index 0, [16,8].
Example 3 — Large Values with Modulo
$ Input: nums = [100000,2000], k = 2, multiplier = 1000000
Output: [999999307,999999993]
💡 Note: After operations array becomes very large, modulo 10^9+7 is applied: [100000000000, 2000000000] → [999999307, 999999993]

Constraints

  • 1 ≤ nums.length ≤ 104
  • 1 ≤ nums[i] ≤ 109
  • 1 ≤ k ≤ 109
  • 1 ≤ multiplier ≤ 106

Visualization

Tap to expand
K Multiplication Operations: Transform Array by Multiplying MinimumsInitial:21356min × 2After Op 1:22356Continue for k=5 operations...Final Result:84656All values % (10^9 + 7)
Understanding the Visualization
1
Initial Array
Start with nums = [2,1,3,5,6], k=5, multiplier=2
2
Find & Multiply
Repeatedly find minimum, multiply by 2
3
Apply Modulo
Final result with modulo 10^9+7 applied
Key Takeaway
🎯 Key Insight: Use heap to efficiently find minimum elements in O(log n) instead of O(n) linear search
Asked in
Google 15 Amazon 12 Facebook 8
3.2K Views
Medium Frequency
~25 min Avg. Time
89 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