Ctrl K

Boost the Smallest, k Times Over

Hard
You are given an array values and integers rounds and factor. Run rounds rounds; in each round find the smallest number in the array (the leftmost one if there are ties) and multiply it by factor. After all the rounds, replace every number with its remainder modulo 10⁹ + 7 and return the resulting array. There can be up to 10⁹ rounds, so simulating them one by one is too slow. Note that the remainder is taken only at the very end: during the rounds the true (huge) values are compared.
Example 1
values=[3, 1, 4], rounds=4, factor=3 → [9, 9, 12]

[3, 1, 4] → [3, 3, 4] → [9, 3, 4] (of the two 3s, the left one goes first) → [9, 9, 4] → [9, 9, 12]. Every number is below 10⁹ + 7, so the remainder changes nothing.

Example 2
values=[500000000, 7], rounds=3, factor=10 → [500000000, 7000]

7 → 70 → 700 → 7000: after three rounds the array is [500000000, 7000], and the remainder changes nothing.

Example 3
values=[1000000000, 1000000000], rounds=3, factor=2 → [999999979, 999999993]

This gives [4·10⁹, 2·10⁹]; modulo 10⁹ + 7 that is 999999979 and 999999993.

Constraints
  • 1 ≤ len(values) ≤ 10⁴
  • 1 ≤ values[i] ≤ 10⁹
  • 1 ≤ rounds ≤ 10⁹
  • 1 ≤ factor ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBusiest Meeting Room HardCrates Over the Footbridge HardShuttle Seat Plan MediumUnfilled Exchange Orders MediumClearing the Stacks Evenly Easy
loading Python…
Input
values=[3, 1, 4], rounds=4, factor=3
Expected
[9, 9, 12]

Run checks the first 3 tests in your browser. Submit checks all 5 tests on the server, hidden ones included.