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.
The following code gives an easy approach to the solution.
I was struggling understanding the other solutions. But, I built this solution by myself. I hope this will help you for easy understanding and approach.
defgetmaxlenarr(value,a):low=a.count(value-1)high=a.count(value+1)returnmax(a.count(value)+low,a.count(value)+high)defpickingNumbers(a):# Write your code hereunique_a=[]forvalueina:ifvaluenotinunique_a:unique_a.append(value)maxlen=2forvalueinunique_a:l=getmaxlenarr(value,a)ifl>maxlen:maxlen=lreturnmaxlen
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 →
The following code gives an easy approach to the solution. I was struggling understanding the other solutions. But, I built this solution by myself. I hope this will help you for easy understanding and approach.