Skip to content

Commit 556316e

Browse files
authored
Refactor sum and product calculation logic
Refactor to combine sum and product calculations into a single loop, maintaining O(n) complexity.
1 parent 14db9b9 commit 556316e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def calculate_sum_and_product(input_numbers: List[int]) -> Dict[str, int]:
1313
"product": 30 // 2 * 3 * 5
1414
}
1515
Time Complexity:
16-
There were two loops, one for each operation. Each has complexity O(n)
17-
for both loops, complexity is O(2n)
16+
There were two separated loops, one for each operation. Each had complexity O(n)
17+
The refactor combined them into a single loop reducing the constant factor, maintaining the same Big-O complexity.
1818
Space Complexity:
1919
space is constant O(1)
2020
Optimal time complexity:

0 commit comments

Comments
 (0)