- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Consider we have an array with size n. This array is sorted. There is one element whose frequency is greater than or equal to n/2, where n is the number of elements in the array. So if the array is like [3, 4, 5, 5, 5], then the output will be 5.

If we closely observe these type of array, we can easily notice that the number whose frequency is greater than or equal to n/2, will be present at index n/2 also. So the element can be found at position n/2

Source Code: #include<iostream> using namespace std; int higherFreq(int arr[], int n) { return arr[n / 2]; } int main() { int arr[] = { 1, 2, 3, 4 , 4, 4, 4, 4, 4, 5}; int n = sizeof(arr) / sizeof(arr[0]); cout << "The number " << higherFreq(arr, n) << " has occurred more than or equal to "<<n <<"/2 amount of times"; }

The number 4 has occurred more than or equal to 10/2 amount of times

- Related Questions & Answers
- Find Multiples of 2 or 3 or 5 less than or equal to N in C++
- Check which element in a masked array is greater than or equal to a given value in NumPy
- Find N distinct numbers whose bitwise Or is equal to K in C++
- How to find the frequency of values greater than or equal to a certain value in R?
- Find unique pairs such that each element is less than or equal to N in C++
- Count of subarrays whose maximum element is greater than k in C++
- Adding elements of an array until every element becomes greater than or equal to k in C++.
- C++ program to find unique pairs such that each element is less than or equal to N
- First element greater than or equal to X in prefix sum of N numbers using Binary Lifting in C++
- Mask array elements greater than or equal to a given value in Numpy
- Find N distinct numbers whose bitwise Or is equal to K in Python
- Count numbers whose XOR with N is equal to OR with N in C++
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Find all factorial numbers less than or equal to n in C++
- Find the number of elements greater than k in a sorted array using C++

Advertisements