Count Complete Rows in a Coin Staircase

Quick Overview

Practice counting complete staircase rows from a coin total. Handle exact triangular totals, partial final rows, and overflow-safe arithmetic across the full input range.

Count Complete Rows in a Coin Staircase

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

# Count Complete Rows in a Coin Staircase Build rows of coins in order, using exactly `i` coins in row `i`, beginning with row one. Given `n` coins, return the number of complete rows you can build. Any coins left for an incomplete next row do not count as another complete row. ### Function `int arrangeCoins(int n)` ### Example 1 ```text Input: n = 10 Output: 4 ``` Four complete rows use `1+2+3+4=10` coins. ### Example 2 ```text Input: n = 2 Output: 1 ``` The first row is complete, but only one coin remains for the two-coin second row. ### Constraints - `1 <= n <= 2147483647`. ### Clarifications Rows must use `1,2,3,...` coins without skipping a row. Return the number completed, not the number of coins left or the partially started final row. ### What a Strong Answer Covers - Exact triangular totals and an incomplete next row. - The full signed 32-bit input range. - Why the returned row count is feasible and the next count is not. - Arithmetic safety and resource bounds.

Overview: Practice counting complete staircase rows from a coin total. Handle exact triangular totals, partial final rows, and overflow-safe arithmetic across the full input range.

Meta logo
Meta
easySoftware EngineerOtherCoding & Algorithms
0
0

Count Complete Rows in a Coin Staircase

Build rows of coins in order, using exactly i coins in row i, beginning with row one. Given n coins, return the number of complete rows you can build. Any coins left for an incomplete next row do not count as another complete row.

Function

int arrangeCoins(int n)

Example 1

Input: n = 10
Output: 4

Four complete rows use 1+2+3+4=10 coins.

Example 2

Input: n = 2
Output: 1

The first row is complete, but only one coin remains for the two-coin second row.

Constraints

  • 1 <= n <= 2147483647 .

Clarifications

Rows must use 1,2,3,... coins without skipping a row. Return the number completed, not the number of coins left or the partially started final row.

What a Strong Answer Covers Guidance

  • Exact triangular totals and an incomplete next row.
  • The full signed 32-bit input range.
  • Why the returned row count is feasible and the next count is not.
  • Arithmetic safety and resource bounds.