Arranging Coins
Real-world version: Complete Tiers Of The Tin DisplayThe statement here is our own: the same inputs, outputs and technique.
A shop builds a stepped display of tins. Tier 1 across the top holds one tin, tier 2 below it holds two tins, and in general tier i holds i tins.
With n tins in stock, the staff work downwards and fill each tier completely before starting the next one, stopping when the stock runs short of what the next tier needs. Return how many tiers end up complete.
Examples
Example 1
- Input
- n = 7
- Output
- 3
Tier 1 takes 1 tin, tier 2 takes 2 and tier 3 takes 3, which uses 6 of the 7 tins. Tier 4 needs 4 tins and only 1 is left, so 3 tiers are complete.
Example 2
- Input
- n = 999999999
- Output
- 44720
The first 44720 tiers take 999961560 tins altogether, leaving 38439 tins. Tier 44721 needs 44721 tins, which is more than what is left, so 44720 tiers are complete.
Example 3
- Input
- n = 6
- Output
- 3
Tiers 1, 2 and 3 take 1, 2 and 3 tins, using the stock exactly, so all 3 tiers are complete and nothing is left over.
Constraints
- 1 <= n <= 2^31 - 1
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def arrange_coins(n: int) -> int:public int arrangeCoins(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's