2274. Maximum Consecutive Floors Without Special Floors
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 52% Topics: Array, Sorting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(1)
# sort
class Solution(object):
def maxConsecutive(self, bottom, top, special):
"""
:type bottom: int
:type top: int
:type special: List[int]
:rtype: int
"""
special.sort()
result = max(special[0]-bottom, top-special[-1])
for i in xrange(1, len(special)):
result = max(result, special[i]-special[i-1]-1)
return result
Solution from kamyu104/LeetCode-Solutions · MIT