Last Updated: 30 Aug, 2021

Cherry Biscuit

Easy
Asked in company
Flipkart limited

Problem statement

Ninja loves cherry biscuits. He brings a packet of biscuits from a shop which contains ‘N’ biscuits. The number of cherries present in each biscuit is given in an array ‘A’.

Ninja likes a biscuit only if the number of cherries in that biscuit is strictly greater than ‘K’.

Can you tell the number of biscuits Ninja likes?

Example :
N = 3 
K = 5
A = [ 1, 6, 7 ]

Biscuit 1 : Since there is only 1 cherry in this biscuit which is not greater than ‘K’, Ninja doesn’t like this biscuit.

Biscuit 2 : Since there are 6 cherries in this biscuit which is greater than ‘K’, Ninja likes this biscuit.

Biscuit 3 : Since there are 7 cherries in this biscuit which is greater than ‘K’, Ninja likes this biscuit.

Hence, Ninja likes 2 biscuits from this packet.
Input Format :
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.

The first line of each test case contains integer ‘N’.

The second line of each test case contains integer ‘K’.

The second line contains ‘N’ space separated integers denoting the elements of array ‘A’.
Output format :
For each test case, print one integer denoting the number of biscuits Ninja likes.

Print the output of each test case in a new line.
Note :
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= N <= 10^4
0 <= K <= 10^9
0 <= A[i] <= 10^9

Time Limit: 1 sec

Approaches

01 Approach

 

Approach : 

 

  • We traverse the array and check each value :
    • If it is greater than ‘K’, we increment our answer.
    • Else, we continue.


 

Algorithm : 

 

  • Initialise a variable ‘ans’ as 0.
  • Run a for loop over the length of array ‘A’ from ‘i’ = 1 to ‘i’ = ’N’.
    • If ‘A[i]’ > ‘K’ , we increment the ‘ans’ by 1.
    • Else, we continue.
  • Return the ‘ans’ as final result.