-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook_allocation.py
More file actions
46 lines (38 loc) · 1.16 KB
/
book_allocation.py
File metadata and controls
46 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from math import ceil
from typing import List
class Solution:
def book_allocation(self, arr: List[int], m: int, max_page: int) -> int:
student_count = 1
n = len(arr)
i = 0
print(arr)
while i <= n-2:
if arr[i] + arr[i+1] > max_page:
student_count += 1
i += 1
else:
while arr[i] + arr[i+1] <= max_page:
i += 1
print(f"i inside while {i}")
student_count += 1
# print(f"{arr[i] + arr[i+1] = } | {max_page = } | {student_count = } | {i = }")
return student_count
sol = Solution()
# arr = [25,46,28,49,24]
# m = 4
# max_page = 72
# print(f"{arr = } | {max_page = } | {sol.book_allocation(arr, m, max_page) = }")
#
arr = [25,46,28,49,24]
m = 4
max_page = 49
print(f"{arr = } | {max_page = } | {sol.book_allocation(arr, m, max_page) = }")
#
arr = [25,46,28,49,24]
m = 4
max_page = 100
print(f"{arr = } | {max_page = } | {sol.book_allocation(arr, m, max_page) = }")
arr = [25,46,28,49,24]
m = 4
max_page = 72
print(f"{arr = } | {max_page = } | {sol.book_allocation(arr, m, max_page) = }")