Skip to main content
Back to problems
#3264
Easy Algorithms

Final array state after k multiplication operations i

Array Math Heap (Priority Queue) Simulation
86.9% acceptance
Feb 25, 2026
544
13
You are given an integer array nums, an integer k, and an integer multiplier. Perform k operations: find the minimum x (first occurrence), replace with x * multiplier. Return the final state of nums.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn get_final_state(mut nums: Vec<i32>, k: i32, multiplier: i32) -> Vec<i32> {
    for _ in 0..k {
      let min_idx = nums
        .iter()
        .enumerate()
        .min_by_key(|&(_, &v)| v)
        .unwrap()
        .0;
      nums[min_idx] *= multiplier;
    }
    nums
  }
}