2274. Maximum Consecutive Floors Without Special Floors

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int maxConsecutive(int bottom, int top, vector<int>& special) {
sort(special.begin(), special.end());
int ret = 0;
special.insert(special.begin(), bottom-1);
special.push_back(top+1);
int n =special.size() ;
for(int i=1;i<n;++i) ret = max(ret, special[i]-special[i-1]-1);
return ret;
}
};

analysis

  • time complexity O(mligm) m is the legth of vector<int>& special
  • sparse complexity O(1)