• + 1 comment

    The question definetely implies it wants you to solve for a contiguous subarray, but the test cases say otherwise. Here's my accepted submission which checks for the case where numbers are all equal/one-above or equal/one-below.

    def pickingNumbers(a): numbers = set(a) max_counter = 0 for n in numbers: counter_plus = 0 counter_minus = 0 for i in a: if i-n == 1 or i-n ==0: counter_plus += 1 if n-i == 1 or n-i ==0: counter_minus += 1 max_counter = max(counter_plus, counter_minus, max_counter) return max_counter acft calculator