Maximum Consecutive Floors Without Special Floors LeetCode solution in Java

1
class Solution {
2
public int maxConsecutive(int bottom, int top, int[] special) {
3
int max = Integer.MIN_VALUE;
4

5
Arrays.sort(special);
6

7
// from bottom to the first special floor
8
max = Math.max(max, special[0] - bottom);
9

10
// middle floors
11
for (int i = 1; i < special.length; i++) {
12
max = Math.max(max, special[i] - special[i - 1] - 1);
13
}
14

15
// from last special floor to the top
16
max = Math.max(max, top - special[special.length - 1]);
17

18
return max;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0