Complete Rows of a Coin Staircase
Updated
Problem statement
You have n coins and want to lay them out as a staircase. Row 1 needs 1 coin, row 2 needs 2 coins, row 3 needs 3 coins, and in general row k needs exactly k coins.
Fill the rows in order, starting with row 1. A row counts only when it gets all of its coins, so a last row that is only partly filled does not count.
Return the number of complete rows.
Function
arrangeCoins(n: int) → intExamples
Example 1
n = 38return = 8The first 8 rows use 1 + 2 + ... + 8 = 36 coins. Row 9 would need 9 more, but only 38 - 36 = 2 coins are left, so that row stays incomplete. The answer is 8.
Example 2
n = 78return = 12The first 12 rows use 1 + 2 + ... + 12 = 78 coins, exactly all of them, so there are 12 complete rows and nothing is left over.
Example 3
n = 2024return = 6363 rows use 63 * 64 / 2 = 2016 coins. Row 64 would need 64 more, but only 2024 - 2016 = 8 coins are left. The answer is 63.
Constraints
1 <= n <= 2^31 - 1
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Floor Square Roots for an ArrayWells Fargo · OAWells Fargo interview questions
- Days to Overtake Another CoderJP Morgan Chase · OAJP Morgan Chase interview questions
- Arrange CoinsAlarm.com · OA
- Perfect Squares Matching a PatternNielsen · OA
- Maximum Alloy Production Within BudgetMicrosoft · OAMicrosoft interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Count Lucky Numbers in a RangeTarget · OA
- Cyber Beacon DetectionRippling · OARippling interview questions
- Souvenir Shop PurchasesAmazon · OA
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)