diff options
| author | Simon Green <mail@simon.green> | 2025-06-15 23:11:30 +1000 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2025-06-15 23:11:30 +1000 |
| commit | 158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6 (patch) | |
| tree | 76ad90cfc94f4850120bdfd018e6bf01c57609b0 /challenge-325/sgreen/python/ch-1.py | |
| parent | e28477d2418099cfbb1a227133c69ddef6eed741 (diff) | |
| download | perlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.tar.gz perlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.tar.bz2 perlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.zip | |
sgreen solutions to challenge 325
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() |
