Reunion of 1's
Practice
4.2 (8 votes)
Data structures
Disjoint set
Medium
String manipulation
Problem
88% Success 9477 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string of size n consisting of 0s and/or 1s. You have to perform total k queries and there are two types of queries possible:

  1. "1" (without quotes): Print length of the longest sub-array which consists of all '1'.
  2. "2 X" (without quotes): where X is an integer between 1 to n. In this query, you will change character at the Xth position to '1' (It is possible that the character at i-th position was already '1').

Input Format

  • First line of input contains n and k, where n is the length of the string, k is the number of queries.
  • Next line contains a string of 0's and/or 1's of length n.
  • Each of next k lines contains query of any one type(i.e 1 or 2).

Input Constraints

  • \(1 \le n,k \le 10^5\)
  • \(1 \le X \le n\)
  • String contains only 0s and/or 1s.
  • Each query is of one of the mentioned types.

Output Format

  • For each query of type 1, print in a new line the maximum size of the subarray with all 1's

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:30
10 votes
Tags:
ApprovedData StructuresDisjoint setMedium
Points:30
8 votes
Tags:
AlgorithmsApprovedData StructuresDepth First SearchDisjoint setMediumOpen
Points:30
14 votes
Tags:
Disjoint Data StructuresData StructuresBasics of Disjoint Data Structures