Arranging Coins

Problem Id: 441 Difficulty: Easy


Intuition

Solution


class Solution:
    def _can_arrange(self, n, stairs):
        return n >= (1 + stairs) * stairs // 2

    def arrangeCoins(self, n: int) -> int:
        start = 0
        end = 1
        while self._can_arrange(n, end):
            end *= 2

        while end - start > 1:
            mid = (start + end) // 2
            if self._can_arrange(n, mid):
                start = mid
            else:
                end = mid
        return start