Team Formation

  • + 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])))