Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Consecutive Floors Without Special Floors

XPChallenge Points: 20
levelLevel: Medium

Alice has leased every floor from bottom to top, including both. Among these floors, some are marked as special floors—these cannot be used as regular office areas.

You are given an array special, where each value represents a floor that has been marked as special.

Your task is to determine the longest continuous stretch of floors that does not contain any special floor at all.
Return the length of this longest uninterrupted block of normal (non-special) floors.

Example 1:

Input: bottom = 1, top = 10, special = [2, 5, 9]

Output: 3

Explanation:

Non-special ranges are: (3, 4) → length 2 (6, 8) → length 3 (10, 10) → length 1 The longest continuous segment is from 6 to 8, but including floor 10 individually also gives 1. Thus, the maximum non-special floors = 3.

Example 2:

Input: bottom = 15, top = 20, special = [15, 17, 20]

Output: 2

Explanation:

Non-special ranges: (16, 16) → 1 (18, 19) → 2 Maximum length = 2.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result