Problem · Queue

ATM Queue Exit Order

Learn this problem
MediumSalesforcePHONE SCREEN
See Salesforce hiring insights

Problem statement

There are n people standing in a queue, numbered from 1 to n. Person i wants to withdraw amounts[i] units of money.

The ATM allows at most k units per transaction. If a person still has money left after a transaction, they move to the end of the queue. Otherwise, they leave the queue.

Return the order in which people leave the queue.

Function

atmQueueOrder(amounts: int[], k: int) → int[]

Examples

Example 1

amounts = [2,3,1,4,2]k = 2return = [1,3,5,2,4]

People 1, 3, and 5 finish during their first turn. Person 2 finishes before person 4 on their later turns.

The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

More Salesforce problems

drafts saved locally
public int[] atmQueueOrder(int[] amounts, int k) {
  // write your code here
}
amounts[2,3,1,4,2]
k2
expected[1,3,5,2,4]
checking account