You are viewing a single comment's thread. Return to all comments →
2 versions of Python code solving in O(n) time:
from collections import Counter def pickingNumbers(a): c = Counter(a) return max( c[n]+c.get(n-1,0) for n in c )
version 2:
def pickingNumbers1(a): a = sorted(a) m=i=0 while i<len(a): s=i while i<len(a) and abs(a[i]-a[s])<=1: i+=1 m = i-s if i-s>m else m return m
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
2 versions of Python code solving in O(n) time:
version 2: