## Count elements in a vector that match a target value or condition

To determine number of integers in a vector that matches a particular value. We use count in C++ STL filter_none edit close play_arrow link brightness_4… Read More »

## Swapping of subranges from different containers in C++

A container is a holder object that holds a collection of other objects. They are implemented as class templates, which allows a great flexibility in… Read More »

## Get first and last elements from Array and Vector in CPP

Given an array, find first and last elements of it. Input: {4, 5, 7, 13, 25, 65, 98} Output: First element: 4 Last element: 98… Read More »

## Perform the given queries on the rooted tree

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 »

## Find the k-th smallest divisor of a natural number N

You’re given a number N and a number K. Our task is to find the kth smallest divisor of N. Examples: Input : N =… Read More »

## Minimum operation require to make first and last character same

Given a string S. You are allowed two types of operations: Remove a character from the front of the string. Remove a character from the… Read More »

## Minimum number of swaps required to sort an array | Set 2

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 »

## Find four factors of N with maximum product and sum equal to N

Given an integer . The task is to find all factors of N print the product of four factors of N such that: Sum of… Read More »

## Difference between std::swap and std::vector::swap

The std::swap function is used to swap two elements where as the std::vector::swap function can swap all elements of two different vector containers. Below are… Read More »

## Minimum number of days required to complete the work

Given N works numbered from 1 to N. Given two arrays D1[] and D2[] of N elements each. Also, each work number W(i) is assigned… Read More »

## Lowest Common Ancestor in Parent Array Representation

Given a binary tree represented as parent array, find Lowest Common Ancestor between two nodes ‘m’ and ‘n’. In the above diagram, LCA of 10… Read More »

## Number of Co-prime pairs obtained from the sum of digits of elements in the given range

Given two numbers A and B where 1 <= A <= B. The task is to count the number of pairs whose elements are co-prime… Read More »

## Delete array element in given index range [L – R]

Given an array A[] and size of array is N. The task is to delete element of array A[] are in given range L to… Read More »

## Minimum cost path from source node to destination node via an intermediate node

Given an undirected weighted graph. The task is to find the minimum cost of the path from source node to the destination node via an… Read More »

## Count unique subsequences of length K

Given an array of N numbers and an integer K. The task is to print the number of unique subsequences possible of length K. Examples:… Read More »