Find Sum of all unique sub | function for finding grandSum ; Go through all subarrays , compute sums and count occurrences of sums . ; Print all those Sums that appear once . ; Driver code
def findSubarraySum ( arr , n ) : NEW_LINE INDENT res = 0 NEW_LINE m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT Sum = 0 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT Sum += arr [ j ] NEW_LINE m [ Sum ] = m . get ( Sum , 0 ) + 1 NEW_LINE DEDENT DEDENT for x in m : NEW_LINE INDENT if m [ x ] == 1 : NEW_LINE INDENT res += x NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT arr = [ 3 , 2 , 3 , 1 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findSubarraySum ( arr , n ) ) NEW_LINE