Hi Coders,
I am trying to solve a problem but couldn't come up with a better solution.
Problem Statement
Given an array A of N integers and Q queries where 1 ≤ Ai ≤ 100, 1 ≤ N ≤ 105 & 1 ≤ Q ≤ 105. Each query gives L and R(a subarray of array A). For each query find the minimum X such that AX > AL + X and L + X ≤ R.
I tried solving this problem but couldn't come up with a solution better than Q × N. Any help to improve the complexity would be much appreciated.