Given an unsorted array arr[] and two numbers X and K, the task is to find K closest values to X in arr[]. Examples: Input:… Read More
Tag Archives: cpp-pair
Prerequisite: vector, vector pair sorting Given a vector, keep track of the present indexes corresponding to each element and after sorting print element with its… Read More
Given N points in 2 dimensional space. The task is to count the number of triplets pairs (A, B, C) such that point B is… Read More
Unordered Map does not contain a hash function for a pair like it has for int, string, etc, So if we want to hash a… Read More
Given an integer m and n ranges (e.g. [a, b]) which are intersecting and overlapping. The task is to find all the number within the… Read More
Given an unsorted array A[]. The task is to print all unique pairs in the unsorted array with equal sum. Note: Print the result in… Read More
Given an array of size N and an integer K, find the minimum for each and every contiguous subarray of size K. Examples: Input :… Read More
Sets are a type of associative containers in which each element has to be unique, because the value of the element identifies it. The value… Read More
Given a rooted tree and not necessarily binary. The tree contains N nodes, labeled 1 to N. You are given the tree in the form… Read More
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y… Read More
Given an array of N distinct elements, find the minimum number of swaps required to sort the array. Note: The problem is not asking to… Read More
Given an array of positive integers(may contain duplicates) and a number ‘m’, find the number of unordered triplets ((Ai, Aj, Ak) and (Aj, Ai, Ak)… Read More
Given an array of integers and an integer x. Find the length of maximum size subarray having an average of integers greater than or equal… Read More
In C++, priority_queue implements heap. Below are some examples of creating priority queue of pair type. Max Priority queue (Or Max heap) ordered by first… Read More
Given an array of pairs where each pair represents a range, the task is to find the sum of the minimum difference between the consecutive… Read More