- Related Questions & Answers
- Find prime number K in an array such that (A[i] % K) is maximum in C++
- Find smallest number K such that K % p = 0 and q % K = 0 in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Find maximum value of x such that n! % (k^x) = 0 in C++
- Place k elements such that minimum distance is maximized in C++
- Pick maximum sum M elements such that contiguous repetitions do not exceed K in C++
- Print direction of moves such that you stay within the [-k, +k] boundary in C++
- Shortest Subarray with Sum at Least K in C++
- Maximum subarray size, such that all subarrays of that size have sum less than k in C++
- Longest Substring with At Least K Repeating Characters in C++
- Convert a number of length N such that it contains any one digit at least 'K' times in C++
- Print all nodes that are at distance k from a leaf node in C++
- Maximum subarray sum by flipping signs of at most K array elements in C++
- Print N lines of numbers such that every pair among numbers has a GCD K
- Find all pairs (a, b) in an array such that a % b = k in C++

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

In this tutorial, we will be discussing a program to find maximum value K such that array has at-least K elements that are >= K.

For this we will be provided with an array containing positive values. Our task is to find the value of K such that the array contains atleast K values greater than or equal to K.

#include <iostream> using namespace std; //calculating maximum value of K int findMaximumNum(unsigned int arr[], int n) { for (int i = n; i >= 1; i--) { int count = 0; for (int j=0; j<n; j++) if (i <= arr[j]) count++; if (count >= i) return i; } return 1; } int main() { unsigned int arr[] = {1, 2, 3, 8, 10 }; int n = sizeof(arr) / sizeof(arr[0]); cout << findMaximumNum(arr, n); return 0; }

3

Advertisements