Minimum number of moves after which there exists a 3X3 coloured square

Given an N * N board which is initially empty and a sequence of queries, each query consists of two integers X and Y where… Read More »

Rearrange Odd and Even values in Alternate Fashion in Ascending Order

Given an array of integers (both odd and even), the task is to arrange them in such a way that odd and even values come… Read More »

Check if a triplet with given sum exists in BST

Given a Binary Search Tree and a SUM. The task is to check if there exists any triplet(group of 3 elements) in the given BST… Read More »

Rearrange all elements of array which are multiples of x in decreasing order

Given an array of integers arr[] and an integer x, the task is to sort all the elements of the array which are multiples of… Read More »

Print levels with odd number of nodes and even number of nodes

Given an N-ary tree, print all the levels with odd and even number of nodes in it. Examples: For example consider the following tree 1… Read More »

Sort perfect squares in an array at their relative positions

Given an integer array , the task is to sort only the elements which are perfect squares at their relative positions in the array (positions… Read More »

Find the missing elements from 1 to M in given N ranges | Set-2

Given an integer and ranges (e.g. [a, b]) which are intersecting and overlapping. The task is to find all the number within the range that… Read More »

Print all pairs in an unsorted array with equal sum

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 »

Count subarrays with Prime sum

Given an array A[] of integers. The task is to count total subarrays whose sum is prime with ( size > 1 ). Examples: Input… Read More »

Count the number of elements in an array which are divisible by k

Given an array of integers. The task is to calculate the count of a number of elements which are divisible by a given number k.… Read More »

Sorting array elements with set bits equal to K

Given an array of integers and a number . The task is to sort only those elements of the array whose total set bits are… Read More »

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 »