Length of Smallest subarray in range 1 to N with sum greater than a given value | Function to return the count of minimum elements such that the sum of those elements is > S . ; Initialize currentSum = 0 ; Loop from N to 1 to add the numbers and check the condition . ; Driver code
function countNumber ( N , S ) { let countElements = 0 ; let currSum = 0 ; while ( currSum <= S ) { currSum += N ; N -- ; countElements ++ ; } return countElements ; } let N , S ; N = 5 ; S = 11 ; let count = countNumber ( N , S ) ; document . write ( count + " " ) ;