Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@thealchemist627 | 456 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@codeantik | 448 |

@SherlockHolmes3 | 447 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@neverevergiveup | 393 |

Complete Leaderboard |

Given a sorted array **Arr** of size **N** and a value **X**, find the number of array elements less than or equal to **X** and elements more than or equal to **X**.

**Example 1:**

**Input:
**N = 7, X = 0
Arr[] = {1, 2, 8, 10, 11, 12, 19}
**Output: **0 7
**Explanation:** There are no elements less or
equal to 0 and 7 elements greater or equal
to 0.

**Example 2:**

**Input:
**N = 7, X = 5
Arr[] = {1, 2, 8, 10, 11, 12, 19}
**Output:** 2 5
**Explanation:** There are 2 elements less or
equal to 5 and 5 elements greater or equal
to 5.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getMoreAndLess****()** which takes the array of integers **arr,** **n **and** x**** **as parameters and returns an array of size 2. pair denoting the answer. The first value is number of elements less than or equal to **x **and the second value is number of** **elements more than or equal to **x.**

**Expected Time Complexity:** O(logN)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ N ≤ 10^{5}

0 ≤ X ≤ 10^{6}

1 ≤ Arr[i] ≤ 10^{6}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Smaller and Larger

...