Count all subarrays whose sum can be split as difference of squares of two Integers | Function to count all the non - contiguous subarrays whose sum can be split as the difference of the squares ; Loop to iterate over all the possible subsequences of the array ; Finding the sum of all the possible subsequences ; Condition to check whether the number can be split as difference of squares ; Driver code
function Solve ( arr , n ) { let temp = 0 , count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { temp = 0 ; for ( let j = i ; j < n ; j ++ ) { temp += arr [ j ] ; if ( ( temp + 2 ) % 4 != 0 ) count ++ ; } } return count ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; let N = arr . length ; document . write ( Solve ( arr , N ) ) ;