InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Smaller or equal elements

Problem Description

Given an sorted array A of size N. Find number of elements which are less than or equal to B.

NOTE: Expected Time Complexity O(log N)



Problem Constraints

1 <= N <= 106

1 <= A[i], B <= 109



Input Format

First agument is an integer array A of size N.

Second argument is an integer B.



Output Format

Return an integer denoting the number of elements which are less than or equal to B.



Example Input

Input 1:

 A = [1, 3, 4, 4, 6]
 B = 4

Input 2:

 A = [1, 2, 5, 5]
 B = 3



Example Output

Output 1:

 4

Output 2:

 2



Example Explanation

Explanation 1:

 Elements (1, 3, 4, 4) are less than or equal to 4.

Explanation 2:

 Elements (1, 2) are less than or equal to 3.



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Smaller or equal elements on Interview Code Editor
Sign Up
to access hints and editorial solutions for Smaller or equal elements

Discussion


Loading...
Click here to start solving coding interview questions