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 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
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 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