Back
Close

Longest Chain of 1 in a Binary String

Statement

 Goal

Given a binary string bin, output the index and the lengthof the longest chain of 1's in bin. If there are multiple longest chains then output only the index that refers to the first occurrences.

To know about what's considered an index in this puzzle, read the info below

- Index refers to groups of 1, not in individual bits. So index = 2, refers to the 2nd group of 1
- Index are counted from 1, not 0
- Single digit is also counted as a group of length 1

Output Meaning:
If output is like
2
4
It means: "The longest chain of 1 in the string is the 2nd chain and it has a length of 4"
Input
Line 1: Length of bin
Line 2: Binary string bin
Output
Line 1: The index of the longest chain of one
Line 2: The length of that chain
Constraints
bin is always a non-empty string and always contains at least one "1"
8 <= length <= 964
Example
Input
8
10111101
Output
2
4

Game modes
Fastest, Shortest

Test cases
Small string Test
Input
8 10111101
Output
2 4

Small string 2 Validator
Input
22 1010101010101010001111
Output
9 4

Single Digits Test
Input
30 101010101011101010101011011011
Output
6 3

Single Digits 2 Validator
Input
45 111000110101001110010101010101111101101010101
Output
11 5

Have digit 0 in front Test
Input
43 0101011110100110101101010111010101111010011
Output
3 4

Have digit 0 in front (2) Validator
Input
100 0000000101111111111111010101000010010101011111001011100010101010010101011101011001010100010101100101
Output
2 13

Only one digit 0 Test
Input
32 01011011110111111011111110111111
Output
5 7

Only one digit 0 (2) Validator
Input
64 011101101110101010110111011111110111110111011101111110111110111
Output
9 7

Only one digit 1 Test
Input
100 00000010000010100000100000101000010000100001001000100010001000101000100001000000100100010101000000
Output
1 1

Only one digit 1 (2) Validator
Input
256 00000101010001000100010000000100000001000000100000010010101010101010101010000010000100100101010101000010100010010000010000100010010001001010101010001010101010001001001001010010100101001010101010101000001000100010001000100010101000100100100001000100100000
Output
1 1

Random Test Test
Input
85 0110101010101011101001010111101010011010101010101000101000010110101111101101001011010
Output
26 5

Random Test (2) Validator
Input
350 00001001010111010101010101011100111010100101011010110101010111101000101110101110101110101001111010010101010101001010101001011011111111111111111111111111110100101010101111111111111111010101001111111111111101001010101000010101010101010101110101001010010100101000101010101111111111011101101011110100110111111101101111111111000000001000000000011001111111
Output
47 28

Random Test (3) Test
Input
964 0101011101010111010101010001010111110110101010110101010101010110100110100100000000011101000000000000011111111111111000000011010010101010101010001111010100101110001010101010111001010111001010100011010101110010010101010101010101000101110010001011000101001010101111101000101010010101010101010011011010111111100000001010101011111100001100110101010111110100101000010100001001010101010101010011111111000000000101000000000000011111111010010101010100010010101010101111100101001010000000010101010101010111110101010000100111101010010111111111111111111111000000000000000011110000000000000000000000001010111111111111111111101010010101010010010100100000000010101011011111101111111000000111101010101010101101010111110101101010100101010111010101010111110100000000110101001010101010111001010100000000001111111111111101000101011101001100000001010101001010101001001010101010101001010101010010101010101001001010000001010101110100101011010101010100001010010101010110100001000100101010
Output
161 21

Random Test (4) Validator
Input
213 100101111101110100100010000011100101000101000100001100001010111111100010000111110110000111010010110010001010001111000100000100010001010100000011001010011001110101000111001101011101101000000010110101011100011000000
Output
17 7

Solution language

Solution

Stub generator input