• + 1 comment

    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.

    def getmaxlenarr(value, a):
        low = a.count(value - 1)
        high = a.count(value + 1)
        return max(a.count(value) + low, a.count(value) + high)
    
    def pickingNumbers(a):
        # Write your code here
        unique_a = []
        for value in a:
            if value not in unique_a:
                unique_a.append(value)
        
        maxlen = 2
        for value in unique_a:
            l = getmaxlenarr(value, a)
            if l > maxlen:
                maxlen = l
                
        return maxlen