7 kyu
Ones and Zeroes
345 of 385saudiGuy
Description:
Your task is to implement a function that examines a given string composed of binary digits (0s and 1s). The function should return True
if:
Every consecutive sequence of ones is immediately followed by an equal-length consecutive sequence of zeroes, and the number of ones is equal to the number of zeroes.
A leading zero always results in a
False
outcome.
Here are some examples to illustrate the expected behavior of the function: Examples
- For the input "110011100010," the function should return True because every consecutive sequence of ones (e.g., "11," "111," "1") is followed by an equal-length consecutive sequence of zeroes.
- For the input "101010110," the function should return False because the sequence of ones ("11") is not followed by an equal-length consecutive sequence of zeroes.
- "111100001100" # True
- "111" # False
- "00110100001111 # False, although the number of zeroes and ones is equal,
the consecutive sequence of ones (e.g., "11," "1," "1111") is not followed
by an equal-length consecutive sequence of zeroes.
Notes
- The input string will only contain digits
0
or1
. - The length of the input string (
txt
) will be greater than zero.
Algorithms
Strings
Similar Kata:
Stats:
Created | Sep 20, 2023 |
Published | Sep 20, 2023 |
Warriors Trained | 902 |
Total Skips | 8 |
Total Code Submissions | 1649 |
Total Times Completed | 385 |
Python Completions | 345 |
Rust Completions | 44 |
Haskell Completions | 8 |
Lua Completions | 7 |
Total Stars | 11 |
% of votes with a positive feedback rating | 89% of 87 |
Total "Very Satisfied" Votes | 71 |
Total "Somewhat Satisfied" Votes | 13 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 13 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |