Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think of dynamic programming.
The definition of <code>dp</code> is a little unusual. Try to think more.
Let <code>dp[l][r]</code> be the maximum number of queries we can process if we want <code>a[l], a[l + 1], ..., a[r - 1]</code> not to be removed after processing <code>dp[l][r]</code> queries.
So <code>dp[0][n] = 0</code> since we can not remove anything.
The answer would be <code>max(dp[i][i])</code>.