fork download
  1. def cacheContents(callLogs):
  2. # Write your code here
  3. cache = []
  4. temp_cache = {}
  5. priority = {}
  6. access = {}
  7.  
  8. for (time, item) in callLogs:
  9. if item not in access:
  10. access[item] = {}
  11. if time not in access[item]:
  12. access[item][time] = 0
  13. access[item][time] += 1
  14.  
  15. for item in access.keys():
  16. lastAccess = None
  17. priority[item] = 0
  18. for time in sorted(access[item].keys()):
  19. if lastAccess == None:
  20. lastAccess = time
  21. priority[item] += (2 * access[item][time])
  22. if time != lastAccess:
  23. priority[item] = max(priority[item] - (time - lastAccess - 1), 0)
  24. if priority[item] > 5:
  25. temp_cache[item] = True
  26. elif priority[item] <= 3:
  27. temp_cache[item] = False
  28. lastAccess = time
  29.  
  30. for item in sorted(temp_cache.keys()):
  31. if temp_cache[item]:
  32. cache.append(item)
  33.  
  34. if len(cache) == 0:
  35. return [-1]
  36. else:
  37. return cache
Success #stdin #stdout 0.02s 9224KB
stdin
Standard input is empty
stdout
Standard output is empty