Mid/SeniorArraySorting

Maximum Consecutive Floors Without Special Floors

Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.

You are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given the integer array special, where special[i] denotes a special floor that Alice has designated for relaxation.

Return the maximum number of consecutive floors without a special floor.

Example 1
Inputbottom = 2, top = 9, special = [4,6]
Output3
The ranges of consecutive floors without a special floor are (2, 3), (5, 5), and (7, 9), so the maximum length is 3.
Example 2
Inputbottom = 6, top = 8, special = [7,6,8]
Output0
Every rented floor is a special floor, so the maximum number of consecutive floors without a special floor is 0.

Constraints

  • 1 <= special.length <= 10^5
  • 1 <= bottom <= special[i] <= top <= 10^9
  • All the values of special are unique.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate