Arrange Coins
Problem statement
You are given an integer array coins. For each element, determine the largest number of complete rows that can be built using that many coins.
Row 1 needs 1 coin, row 2 needs 2 coins, and in general row r needs r coins. Return an array in which each result corresponds to the coin count at the same input index.
Function
arrangeCoins(coins: int[]) → int[]Examples
Example 1
coins = [3, 4, 6]return = [2, 2, 3]With 3 coins, rows of sizes 1 and 2 use all coins, so the result is 2. With 4 coins, two rows use 3 coins but a third row would need 3 more, so the result is also 2. With 6 coins, rows of sizes 1, 2, and 3 fit exactly, so the result is 3.
Constraints
1 <= coins.length <= 1000000 <= coins[i] <= 1000000000