# Category Archives: Competitive Programming

## Count of cells in a matrix whose adjacent cells’s sum is prime Number

Given a M x N matrix mat[][], the task is to count the number of cells which have the sum of its adjacent cells equal… Read More »

## Count of unique lengths of connected components for an undirected graph using STL

Given an undirected graph, the task is to find the size of each connected component and print the number of unique sizes of connected components… Read More »

## Design a structure which supports insertion and first non-repeating element in O(1) time

Design a Data structure which supports insertion and first non-repeating element in O(1) time. Operations that are supported by the data structure: Insertion: Insert a… Read More »

## Range Queries to count elements lying in a given Range : MO’s Algorithm

Given an array arr[] of N elements and two integers A to B, the task is to answer Q queries each having two integers L… Read More »

## Check if longest connected component forms a palindrome in undirected graph

Given an undirected graph with V vertices and E edges, the task is to check that if the largest connected component of the graph forms… Read More »

## Longest subsequence with different adjacent characters

Given string str. The task is to find the longest subsequence of str such that all the characters adjacent to each other in the subsequence… Read More »

## Maximum number of prime factors a number can have with exactly x factors

Given an integer X, denoting the number of factors of a positive integer N can have. the task is to find the maximum number of… Read More »

## Count of elements in first Array greater than second Array with each element considered only once

Given two sorted array of size N. The task is to find the maximum number of elements in the first array which are strictly greater… Read More »

## Minimize the maximum difference of adjacent elements after at most K insertions

Given an array of N elements, the task is to minimize the maximum difference of adjacent elements by inserting at most K elements in the… Read More »

## Split N powers of 2 into two subsets such that their difference of sum is minimum

Given an even number N, the task is to split all N powers of 2 into two sets such that the difference of their sum… Read More »

## Maximum Balanced String Partitions

Given a balanced string str of size N with an equal number of L and R, the task is to find a maximum number X,… Read More »

## Count of sub-arrays with odd product

Given an integer array arr[] of size N, the task is to count the number of sub-arrays that have an odd product. Examples: Input :… Read More »

## Common nodes in the inorder sequence of a tree between given two nodes in O(1) space

Given a binary tree consisting of distinct values and two numbers K1 and K2, the task is to find all nodes that lie between them… Read More »

## Sort elements of an array in increasing order of absolute difference of adjacent elements

Given an array arr[], the task is to arrange the array in such a way that the absolute difference between the adjacent elements is in… Read More »

## Minimum possible modifications in the matrix to reach destination

Given a matrix of size N x M consisting of integers 1, 2, 3 and 4. Each value represents the possible movement from that cell:… Read More »