For this kind of range query sums ,which apprach to use mo’s algorithm or segment trees or anything else.
Hackerank mathematics
This problem can be solved using map, what you have to do is that
There are 3 conditions that needs to be checked in the following order.
- If A[a] is odd, irrespective of what A[b] is, the answer is
odd. - If a == b, then the answer is
even( as the condition #1 is executed in case the number is odd). - If A[a+1] == 0, then the answer is
oddas x0 = 1.
If none of the above conditions match, return even .
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.