You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.

Given the integer n, return the number of complete rows of the staircase you will build.

&nbsp;
Example 1:

Input: n = 5
Output: 2
Explanation: Because the 3rd row is incomplete, we return 2.


Example 2:

Input: n = 8
Output: 3
Explanation: Because the 4th row is incomplete, we return 3.


&nbsp;
Constraints:


	1 &lt;= n &lt;= 231 - 1


class Solution:
    def arrangeCoins(self, n: int) -> int:
        for i in range(1,2**31):
            val=i*(i+1)//2
            if val>n:
                a=i
                break
            elif val==n:
                return i
        return a-1
class Solution {
    public int arrangeCoins(int n) {
        long s =0; long e = n;
        while (s <= e) {
         long mid = s +(e-s)/2;
            long coin = mid *( mid +1)/2;
            if(coin > n){
                 e = mid -1;
            } else if (coin < n){
                s = mid +1;
            } else return (int) mid;
        }
        return (int)e;
    }
}
class Solution {
public:
    int arrangeCoins(int n) {

         int count=0;
         while(n>0)
         {
             count++;
             n=n-count;
         }
         if(n==0) //all the coins are used to make complete rows so n if fully uitlized till 0
         {
             return count;
         }
         else if(n<0) //if the last row has not been created fully then n will go negative
         {
             return count-1;
         }
         return -1; //this will never get encountered

    }
};
var arrangeCoins = function(n) {
    if(n===1) return n
    for(let i=1; i<=n; i++){
        if(n<Math.floor((i*(i+1))/2)){
            return i-1
        }
    }
};
Arranging Coins