Ctrl K

Growing Charges

Medium
A customer has two accounts holding first and second coins. A subscription charges them every day, and the charge grows: on day i (days start at 1) it takes i coins. The money is always taken from the account that currently holds more; on a tie, from the first one. If that account has fewer than i coins, the charge fails and the subscription stops. Return [day, rest1, rest2]: the day on which the charge failed and the balances of the first and second accounts at that moment.
Example 1
first=3, second=1 → [3, 0, 1]

Day 1: 1 is taken from account 1 (2 left). Day 2: account 1 is still larger, 2 is taken (0 left). Day 3: account 2 is larger but holds only 1 < 3, so the charge fails.

Example 2
first=0, second=0 → [1, 0, 0]

On day 1 there is nothing to cover a charge of 1.

Example 3
first=5, second=9 → [5, 1, 3]
Constraints
  • 0 ≤ first, second ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMultiplying Digit Strings MediumMultiply Complex Numbers in Strings MediumTotal of a Fraction Chain MediumSolve for x MediumRotating Operator Countdown Medium
loading Python…
Input
first=3, second=1
Expected
[3, 0, 1]

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