Company: Google_IITR
Difficulty: medium
Trim zeroes Problem Description You are given a string S of length N made up only of the characters '0' and '1'. You must handle Q queries, each of one of two kinds: type 1 with position = D and integer X If X = 1 , set the character at D to '1'. If X = 0 , set the character at D to '0'. type 2 with position = l and position = r Let A denote the substring of S spanning index l through r . Report the length of the longest substring of A whose first and last characters are both '1'. Task Work out the answer to every type 2 query, in the order given. Notes 1-based indexing is followed. Queries are dependent and processed in the given order. A substring is a contiguous sequence of characters within a string. For example, the substrings of the string "010" are "0", "1", "0", "01", "10" and "010". Examples Example 1: Assumptions: N = 5 S = "01011" Q = 5 Query = [[2, 2, 3], [2, 1, 5], [1, 5, 0], [2, 4, 4], [2, 1, 5]] Approach: Initially, S = 01011 For the 1 st query, A = "10" . The longest su