MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / mincost_tickets

Function mincost_tickets

dynamic_programming/minimum_tickets_cost.py:28–123  ·  view source on GitHub ↗

>>> mincost_tickets([1, 4, 6, 7, 8, 20], [2, 7, 15]) 11 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 7, 15]) 17 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 90, 150]) 24 >>> mincost_tickets([2], [2, 90, 150]) 2 >>> min

(days: list[int], costs: list[int])

Source from the content-addressed store, hash-verified

26
27
28def mincost_tickets(days: list[int], costs: list[int]) -> int:
29 """
30 >>> mincost_tickets([1, 4, 6, 7, 8, 20], [2, 7, 15])
31 11
32
33 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 7, 15])
34 17
35
36 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 90, 150])
37 24
38
39 >>> mincost_tickets([2], [2, 90, 150])
40 2
41
42 >>> mincost_tickets([], [2, 90, 150])
43 0
44
45 >>> mincost_tickets('hello', [2, 90, 150])
46 Traceback (most recent call last):
47 ...
48 ValueError: The parameter days should be a list of integers
49
50 >>> mincost_tickets([], 'world')
51 Traceback (most recent call last):
52 ...
53 ValueError: The parameter costs should be a list of three integers
54
55 >>> mincost_tickets([0.25, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 90, 150])
56 Traceback (most recent call last):
57 ...
58 ValueError: The parameter days should be a list of integers
59
60 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 0.9, 150])
61 Traceback (most recent call last):
62 ...
63 ValueError: The parameter costs should be a list of three integers
64
65 >>> mincost_tickets([-1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 90, 150])
66 Traceback (most recent call last):
67 ...
68 ValueError: All days elements should be greater than 0
69
70 >>> mincost_tickets([2, 367], [2, 90, 150])
71 Traceback (most recent call last):
72 ...
73 ValueError: All days elements should be less than 366
74
75 >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [])
76 Traceback (most recent call last):
77 ...
78 ValueError: The parameter costs should be a list of three integers
79
80 >>> mincost_tickets([], [])
81 Traceback (most recent call last):
82 ...
83 ValueError: The parameter costs should be a list of three integers
84
85 >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [1, 2, 3, 4])

Callers

nothing calls this directly

Calls 1

dynamic_programmingFunction · 0.85

Tested by

no test coverage detected