# Category Archives: Competitive Programming

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

## Missing occurrences of a number in an array such that maximum absolute difference of adjacent elements is minimum

Given an array arr[] of some positive integers and missing occurrence of a specific integer represented by -1, the task is to find that missing… Read More »

## Find two numbers made up of a given digit such that their difference is divisible by N

Given two numbers, N and M, the task is to find two numbers made up of M as all its digits such that their difference… Read More »

## Number of times Maximum and minimum value updated during traversal of array

Given an array arr[], the task is to count the number of times the minimum and the maximum value is updated during the traversal of… Read More »

## Find K numbers with sum equal to N and sum of their squares maximized

Given two integers N and K, the task is to find K numbers(A1, A2, …, AK) such that ∑i=1KAi is equal to N and ∑i=1KAi2… Read More »

## Longest subarray with absolute difference between elements less than or equal to K using Heaps

Given an array arr[] of N integers and an integer K, our task is to find the length of the longest subarray such that for… Read More »

## Merge first two minimum elements of the array until all the elements are greater than K

Given an array arr[] and an integer K, the task is to find the number of merge operation required such that all the elements of… Read More »

## Segregate groups of first N numbers having GCD equals to 1

Given a number N. The task is to group all the numbers from 1 to N such GCD of all the numbers in each group… Read More »

## Longest palindromic string formed by concatenation of prefix and suffix of a string

Given a string str, the task is to find the longest palindromic substring formed by the concatenation of the prefix and suffix of the given… Read More »

## Sum of all N-digit palindromic numbers which doesn’t contains 0 and are divisible by 9

Given a number N, the task is to find the sum of all N-digit palindromic numbers which are divisible by 9 and the number doesn’t… Read More »

## Path with minimum XOR sum of edges in a directed graph

Given a directed graph with N nodes and E edges, a source S and a destination D nodes. The task is to find the path… Read More »

## Longest subarray in which absolute difference between any two element is not greater than X

Given an integer array arr[] of size N and an integer X, the task is to find the longest sub-array where the absolute difference between… Read More »

## Maximize the decimal equivalent by flipping only a contiguous set of 0s

Given a binary number in the form of a string, the task is to print a binary equivalent obtained by flipping only one contiguous set… Read More »

## Split N natural numbers into two sets having GCD of their sums greater than 1

Given an integer N, the task is to create two sets of distinct elements from 1 to N such that the gcd of their respective… Read More »