NewThe Learning module is now liveSee what's new

There are n people standing in a queue at an ATM.

You are given an integer array amounts, where amounts[i] is the amount of money the (i+1)th(i+1)^{\text{th}} person wants to withdraw, and an integer k, which is the maximum amount the ATM allows in one turn.

During each turn, the person at the front of the queue withdraws at most k dollars. If they still need more money, they move to the back of the queue. Otherwise, they leave the queue permanently.

Return an array containing the order in which people leave the queue. Each person should be identified by their original 1-based position.

Constraints:

  • 1 ≤ amounts.length ≤ 10310^3
  • 1 ≤ amounts[i] ≤ 10510^5
  • 1 ≤ k ≤ 10510^5

Example 1:

Input: amounts = [2, 7, 4], k = 3 Output: [1, 3, 2] Explanation:

  • Person 1 needs only one turn, so they leave first.
  • Person 2 and person 3 both return to the back of the queue after partial withdrawals.
  • Person 3 finishes before person 2, so the final order is [1, 3, 2].

Example 2:

Input: amounts = [5], k = 3 Output: [1]

Example 3:

Input: amounts = [1, 2, 3, 4, 5], k = 1 Output: [1, 2, 3, 4, 5]


Accepted
1.9k/3.1k
Acceptance Rate60.1%
Test Cases
Input
amounts =
k =
Output
Expected