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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Picking Numbers
  5. Discussions

Picking Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • trinhhai_dmc
    4 months ago+ 1 comment

    Python:

    def pickingNumbers(a):
        s=[]
        c1,c2=0,0
        for i in range(len(a)):
            for j in range(len(a)):
                if a[i] in [a[j],a[j]-1]:
                    c1+=1
                if a[i] in [a[j],a[j]+1]:
                    c2+=1
            s.append(c1)
            s.append(c2)
            c1=0
            c2=0
        return max(s)
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy