# Category Archives: Competitive Programming

## 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 »

## Caesar Concatenation

Given two strings str1 and str2 containing alpha-numeric characters and a number N. The task is to form a new encrypted string which contains the… Read More »

## Construct a string of length L such that each substring of length X has exactly Y distinct letters

Given the length of the string l, the length of the substring x and the number of distinct characters that a substring of length x… Read More »

## Nodes with prime degree in an undirected Graph

Given an undirected graph with N vertices and M edges, the task is to print all the nodes of the given graph whose degree is… Read More »

## Find the final co-ordinates reached by following a sequence of directions

Given a starting point with x and y co-ordinates SX and SY respectively, and a sequence ‘D’ denoting the directions to be followed, the task… Read More »

## Nth positive number whose absolute difference of adjacent digits is at most 1

Given a number N, the task is to find the Nth number which has an absolute difference of 1 between every pair of its adjacent… Read More »

## Find the minimum dominating set of a Binary tree

Given a binary tree with N nodes numbered [1, N], the task is to find the size of the smallest Dominating set of that tree.… Read More »

## Number of ways to color N-K blocks using given operation

Given N blocks out of which K are colored. These K colored blocks are denoted by an array arr[]. The task is to count the… Read More »

## Find minimum GCD of all pairs in an array

Given an array arr of positive integers, the task is to find minimum GCD possible for any pair of the given array. Examples: Input: arr[]… Read More »

## Find the minimum number possible by changing at most one digit

Given a positive integer N consisting only two types of digits 6 and 9, the task is to generate the minimum number possible by reversing… Read More »

## Lowest Common Ancestor for a Set of Nodes in a Rooted Tree

Given a rooted tree with N nodes, the task is to find the Lowest Common Ancestor for a given set of nodes V of that… Read More »

## Find Non-overlapping intervals among a given set of intervals

Given N set of time intervals, the task is to find the intervals which don’t overlap with the given set of intervals. Examples: Input: interval… Read More »