Python3 implementation of the above approach
from collections import defaultdict NEW_LINE MAX = 100005 NEW_LINE def partial_sum ( prefix_sum , arr , n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT prefix_sum [ i ] = ( prefix_sum [ i - 1 ] + arr [ i - 1 ] ) NEW_LINE DEDENT return prefix_sum NEW_LINE DEDENT