# Category Archives: Competitive Programming

## Sort an Array based on the absolute difference of adjacent elements

Given an array arr[] containing N integers, the task is to rearrange all the elements of array such that absolute difference between consecutive elements of… Read More »

## Minimum Cost of Simple Path between two nodes in a Directed and Weighted Graph

Given a directed graph, which may contain cycles, where every edge has weight, the task is to find the minimum cost of any simple path… Read More »

## Construct an Array of size N in which sum of odd elements is equal to sum of even elements

Given an integer N which is always even, the task is to create an array of size N which contains N/2 even numbers and N/2… Read More »

## Count of possible subarrays and subsequences using given length of Array

Given an integer N which denotes the length of an array, the task is to count the number of subarray and subsequence possible with the… Read More »

## Generate a string of size N whose each substring of size M has exactly K distinct characters

Given 3 positive integers N, M and K. the task is to construct a string of length N consisting of lowercase letters such that each… Read More »

## Array range queries to count the number of Fibonacci numbers with updates

Given an array arr[] of N integers, the task is to perform the following two queries: query(start, end): Print the number of fibonacci numbers in… Read More »

## Clockwise Triangular traversal of a Binary Tree

Given a Complete Binary Tree, the task is to print the elements in the Clockwise traversal order. Clockwise Traversal of a tree is defined as:… Read More »

## Which Python Modules are useful for competitive programming?

In the previous article, we have discussed that C++, Java and Python are three most common languages for competitive programming. In this article, we are… Read More »

## Print the sequence of size N in which every term is sum of previous K terms

Given two integers N and K, the task is to generate a series of N terms in which every term is sum of the previous… Read More »

## Sum of GCD of all possible sequences

Given two numbers N and K. A sequence A1, A2, ….AN of length N can be created by placing numbers from 1 to K at… Read More »

## Default values in a Map in C++ STL

Prerequisite: Map in STL A map is a container which is used to store a key-value pair. By default, In Primitive datatypes such as int,… Read More »

## Dynamic Segment Trees : Online Queries for Range Sum with Point Updates

Prerequisites: Segment Tree Given a number N which represents the size of the array initialized to 0 and Q queries to process where there are… Read More »

## Binary Array Range Queries to find the minimum distance between two Zeros

Prerequisite: Segment Trees Given a binary array arr[] consisting of only 0’s and 1’s and a 2D array Q[][] consisting of K queries, the task… Read More »

## Find last remaining element after reducing the Array

Given an array arr[] of size N and an integer K. The task is to find the last remaining element in the array after reducing… Read More »

## Queries to find kth smallest element and point update : Ordered Set in C++

Given an array arr[] of size N and a set Q[][] containing M queries, the task is to execute the queries on the given array… Read More »