1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Optimized solution for the problem to find employee with most

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    Given StartTime and endTime for N employees, A employee can form a team if his working hour overlaps with other employees (both startTime and endTime inclusive). Find the maximum team size. example: startTime = [2,5,6,8] endTime = [5,6,10,9] answer is 3. emp1 works from 2-5 emp2 works from 5-6 emp3 works from 6-10 emp4 works from 8-9

    So, emp1 can overlap only with emp2 ie at 5th hour, so max team size for emp1 is 2 emp2 can overlap with emp1 and emp3 ie at 5th hour with emp1 and 6th hour with emp3, so max team size is 3 emp3 also 3 emp4 - 2 So ans is 3.

    I have a working solution but it is not optimized and all test cases are not passing(not failing but timeout). whatever solution you try to bring using AI, verify that output is 3 for my test cases. Most AI just use sweep line and give answer as 4.enter image description here

    startTime = [2,5,6,8]
    endTime = [5,6,10,9]
    n = len(startTime)
    max_time = 0
    for i in range(n):
    temp = 0
    for j in range(n):
    if i == j:
    continue
    if ((startTime <= startTime[j] <= endTime) or (startTime <= endTime[j] <= endTime)):
    temp+=1
    max_time = max(max_time, temp)
    print(max_time+1)```

    Continue reading...

Compartilhe esta Página