Weak test cases O(max(A[i])) solution gets accepted


#1
int Solution::longestConsecutive(const vector<int> &A) {
if(!A.size())
    return 0;
unordered_map<int, bool> m={};
int i, n=A.size(), cnt=0, mx=INT_MIN;
for(i=0; i<n; i++)
    m[A[i]]=1;
int l=*min_element(A.begin(), A.end()), h=*max_element(A.begin(), A.end());
while(l<=h){
    cnt=0;
    if(m.count(l)){
        while(m.count(l)){
            l++;
            cnt++;
        }
        mx=max(mx, cnt);
    }
    else 
        l++;
}
return mx;

}