Ctrl K

Longest Run of Office Floors

Medium
A company rents every floor of a building from low to high inclusive. Some of these floors are set aside as lounges; their numbers are listed in the array lounges. Every other rented floor is an office floor. Return the largest number of consecutive office floors with no lounge between them. If there are no office floors, return 0.
Example 1
low=10, high=20, lounges=[13, 14, 19] → 4

Office floors come in runs 10–12 (3 floors), 15–18 (4 floors) and 20 (1 floor). The longest run has 4 floors.

Example 2
low=4, high=5, lounges=[5, 4] → 0

Both floors are lounges, so there are no office floors at all.

Example 3
low=1, high=100, lounges=[1] → 99

The only lounge is on floor 1, so floors 2–100 form one run of 99 floors.

Constraints
  • 1 ≤ lounges.length ≤ 10⁵
  • 1 ≤ low ≤ lounges[i] ≤ high ≤ 10⁹
  • all numbers in lounges are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsZero-Sum Triples MediumTriple Sum Nearest the Target MediumFour Numbers to a Target MediumDistinct Orderings With Repeats MediumAnagram Buckets Medium
loading Python…
Input
low=10, high=20, lounges=[13, 14, 19]
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.