Company: Zeta_4August
Difficulty: medium
Debugging - Finding subsequence Problem Description A buggy implementation of the problem below has been provided to you inside findSubsequenceFunction , but as written it fails some of the test cases. Your job is to locate every bug in that code and correct it so that it passes all the test cases. You're given: N : An integer A : An array of integers where every element is either 1 or -1. Each query supplies two integers, L and R . For that query you must find the greatest possible length of a subsequence taken from the subarray A[L...R] that obeys these rules: Writing the chosen subsequence of length K as b 1 , b 2 , ..., b K : Every prefix sum of this subsequence must be non-negative. The total sum across the whole subsequence must equal 0. When no subsequence meets both rules, the answer for that query is 0. Task: You must answer Q independent queries this way, reporting the longest valid subsequence length for each one. Notes: Indexing is 1-based throughout. A subsequence here mea