Picking Numbers

  • + 0 comments

    Here is my python solution, the question is kind of confusing though.


    def pickingNumbers(a):
        # Write your code here
        a.sort()
        result = [[a[0]]]
        last_index = 1
        for item in result:
            for index in range(last_index, len(a)):
                last_index += 1
                if (abs(min(item) - a[index]) <= 1):
                    item.append(a[index])
                else:
                    result.append([a[index]])
                    break
        return len(sorted(result, key=lambda x: len(x))[-1])