Longest `subsequence` of balanced parentheses
I am trying to solve a variant of a problem I asked earlier: Given a string of parentheses (length <= 1,000,000) and a list of range queries, find the longest subsequence of balanced parentheses within each of the ranges for each of the <= 100,000 queries I found this other SO question that is similar but only has an O(N^3) algorithm. I believe that a DP solution of the form dp[i, j] = longest balanced subsequence in [i .. j] should work because once computed, this would enable to to answer all of the range queries just by querying the DP table. However, even an O(N^2) solution to this problem