text: Count the subarray with sum strictly greater than the sum of remaining elements | javascript implementation of the above approach ; Calculating total sum of given array ; For loop for beginning povar of a subarray ; initialise subarray_sum to 0 ; For loop for calculating subarray_sum and remaining_sum ; Calculating subarray_sum and corresponding remaining_sum ; Checking for the condition when subarray sum is strictly greater than the remaining sum of the array element ; Driver code
code: function Count_subarray ( arr , n ) { var total_sum = 0 , subarray_sum , remaining_sum , count = 0 ; for ( i = 0 ; i < n ; i ++ ) { total_sum += arr [ i ] ; } for ( i = 0 ; i < n ; i ++ ) { subarray_sum = 0 ; for ( j = i ; j < n ; j ++ ) { subarray_sum += arr [ j ] ; remaining_sum = total_sum - subarray_sum ; if ( subarray_sum > remaining_sum ) { count += 1 ; } } } return count ; } var arr = [ 10 , 9 , 12 , 6 ] ; var n = arr . length ; document . write ( Count_subarray ( arr , n ) ) ;