Skip to content

Commit c2402a1

Browse files
committed
[main] Added python problem
1 parent edda6bb commit c2402a1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
6+
total: float = 0
7+
running_decrease: int = 0
8+
brackets_clone = [x[:] for x in brackets]
9+
for i, each_bracket in enumerate(brackets):
10+
if running_decrease != 0:
11+
each_bracket[0] -= running_decrease
12+
left_ = each_bracket[0] - income
13+
if left_ <= 0:
14+
# income is > each_bracket[0]
15+
total += each_bracket[0] * (each_bracket[1] / 100)
16+
income -= each_bracket[0]
17+
else:
18+
total += income * (each_bracket[1] / 100)
19+
income = 0
20+
running_decrease = brackets_clone[i][0]
21+
return total
22+
23+
24+
if __name__ == "__main__":
25+
a = [[3, 50], [7, 10], [12, 25]]
26+
sol = Solution()
27+
print(sol.calculateTax(a, 10))
28+
b = [[1, 0], [4, 25], [5, 50]]
29+
sol = Solution()
30+
print(sol.calculateTax(b, 2))

0 commit comments

Comments
 (0)