Longest subarray with only one value greater than k

Given an array of N numbers, find length of the longest subarray such that K is the second largest element on insertion. Examples: Input: a[]… Read More »

Sets of pairs in C++

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 »

set get_allocator() in C++ STL

The set::get_allocator() in C++ STL is an in-built function which returns the copy of the allocator object associated with the set. Syntax: mulset.get_allocator(); Parameters: This… Read More »

set operator= in C++ STL

The ‘=’ is an operator in C++ STL which copies (or moves) a set to another set and set::operator= is the corresponding operator function. There… Read More »

Queries to add, remove and return the difference of maximum and minimum.

Given Q queries. The queries are of three types and are described below: Add the number num to the list. Remove the number num from… Read More »

Queries on insertion of an element in a Bitonic Sequence

Given a Bitonic sequence ‘S’ and ‘Q’ no. of queries. Each query contain an integer xi, 1 <= i <= Q. The task is to… Read More »

Count number of triplets with product equal to given number with duplicates allowed | Set-2

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 »

Subarray whose sum is closest to K

Given an array of positive and negative integers and an integer K. The task is to find the subarray which has its sum closest to… Read More »

Smallest Greater Element on Right Side

Given an array of distinct elements, print the Closest Greater Element (NGE) for every element. The closest greater Element for an element x is the… Read More »

Queries to insert, delete one occurrence of a number and print the least and most frequent element

Given Q queries of type 1, 2, 3 and 4 as described below. Type-1: Insert a number to the list. Type-2: Delete only one occurrence… Read More »

set cbegin() and cend() function in C++ STL

The set::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container. The iterator cannot… Read More »

set crbegin() and crend() function in C++ STL

The set::crbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the last element in the container. The iterator cannot… Read More »

set count() function in C++ STL

The set::count() is a built-in function in C++ STL which returns the number of times an element occurs in the set. It can only return… Read More »

set max_size() function in C++ STL

The set::max_size() is a built-in function in C++ STL which returns the maximum number of elements a set container can hold. Syntax: set_name.max_size() Parameters: This… Read More »

set emplace_hint() function in C++ STL

The set::emplace_hint() is a built-in function in C++ STL which inserts a new element in the set. A position is passed in the parameter of… Read More »