Finished
11def largest_product(series: str, size: int) -> int:
2 pass
2 # Edge Case: negative span value
3 if size < 0:
4 raise ValueError("span must not be negative")
5
6 # Edge Case: span length exceeds input length
7 if size > len(series):
8 raise ValueError("span must not exceed string length")
9
10 # Edge Case: empty input string with zero span
11 if size == 0:
12 return 1
13
14 # Edge Case: non-digit characters in input
15 if not series.isdigit():
16 raise ValueError("digits input must only contain digits")
17
18 max_product = 0
19 for i in range(len(series) - size + 1):
20 substring = series[i:i+size]
21 product = 1
22 for digit in substring:
23 product *= int(digit)
24 if product > max_product:
25 max_product = product
26
27 return max_product
28
29# Handled Edge Cases: negative span value, span length exceeds input length, empty input string with zero span, non-digit characters in input
Test NameStatus
test_can_find_the_largest_product_of_2
Pass
test_can_find_the_largest_product_of_2_with_numbers_in_order
Pass
test_can_find_the_largest_product_of_3
Pass
test_can_find_the_largest_product_of_3_with_numbers_in_order
Pass
test_can_find_the_largest_product_of_5_with_numbers_in_order
Pass
test_can_get_the_largest_product_of_a_big_number
Pass
test_euler_big_number
Pass
test_finds_the_largest_product_if_span_equals_length
Pass
test_rejects_empty_string_and_nonzero_span
Pass
test_rejects_invalid_character_in_digits
Pass
test_rejects_negative_span
Pass
test_rejects_span_longer_than_string_length
Pass
test_reports_zero_if_all_spans_include_zero
Pass
test_reports_zero_if_the_only_digits_are_zero
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.