Alice manages a company and has rented a contiguous range of floors in a skyscraper for office space. She has designated some of these floors as "special floors" for relaxation and recreation only.
Given two integers bottom and top representing the inclusive range of floors Alice has rented, and an integer array special where special[i] represents a floor designated for relaxation, find the maximum number of consecutive regular office floors (floors that are NOT special).
Goal: Find the largest gap between special floors to maximize consecutive workspace.
Example: If Alice rented floors 2-9 and floors [4, 6] are special, the consecutive sequences are [2,3], [5], [7,8,9] with lengths 2, 1, 3 respectively. The answer is 3.
Input & Output
Visualization
Time & Space Complexity
Sorting the special floors array dominates the time complexity
Only using constant extra space for variables (excluding input)
Constraints
- 1 โค bottom โค top โค 109
- 0 โค special.length โค 105
- bottom โค special[i] โค top
- All values in special are unique
- special is given in any order (not necessarily sorted)