If you have asked for an array where you need to add sum from one position to another position and you must do the work in O(N) time. Then what should you do? Then you need to start the position where you started counting & set the given value on that position. The next work is to add the (final+1) position and subtract the value. Example: Add 10 on (1 to 2) position Add 20 on (2 to 3) position Add 25 on (2 to 5) position Addition point set (10 on 1st position:20 on 2nd position:25 on 2nd position) Subtraction point set (10 on 3rd position:20 on 4th position:25 on 6th position) Array Array [1] Array [2] Array [3] Array [4] Array [5] Extra After adding 10 10 -10 After adding 20 20 -20 After adding 25 ...
I am Tanvir Ahmmad from Bangladesh. Working as a competitive programmer. It will be very pleasure to help you. Happy coding...