find kth max and min element in an array

#include <bits/stdc++.h> 
using namespace std;

int main(){
  	const int size = 10;
  	int k = 3; //Can be any number smalled than size
	int array[size] = {5,2,8,34,73,82,1,6,19,29};
	sort(array,array+size);
	int smallestKthElement = array[k-1];	
	int largestKthElement = array[size-k];
}

0
0

                                    
function nthlargest(arra,highest){
			var x = 0,
				y = 0,
				z = 0,
				temp = 0,
				tnum = arra.length, 
				flag = false, 
				result = false; 
   
			while(x &lt; tnum){
				y = x + 1; 
				
				if(y &lt; tnum){
					for(z = y; z &lt; tnum; z++){
						
						if(arra[x] &lt; arra[z]){
							temp = arra[z];
							arra[z] = arra[x];
							arra[x] = temp;
							flag = true; 
						}else{
							continue;
						}	
					}					
				}
				
				if(flag){
					flag = false;
				}else{
					x++; 
					if(x === highest){ 
                      
						result = true;
					}	
				}
				if(result){
					break;
				}
			}

			return (arra[(highest - 1)]);	
		}
		
console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4)); 

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript largest number in array find biggest arrar element in js get largest number in array javascript find the minimum and maximum element in an array kth max min element in array Write a program to find min and max element in an array find kth min max array kth max element in array find the min and max elems of the array find largest among array js find largest number in arrayusing javascript js take largest element from each array find the kth max and min element of an array python find the kth max and min element of an array javascript k largest element arr,n,k javascript k largest element find kth max and min element in an array practice minimum and maximum element in an array find minimum and maximum element in an array find the kth max and min element of an array practice find the maximum and minimum element in an array find maximum and minimum element in an array kth largest element in an array coding ninjs find the kth largest element in an unsorted array javascript find k largest elements in array javascript finding largest number in array javascript get largest no in the array javascript find largest value in array javascript find the largest number from array in javascript find largest index javascript find the largest element in an array javascript js largest number in array largest element in array function find largest index the array javascript kth largest element in an array js solution function that returns the largest number in the Array in javascript how to find largest element in array how to find the largest element in an array kth largest element in an array js see which array is the biggest element javascript find the biggest element in an array javascript get the largest number in array javascript largest javascript array find largest number in array javascript finding the largest number in an array javascript javascript find largest element in array return largest number in array javascript js find largest number in array how to find the largest number in an array javascript how to find largest number in array javascript 13. Find largest element of given array. javascript finding the smallest element in an array Find the largest element of an array in javascript write a javascript function to get largest element from an unsorted array write a javascript function to get nth largest element from an unsorted array 2nd largest number in array javascript kth largest element in an array java kth smallest element array using javascript You are given an array of integers. Find the sum of first K smallest numbers. find the largest number in array javascript find k largest elements in array gfg Find largest element in an unsorted array js kth max and min element in array kth min max element find kth max and min element in an array k largest elements find kth largest element in array Find the &quot;Kth&quot; max and min element of an array kth largest element extract kth from array javascript find fourth largest in unsorted array Kth largest element in an array using heap find k th largest element in js find Kth largest element in array js find the kth largest element javascript This function sorts the elements of the array in descending order and returns the element at the nth index in the sorted array. Sample Input: Array = [43, 56, 23, 89, 88, 90, 99, 652], Positive Integer n = 4,then the return value must be 88. Write a JavaScript function to get nth largest element from an unsorted array. kth largest element in an array javascript find nth largest number in array js maximum element in an array largest element in array python maximum element in array c++ kth largest element in an array gfg kth largest element in an array kth largest element in an array heap
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source