Number of occurrence.

Number of occurrence.

class Solution{

public:

/* if x is present in arr[] then returns the count

of occurrences of x, otherwise returns 0. */

int count(int arr[], int n, int x) {

int lb= lower_bound(arr,arr+n,x)-arr;

int ub=uper_bound(arr,arr+n,x)-arr-1;

return (ub-lb+1) ;

}

};



要查看或添加评论,请登录

Abhishek Singh的更多文章

  • React JS Machine Coding: 25+ Must-Do Questions

    React JS Machine Coding: 25+ Must-Do Questions

    1. Weather App A weather application that fetches and displays real-time weather information based on the user’s…

  • Why One Should Choose Next.js For Frontend Framework ?

    Why One Should Choose Next.js For Frontend Framework ?

    Why Next.js? The world today is hyperconnected! It means if you run a business, then app development isn’t an option…

  • Mongoose

    Mongoose

    In MongoDB, "mongoose" is not a term for a specific action, but rather a popular JavaScript library used for…

  • Tail Recursion

    Tail Recursion

    Tail recursion is defined as a recursive function in which the recursive call is the last statement that is executed by…

  • Visual Studio shortcut keys

    Visual Studio shortcut keys

    # General Shortcuts Ctrl-X or Shift-Delete: Cuts the currently selected item to the clipboard. Without selection it…

  • Pointers, References and Dynamic Memory Allocation.

    Pointers, References and Dynamic Memory Allocation.

    C++ Programming Language Pointers, References and Dynamic Memory Allocation Pointers, References and Dynamic Memory…

  • Search in a Rotated Array.

    Search in a Rotated Array.

    Given a sorted and rotated array A of N distinct elements which is rotated at some point, and given an element key. The…

  • Find First and Last Position of Element in Sorted Array.

    Find First and Last Position of Element in Sorted Array.

    Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target…

  • Search insert position of K in a sorted array.

    Search insert position of K in a sorted array.

    Given a sorted array Arr[](0-index based) consisting of N distinct integers and an integer k, the task is to find the…

  • Ceil The Floor.

    Ceil The Floor.

    Given an unsorted array Arr[] of N integers and an integer X, find floor and ceiling of X in Arr[0..

社区洞察

其他会员也浏览了