daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def divide_to_groups(calendar):
  2.     # base-case
  3.     if len(calendar) == 0:
  4.         return 0
  5.  
  6.     arr = []
  7.    
  8.     # "a" and "b" are used for sorted,
  9.     # they mark the start and the end
  10.     # of a particular array
  11.     for i in calendar:        
  12.         arr.append((i[0], "a"))
  13.         arr.append((i[1], "b"))
  14.     arr = sorted(arr)
  15.    
  16.     grps = 0
  17.     max_grps = 0
  18.    
  19.     for i in arr:
  20.         if i[1] == "a":
  21.             grps += 1
  22.             if max_grps < grps:
  23.                 max_grps = grps
  24.         else:
  25.             grps -= 1
  26.    
  27.     return max_grps
  28.  
  29.  
  30. # Neboj se pridat si vlastni testy
  31. def test_default():
  32.     calendars = [
  33.         [ ],
  34.         [ (1, 2), (3, 3), (500, 800), (50, 56) ],
  35.         [ (1, 2), (5, 8), (1, 3), (1, 1), (3, 6), ]
  36.     ]
  37.  
  38.     answers = [ 0, 1, 3 ]
  39.  
  40.     for i in range(len(calendars)):
  41.         result = divide_to_groups(calendars[i])
  42.         if result == answers[i]:
  43.             print("[", i, "] OK.", sep="")
  44.         else:
  45.             print("[", i, "] Not OK. Expected ", answers[i], " but got ", result, ".", sep="")
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     test_default()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top