Signaling
Practice
4 (14 votes)
Basics of greedy algorithms
Greedy algorithms
Algorithms
Problem
73% Success 1963 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a binary string  \(S\) of length  \(N\). Where a character at \(i^{th}\) position signifies the signal level of an antenna at \(i^{th}\) 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

\(1 \leq T \leq 10\)
\(1 \leq N \leq 10^{5}\)

Code snippets (also called starter code/boilerplate code)

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

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
4 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:10
41 votes
Tags:
Ad-HocAlgorithmsCoprimeEasyGreedy Algorithms
Points:10
2 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms