Kth Largest Element in an Array
Medium Problems DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Finding Kth Largest and Smallest Element in an Unsorted Array, Arrays, Sorting, Heap/Priority Queue, Quickselect Algorithm, Time Complexity, Space Complexity, space complexity, sorting algorithms, heap, array partitioning, quickselect algorithm, time complexity analysis, Heap (Priority Queue), Kth Largest/Smallest Element (Quickselect).
Problem Statement Given an unsorted array of integers, find both the kth largest and kth smallest elements in the array. Input An array arr of n distinct integers (1 ≤ n ≤ 10^5) An integer k where 1 ≤ k ≤ n Output A tuple/list containing two integers in the format (kth largest, kth smallest) Examples Constraints Array elements are distinct Expected solutions should handle large arrays efficiently (O(n) time or better) You may modify the input array Difficulty Medium (requires knowledge of efficient selection algorithms)