function to find the maximum profit by doing jobs in a given time frame args numjobs int number of jobs jobs list a list of tuples of jobid deadline profit returns maxprofit int maximum profit that can be earned by doing jobs in a given time frame examples jobsequencingwithdeadlines4 1 4 20 2 1 10 3 1 40 4 1 30 2 60 jobsequencingwithdeadlines5 1 2 100 2 1 19 3 2 27 4 1 25 5 1 15 2 127 sort the jobs in descending order of profit create a list of size equal to the maximum deadline and initialize it with 1 finding the maximum profit and the count of jobs find a free time slot for this job note that we start from the last possible slot function to find the maximum profit by doing jobs in a given time frame args num_jobs int number of jobs jobs list a list of tuples of job_id deadline profit returns max_profit int maximum profit that can be earned by doing jobs in a given time frame examples job_sequencing_with_deadlines 4 1 4 20 2 1 10 3 1 40 4 1 30 2 60 job_sequencing_with_deadlines 5 1 2 100 2 1 19 3 2 27 4 1 25 5 1 15 2 127 sort the jobs in descending order of profit create a list of size equal to the maximum deadline and initialize it with 1 finding the maximum profit and the count of jobs find a free time slot for this job note that we start from the last possible slot
def job_sequencing_with_deadlines(num_jobs: int, jobs: list) -> list:
    

    
    jobs = sorted(jobs, key=lambda value: value[2], reverse=True)

    
    
    max_deadline = max(jobs, key=lambda value: value[1])[1]
    time_slots = [-1] * max_deadline

    
    count = 0
    max_profit = 0
    for job in jobs:
        
        
        for i in range(job[1] - 1, -1, -1):
            if time_slots[i] == -1:
                time_slots[i] = job[0]
                count += 1
                max_profit += job[2]
                break
    return [count, max_profit]


if __name__ == "__main__":
    import doctest

    doctest.testmod()