Signaling

4

14 votes
Basics of Greedy Algorithms, Greedy Algorithms, Algorithms
Problem

You are given a binary string  S of length  N. Where a character at ith position signifies the signal level of an antenna at ith second.

0 represents low signal and 1 represents high signal.

What is the maximum consecutive time(in seconds) for which the signal was high?

Function Description

Complete the function solve provided in the editor. This function takes the following one parameter and returns the required answer:

N: the size of the binary string.

S: the binary string.

Input Format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

The first line contains T denoting the number of test cases. T also specifies the number of times you have to run the solve function on a different set of inputs.
For each test case:

  • The first line contains the integer N.
  • The second line contains the binary string S of length N

Output Format
For each test case, print the answer in a new line. 

Constraints

1T10
1N105

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Sample Input
1
7
1100111
Sample Output
3
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Signal was high during last 3 second for the longest consecutive time. Thus the answer is 3.

Editor Image

?