We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# TC - O(nlogn) ; SC - O(1)curr_length,max_length=0,0min_num=float('inf')# Sorting the array in ascending ordera.sort()# Looping through the array and track the difference and minimumforiinrange(len(a)-1):ifa[i+1]-a[i]<2anda[i+1]-min_num<2:curr_min=min(min_num,a[i])ifcurr_min<=min_num:min_num=curr_mincurr_length+=1max_length=max(curr_length,max_length)else:curr_length=0curr_min,min_num=float('inf'),float('inf')returnmax_length+1
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
=== Python Solution ===