Can anyone suggest a good algo for this question
A problem to use simple divisibility rules.
Take the cumulative sum of the array. For a particular index, subtract that number and then check if the remaining sum is divisible by 3 or not.
Take the previous value a[i-1] and the last value a[n] for checking the divisibility by 2 and 5.
For queries: For a particular index, store how many lucky indices are there before that index. Then for given L and R the answer would be answer[R] - answer[L-1] .
Sir the code is showing TLE error in most of the test cases can you check the code.
@mukuuu
You need to take cumulative sum
You’re running a loop instead
Shift to cumulative sum approach
For reference https://www.geeksforgeeks.org/cpp-program-for-range-sum-queries-without-updates/
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.