Company: Google_8nov
Difficulty: medium
Binary String Queries Problem Description You are given a string S of length N consisting of only '0' and '1'. You are given Q queries of two different types: Type 1: You are given a position D and integer X. If X=1 change the character at D to '0'. If X=0 change the character at D to '1'. Type 2: You are given 2 position L and R. Let A be the substring of S containing all the characters from index L to R. Find the length of the longest substring of A which both the starting and ending character as '1'. Task Determine the answer for each type 2 query in the given order. 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, 3], [2, 1], [1, 5, 0], [2, 4], [2, 5]] Approach Initially, S = "01011" In the 1 st query, A = "10". Here