Length of Smallest subarray in range 1 to N with sum greater than a given value | Java implementation of the above implementation ; 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
class GFG { static int countNumber ( int N , int S ) { int countElements = 0 ; int currSum = 0 ; while ( currSum <= S ) { currSum += N ; N -- ; countElements ++ ; } return countElements ; } public static void main ( String [ ] args ) { int N , S ; N = 5 ; S = 11 ; int count = countNumber ( N , S ) ; System . out . println ( count ) ; } }