• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Dec 16th, 2018 54 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, "a"))
13.         arr.append((i, "b"))
14.     arr = sorted(arr)
15.
16.     grps = 0
17.     max_grps = 0
18.
19.     for i in arr:
20.         if i == "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])