fork download
  1. def findLongestRun(runLogs):
  2. max_len = 0
  3. max_proc = 0
  4.  
  5. prev_end = 0 # first process starts at time 0
  6.  
  7. for proc, end_time in runLogs:
  8. run_length = end_time - prev_end
  9. if run_length > max_len:
  10. max_len = run_length
  11. max_proc = proc
  12. prev_end = end_time
  13.  
  14. return chr(max_proc + ord('a'))
  15.  
  16.  
  17. # Example test
  18. # runLogs = [(0, 3), (2, 5), (0, 9), (1, 15)]
  19. # runLogs = [(0,2), (1,3), (0,7)]
  20. runLogs = [(0,1), (0,3), (4,5), (5,6), (4,10)]
  21. print(findLongestRun(runLogs)) # Output: 'b'
  22.  
Success #stdin #stdout 0.07s 14104KB
stdin
Standard input is empty
stdout
e