Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it.
(n: str = N)
| 74 | |
| 75 | |
| 76 | def solution(n: str = N) -> int: |
| 77 | """ |
| 78 | Find the thirteen adjacent digits in the 1000-digit number n that have |
| 79 | the greatest product and returns it. |
| 80 | """ |
| 81 | |
| 82 | largest_product = -sys.maxsize - 1 |
| 83 | substr = n[:13] |
| 84 | cur_index = 13 |
| 85 | while cur_index < len(n) - 13: |
| 86 | if int(n[cur_index]) >= int(substr[0]): |
| 87 | substr = substr[1:] + n[cur_index] |
| 88 | cur_index += 1 |
| 89 | else: |
| 90 | largest_product = max(largest_product, str_eval(substr)) |
| 91 | substr = n[cur_index : cur_index + 13] |
| 92 | cur_index += 13 |
| 93 | return largest_product |
| 94 | |
| 95 | |
| 96 | if __name__ == "__main__": |