Find the Kth max and min element in an array

https://practice.geeksforgeeks.org/problems/kth-smallest-element/0 Make priority queue of size k, insert first k elements from the array For the remaining elements, pop and insert into pq if element is smaller than top class Solution { public: int kthSmallest(int arr[], int l, int r, int k) { priority_queue<int, vector<int>> pq(arr, arr + k); int n = r - l + 1; for (int i = k; i < n; i++) { if (arr[i] < pq.
Read more →

Rearrange characters in a string such that no two adjacent are same

Read more →

Implement a maxheap/minheap

https://www.geeksforgeeks.org/building-heap-from-array/ #include <bits/stdc++.h> using namespace std; class Heap { vector<int> v; bool isMinHeap; bool compare(int a, int b) { return isMinHeap ? a < b : a > b; } void heapify(int i) { int left = 2 * i, right = 2 * i + 1; int minIdx = i; if (left < (int)v.size() && compare(v[left], v[minIdx])) { minIdx = left; } if (right < (int)v.size() && compare(v[right], v[minIdx])) { minIdx = right; } if (minIdx !
Read more →

Heap sort

Read more →

Maximum of all subarrays of size K

Read more →

Kth largest element in an array

Read more →

Merge K sorted arrays

Read more →

Merge 2 binary max heaps

Read more →

Kth largest sum continuous subarrays

Read more →

Reorganize strings

Read more →

Merge K sorted linked lists

Read more →

Smallest range in K lists

Read more →

Median in a stream of integers

Read more →

Check if a binary tree is heap

Read more →

Connect N ropes with minimum cost

Read more →

Convert BST to min heap

Read more →

Convert min heap to max heap

Read more →

Minimum sum of two numbers formed from digits of an array

Read more →