diff options
Diffstat (limited to 'challenge-325/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-325/sgreen/python/ch-1.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-325/sgreen/python/ch-1.py b/challenge-325/sgreen/python/ch-1.py new file mode 100755 index 0000000000..899fdf8dbf --- /dev/null +++ b/challenge-325/sgreen/python/ch-1.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import sys + + +def consecutive_ones(ints: list) -> int: + """ + Function to find the maximum number of consecutive 1s in a binary array. + :param ints: List of integers (0s and 1s) + :return: Maximum count of consecutive 1s + """ + max_count = 0 + current_count = 0 + + for num in ints: + if num == 1: + current_count += 1 + if current_count > max_count: + max_count = current_count + else: + current_count = 0 + + return max_count + + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = consecutive_ones(array) + print(result) + + +if __name__ == '__main__': + main() |
