Compute the product while traversing for subarrays
for i in range ( n ) : NEW_LINE INDENT product = 1 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT product *= arr [ j ] ; NEW_LINE res = res * product NEW_LINE DEDENT DEDENT