# Category Archives: Competitive Programming

## First subarray with negative sum from the given Array

Given an array arr[] consisting of N integers, the task is to find the start and end indices of the first subarray with a Negative… Read More »

## Largest odd divisor Game to check which player wins

Two players are playing a game starting with a number n. In each turn, a player can make any one of the subsequent moves:   Divide… Read More »

## Print the nodes of Binary Tree having a grandchild

Given a Binary Tree, the task is to print the nodes that have grandchildren. Examples: Input: Output: 20 8 Explanation: 20 and 8 are the… Read More »

## Check if two nodes are on same path in a tree | Set 2

Given two nodes of a binary tree v1 and v2, the task is to check if two nodes are on the same path in a… Read More »

## Count quadruplets(A, B, C, D) till N such that sum of square of A and B is equal to that of C and D

Given a number N, the task is to find the number of quadraples such that a2 + b2 = c2 + d2 where (1 <=… Read More »

## Maximum bitwise OR value of subsequence of length K

Given an array arr[] of N positive integers and a number K, the task is to find the maximum value of bitwise OR of the… Read More »

## Sum of all divisors from 1 to N | Set 3

Given a positive integer N, the task is to find the sum of divisors of all the numbers from 1 to N. Examples: Input: N… Read More »

## Reverse a subarray of the given array to minimize the sum of elements at even position

Given an array arr[] of positive integers. The task is to reverse a subarray to minimize the sum of elements at even places and print… Read More »

## Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s

Given two integers N and K, the task is to count the numbers up to N digits such that no two zeros are adjacents and… Read More »

## Count of square free divisors of a given number

Given an integer N, the task is to count the number of square-free divisors of the given number. A number is said to be square-free,… Read More »

## Minimum cost of reducing Array by merging any adjacent elements repetitively

Given an array arr[] of N numbers. We can merge two adjacent numbers into one and the cost of merging the two numbers is equal… Read More »

## Largest number M less than N such that XOR of M and N is even

Given a positive integer N, the task is to find the largest integer M such that 0 <= M < N and XOR(M, N) is… Read More »

## Minimize operations required to make each element of Array equal to it’s index value

Given an array arr[] consisting of N integers, the task is to to modify the array such that arr[index] = index using minimum number of… Read More »

## K-th term from given N merged Arithmetic Progressions

Given an integer K and an array arr[] of N integers, each of which is the first term and common difference of an Arithemetic Progression,… Read More »

## Count all indices of cyclic regular parenthesis

Given a string S of length N, consisting of only opening ‘(‘ and closing ‘)‘ parenthesis. The task is to find all indices ‘K‘ such… Read More »