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
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Greedy
  4. Team Formation
  5. Discussions

Team Formation

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • TChalla
    2 years ago+ 0 comments

    Python3 solution

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import heapq
    import sys
    
    for _ in range(int(sys.stdin.readline())):
        t = list(map(int, sys.stdin.readline().split()))
        n = t[0]
        if n == 0:
            print(0)
            continue
        a = sorted(t[1:])
        heap = {}
        for x in a:
            if x not in heap:
                heap[x] = []
            if x - 1 in heap and len(heap[x - 1]) > 0:
                heapq.heappush(heap[x], heapq.heappop(heap[x - 1]) + 1)
            else:
                heapq.heappush(heap[x], 1)
        print(min(heap[x][0] for x in heap if len(heap[x])))        
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy