if I get a valid subsegment from index l to r then it will also be sure that all subsequent between l to r is also valid.
so I make a dp array where dp[i] stores the starting index of valid subsegment till index i.
And then perform query.
I am unable to figure out what’s wrong with this approach or I miss something.
please help me to figure it out.