Skip to content
LC-1798 Medium LeetCode

1798. Maximum Number of Consecutive Values You Can Make

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Array, Greedy, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(1)

class Solution(object):
    def getMaximumConsecutive(self, coins):
        """
        :type coins: List[int]
        :rtype: int
        """
        coins.sort()
        result = 1
        for c in coins:
            if c > result:
                break
            result += c
        return result

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions