Traverse original array and compute cumulative sum take remainder of this current cumulative sum and increase count by 1 for this remainder in mod array
$ cumSum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ cumSum += $ arr [ $ i ] ;