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.
defpickingNumbers(a):# constraint-1if(2<=len(a)<=100):passa.sort()# only taking the repeated elementsall_num=[*set(a)]# constrain-2foriinall_num:if(0<i<100):pass# taking all the first numbers of consecutive pairs presentconsecutive_num=[]foriinall_num:ifi+1inall_num:consecutive_num.append(i)# counting the number of consecutive numscount_list=[]foriinconsecutive_num:count_list.append(a.count(i)+a.count(i+1))# counting the number of single unitsforiinall_num:count_list.append(a.count(i))returnmax(count_list)
Cookie support is required to access HackerRank
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 →
My code