Python, textbook solution for textbook problem

  • 0

    That's the textbook schedule problem to maximize number of schedule tasks. The solution is to sort by end_time and be greedy. The only difference is > vs >=

        if not pairs: return 0
        pairs = sorted( [[j, i] for i, j in pairs] )
        next_pair = pairs[0]
        counter = 1
        for pair in pairs[1:]:
            if pair[1] > next_pair[0]:
                next_pair = pair
                counter += 1
        return counter

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.