About time complexity of the probelm

If we apply recusrsion with dp for each quaries then for each it takes O(n) time, how to minimize it

hi @pallabpal0024_76613dca723a36c4 u can store for each index pair before hand and answer in O(1) for queries

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.