# Category Archives: Competitive Programming

## Maximum of all distances to the nearest 1 cell from any 0 cell in a Binary matrix

Given a Matrix of size N*N filled with 1‘s and 0‘s, the task is to find the maximum distance from a 0-cell to its nearest… Read More »

## Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9

Given a number N, the task is to find the sum of all N digits palindromic numbers (formed by digits from 1 to 9) that… Read More »

## Writing code faster during Competitive Programming in C++

This article focuses on how to implement your solutions and implement them fast while doing competitive programming. Setup Please refer Setting up a C++ Competitive… Read More »

## Print the nodes with a prime degree in given Prufer sequence of a Tree

Given a Prufer sequence of a Tree, the task is to print the nodes with prime-degree in this tree. Examples: Input: arr[] = {4, 1,… Read More »

## Check if the square of a number is divisible by K or not

Given two integers, X and K, the task is to find if X2 is divisible by K or not. Here, both K and X can… Read More »

## Count of odd and even parity elements in subarray using MO’s algorithm

Given an array arr consisting of N elements and Q queries represented by L and R denoting a range, the task is to print the… Read More »

## Check if the length of all connected components is a Fibonacci number

Given an undirected graph with V vertices and E edges, the task is to find all the connected components of the graph and check if… Read More »

## Check if the given array can be constructed uniquely from the given set of subsequences

Given an array arr of distinct elements and a list of subsequences seqs of the array, the task is to check whether the given array… Read More »

## Find the length of the longest subsequence with first K alphabets having same frequency

Given a string str with uppercase characters and an integer K, the task is to find the length of the longest subsequence such that the… Read More »

## Generate a string with maximum possible alphabets with odd frequencies

Given an integer N, the task is to generate a string str which contains maximum possible lowercase alphabets with each of them appearing an odd… Read More »

## Print all possible combinations of the string by replacing ‘\$’ with any other digit from the string

Given a number as a string where some of the digits are replaced by a ‘\$’, the task is to generate all possible number by… Read More »

## Minimum cost to merge numbers from 1 to N

Given an integer N, the task is to find the minimum cost to merge all the numbers from 1 to N where the cost of… Read More »

## Find smallest perfect square number A such that N + A is also a perfect square number

Given a positive number N. The task is to find out the smallest perfect square number A such that N + A is also a… Read More »

## Check if minimum element in array is less than or equals half of every other element

Given an array arr[], the task is to check if the minimum element in the array is less than or equal to half of every… Read More »

## Must do Math for Competitive Programming

Competitive Programming (CP) doesn’t typically require to know high-level calculus or some rocket science. But there are some concepts and tricks which are sufficient most… Read More »