[InterviewBit] Maximum Consecutive Gap

Maximum Consecutive Gap

  • Time :
  • Space :
1
2
3
4
5
6
7
8
int Solution::maximumGap(const vector<int> &A) {
vector<int> AA;
for(auto& a : A) AA.push_back(a);
sort(begin(AA), end(AA));
int res = 0;
for(int i = 0; i < AA.size()-1; i++) res = max(res, AA[i+1] - AA[i]);
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/20/PS/interviewbit/maximum-consecutive-gap/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.