Absolute difference between floor of Array sum divided by X and floor sum of every Array element when divided by X | Function to find absolute difference between the two sum values ; Variable to store total sum ; Variable to store sum of A [ i ] / X ; Traverse the array ; Update totalSum ; Update perElementSum ; Floor of total sum divided by X ; Return the absolute difference ; Input ; Size of Array ; Function call to find absolute difference between the two sum values
function floorDifference ( A , N , X ) { let totalSum = 0 ; let perElementSum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { totalSum += A [ i ] ; perElementSum += Math . floor ( A [ i ] / X ) ; } let totalFloorSum = Math . floor ( totalSum / X ) ; return Math . abs ( totalFloorSum - perElementSum ) ; } let A = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let X = 4 ; let N = A . length ; document . write ( floorDifference ( A , N , X ) ) ;