
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Maximum possible middle element of the array after deleting exactly k elements in C++
In this tutorial, we will be discussing a program to find maximum possible middle element of the array after deleting exactly k elements
For this we will be provided with an array of size N and an integer K. Our task is to reduce K elements from the array such that the middle element of the resulting array is maximum.
Example
#include <bits/stdc++.h> using namespace std; //calculating maximum value of middle element int maximum_middle_value(int n, int k, int arr[]) { int ans = -1; int low = (n + 1 - k) / 2; int high = (n + 1 - k) / 2 + k; for (int i = low; i <= high; i++) { ans = max(ans, arr[i - 1]); } return ans; } int main() { int n = 5, k = 2; int arr[] = { 9, 5, 3, 7, 10 }; cout << maximum_middle_value(n, k, arr) << endl; n = 9; k = 3; int arr1[] = { 2, 4, 3, 9, 5, 8, 7, 6, 10 }; cout << maximum_middle_value(n, k, arr1) << endl; return 0; }
Output
7 9
- Related Articles
- Find all possible substrings after deleting k characters in Python
- Maximum array sum that can be obtained after exactly k changes in C++
- Find the k smallest numbers after deleting given elements in C++
- Find the k largest numbers after deleting the given elements in C++
- Maximize the size of array by deleting exactly k sub-arrays to make array prime in C++
- Program to find minimum amplitude after deleting K elements in Python
- Program to find maximum difference of adjacent values after deleting k numbers in python
- Find last element after deleting every second element in array of n integers in C++
- Python – K middle elements
- Build Array Where You Can Find The Maximum Exactly K Comparisons in C++
- Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++
- Program to find minimum possible maximum value after k operations in python
- C++ Program to Generate All Possible Subsets with Exactly k Elements in Each Subset
- Maximum Possible Product in Array after performing given Operations in C++
- Find the largest after deleting the given elements in C++

Advertisements