Given an array of N integers. The task is to find the average of the numbers after removing k largest elements and k smallest element from the array i.e. calculate the average value of the remaining N – 2K elements.
Input: arr = [1, 2, 4, 4, 5, 6], K = 2 Output: 4 Remove 2 smallest elemnts i.e. 1 and 2 Remove 2 largest elements i.e. 5 and 6 Remaining elements are 4, 4. So average of 4, 4 is 4. Input: arr = [1, 2, 3], K = 3 Output: 0
- If no. of elements to be removed is greater than no. of elements present in the array, then ans = 0.
- Else, Sort all the elements of the array. Then, calculate average of elements from Kth index to n-k-1th index.
Below is the implementation of the above approach:
- k largest(or smallest) elements in an array | added Min Heap method
- Check if the array has an element which is equal to sum of all the remaining elements
- Check if the array has an element which is equal to product of remaining elements
- Maximum distinct elements after removing k elements
- Count occurrences of the average of array elements with a given number
- Find the smallest and second smallest elements in an array
- Smallest greater elements in whole array
- Find the largest three elements in an array
- k-th smallest absolute difference of two elements in an array
- Element equal to the sum of all the remaining elements
- Third largest element in an array of distinct elements
- Largest sub-array whose all elements are perfect squares
- Smallest number that never becomes negative when processed against array elements
- Print n smallest elements from given array in their original order
- Smallest perfect square divisible by all elements of an array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.