# Category Archives: Competitive Programming

## Lazy Propagation in Segment Tree | Set 2

Given an array arr[] of size N. There are two types of operations: Update(l, r, x) : Increment the a[i] (l <= i <= r)… Read More »

## Find n positive integers that satisfy the given equations

Given three integers N, X and Y. The task is to find N positive integers that satisfy the given equations. a12 + a22 + ….… Read More »

## Find (1^n + 2^n + 3^n + 4^n) mod 5 | Set 2

Given a very large number N. The task is to find (1n + 2n + 3n + 4n) mod 5. Examples: Input: N = 4… Read More »

## Minimum number of given operations required to convert a permutation into an identity permutation

Given a permutation P (P1, P2, P3, … Pn) of first n natural numbers. Find the minimum number of operations to convert it into an… Read More »

## Find original numbers from gcd() every pair

Given an array arr[] containing GCD of every possible pair of elements of another array. The task is to find the original numbers which are… Read More »

## Element in a matrix starting from which anti-clockwise traversal ends at the last element

Given a mat[][] of size n X n, the task is to find an element X such that if the anti-clockwise traversal is begun from… Read More »

## Maximum number of candies that can be bought

Given an array arr[] of size n where arr[i] is the amount of candies of type i. You have unlimited amount of money. The task… Read More »

## Replace array elements by sum of next two consecutive elements

Given an array arr[] of size n, The task is to replace every element of the array by the sum of next two consecutive elements… Read More »

## Spanning Tree With Maximum Degree (Using Kruskal’s Algorithm)

Given an undirected unweighted connected graph consisting of n vertices and m edges. The task is to find any spanning tree of this graph such… Read More »

## Number of subarrays having sum of the form k^m, m >= 0

Given an integer k and an array arr[], the task is to count the number of sub-arrays which have the sum equal to some positive… Read More »

## Count common characters in two strings

Given two strings s1 and s2 consisting of lowercase English alphabets, the task is to count all the pairs of indices (i, j) from the… Read More »

## Given count of digits 1, 2, 3, 4, find the maximum sum possible

Given the count of digits 1, 2, 3, 4. Using these digits you are allowed to only form numbers 234 and 12. The task is… Read More »

## Find the good permutation of first N natural numbers

Given an integer N, the task is to print a good permutation of first N natural numbers. Let’s denote the ith element of the permutation… Read More »

## Find the maximum number of composite summands of a number

Given an integer N(1<=N<=10^9). The task is to represent N as a sum of the maximum possible number of composite summands and print this maximum… Read More »

## Find the numbers of strings that can be formed after processing Q queries

Given a number N(1<=N<=2000)., The task is to find the number strings of size N that can be obtained after using characters from 'a' to… Read More »