Sort by

recency

|

2580 Discussions

|

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-picking-numbers-problem-solution.html

  • + 0 comments

    There is a problem with the first sentence of the problem description: a subarray is a contiguous slice of the parent array. However the actual test cases allow using any subset of the input.

  • + 0 comments

    def pickingNumbers(a): se=list(set(a)) maxi=-99 for i in se: ma=0 ma=a.count(i)+max(a.count(i-1),a.count(i+1)) maxi=max(ma,maxi) return maxi play lucky 88

  • + 0 comments

    One explicite loop only.

    def pickingNumbers(a): a.sort()

    cntmax = 0
    
    for el in a[:] :
        cnt0 = a.count(el)
        cnt1 = a.count(el+1)
        cntmax = max(cntmax, cnt0+cnt1)
        a = a[cnt0:]
    return cntmax
    
  • + 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