I got stuck in one algorithm question. Please suggest me some efficient algorithm for the below problem
Question is
Find numbers of subarrays(in range between 0 < R < N) whose sum is divisible by given number.
My approach:
Input: 0 5 3 8 2 1
Sum: 0 0 5 8 16 18 19
Mod 3: 0 0 2 2 1 0 1
No. of ways to chooses 0 , 1 or 2 is NC2
Problem: Is i am have asked to choose between some range i.e from 2 to 5 so array will become:
3 8 2 1
Does I have to recalculate the sum and Mod again or the original MOd array will give me a correct answer
Second Problem: What IF i change one element i.e 8 is change to 11
, How it will be effect
For the above problem I am considering using BIT
dp[4][Max. Element] if mod is 0 update dp[0] if 1 update dp[1] so on How To update if VAlue at index is change