Important functions of STL Components in C++
...
read more
priority_queue::swap() in C++ STL
Priority queues are a type of container adaptors, specifically designed such that the first element of the queue is either the greatest or the smallest of all elements in the queue. However, in C++ STL (by default) the largest element is at the top. We can also create a priority queue having the smallest element at the top by simply passing an extra parameter while creating the priority queue....
read more
Minimize remaining array element by removing pairs and replacing them with their average
Given an array arr[] of size N, the task is to find the smallest possible remaining array element by repeatedly removing a pair, say (arr[i], arr[j]) from the array and inserting the Ceil value of their average....
read more
Length of the longest subsequence with negative sum of all prefixes
Given an array arr[] consisting of N integers, the task is to find the length of the longest subsequence such that the prefix sum at each index of the subsequence is negative....
read more
Replace the middle element of the longest subarray of 0s from the right exactly K times
Given an array arr[] of size N, consisting of 0s initially, and a positive integer K, the task is to print the array elements by performing the following operations exactly K times....
read more
Find the k smallest numbers after deleting given elements
Given an array of integers, find the k smallest numbers after deleting given elements. In case of repeating elements delete only one instance in the given array for every instance of element present in the array containing the elements to be deleted....
read more
Maximize jobs that can be completed under given constraint
Given an integer N denoting number of jobs and a matrix ranges[] consisting of a range [start day, end day] for each job within which it needs to be completed, the task is to find the maximum possible jobs that can be completed.Examples:...
read more
Minimum Cost using Dijkstra by Modifying Cost of an Edge
Given an undirected weighted graph of N nodes and M edges in the form of a tuple lets say {X, Y, Z} such that there is an edge with cost Z between X and Y. We are supposed to compute the minimum cost of traversal from node 1 to N. However, we can perform one operation before the traversal such that we can reduce the cost of any edge lets say, C to C / 2 (integer division)....
read more
Maximum number of apples that can be eaten by a person
Given two arrays apples[] and days[] representing the count of apples an apple tree produces and the number of days these apples are edible from the ith day respectively, the task is to find the maximum number of apples a person can eat if the person can eat at most one apple in a day....
read more
Priority Queue of Vectors in C++ STL with Examples
Priority Queue in STL Priority queues are a type of container adapters, specifically designed such that the first element of the queue is the greatest of all elements in the queue and elements are in non increasing order(hence we can see that each element of the queue has a priority{fixed order})...
read more
priority_queue value_type in C++ STL
The priority_queue :: value_type method is a built-in function in C++ STL which represents the type of object stored as an element in a priority_queue. It acts as a synonym for the template parameter....
read more
Minimum increment/decrement to make array non-Increasing
Given an array a, your task is to convert it into a non-increasing form such that we can either increment or decrement the array value by 1 in the minimum changes possible....
read more