Add temp to the sum
final_ans += temp ; } final_ans += ( N + 1 ) ; return final_ans ; } function lowerBound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; }