#2274

Maximum Consecutive Floors Without Special Floors

specialist · 840 · lc medium +31 · verified · 52.5% accepted · 430 likes · top 43%

Description

Alice rents all floors from bottom to top inclusive and has marked certain floors as special relaxation areas.

Given integers bottom, top, and an integer array special listing the special floors, return the maximum count of consecutive non-special floors within the rented range.

Example 1:

Input: bottom = 2, top = 9, special = [4,6]
Output: 3
Explanation: The following are the ranges (inclusive) of consecutive floors without a special floor:
- (2, 3) with a total amount of 2 floors.
- (5, 5) with a total amount of 1 floor.
- (7, 9) with a total amount of 3 floors.
Therefore, we return the maximum number which is 3 floors.

Example 2:

Input: bottom = 6, top = 8, special = [7,6,8]
Output: 0
Explanation: Every floor rented is a special floor, so we return 0.

Code

1
2
3