Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def divide_to_groups(calendar):
- # base-case
- if len(calendar) == 0:
- return 0
- arr = []
- # "a" and "b" are used for sorted,
- # they mark the start and the end
- # of a particular array
- for i in calendar:
- arr.append((i[0], "a"))
- arr.append((i[1], "b"))
- arr = sorted(arr)
- grps = 0
- max_grps = 0
- for i in arr:
- if i[1] == "a":
- grps += 1
- if max_grps < grps:
- max_grps = grps
- else:
- grps -= 1
- return max_grps
- # Neboj se pridat si vlastni testy
- def test_default():
- calendars = [
- [ ],
- [ (1, 2), (3, 3), (500, 800), (50, 56) ],
- [ (1, 2), (5, 8), (1, 3), (1, 1), (3, 6), ]
- ]
- answers = [ 0, 1, 3 ]
- for i in range(len(calendars)):
- result = divide_to_groups(calendars[i])
- if result == answers[i]:
- print("[", i, "] OK.", sep="")
- else:
- print("[", i, "] Not OK. Expected ", answers[i], " but got ", result, ".", sep="")
- if __name__ == '__main__':
- test_default()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement