# Category Archives: Divide and Conquer

## Construct an array of first N natural numbers having no triplet (i, j, k) such that a[i] + a[j] = 2* a[k] where i < j< k

Given a positive integer N, the task is to construct an array a[] using first N natural numbers which contains no such triplet (i, j,… Read More »

## Reduce array to longest sorted array possible by removing either half of given array in each operation

Given an array arr[] of size N (always power of 2), the task is to find the length of the longest sorted array to which… Read More »

## Maximum length possible by cutting N given woods into at least K pieces

Given an array wood[] of size N, representing the length of N pieces of wood and an integer K, at least K pieces of the… Read More »

## Merge two sorted arrays in O(1) extra space using Heap

Given two sorted arrays, arr[], brr[] of size N, and M, the task is to merge the two given arrays such that they form a… Read More »

## Merge two sorted arrays in O(1) extra space using QuickSort partition

Given two sorted arrays, arr[], brr[] of size N, and M, the task is to merge the two given arrays such that they form a… Read More »

## Print X array elements closest to the Kth smallest element in the array

Given two integers K, X, and an array arr[] consisting of N distinct elements, the task is to find X elements closest to the Kth… Read More »

## Mth bit in Nth binary string from a sequence generated by the given operations

Given two integers N and M, generate a sequence of N binary strings by the following steps: S0 = “0” S1 = “1” Generate remaining… Read More »

## Find all array elements occurring more than ⌊N/3⌋ times

Given an array arr[] consisting of N integers, the task is to find all the array elements having frequency more than ⌊N/3⌋ in the given… Read More »

## Abstraction of Binary Search

What is the binary search algorithm? Binary Search Algorithm is used to find a certain value of x for which a certain defined function f(x) needs… Read More »

## Puzzle | Find the overweight islander

There are 12 men on an island. 11 weigh exactly the same, but one of them is slightly lighter or heavier. There is a seesaw… Read More »

## Find value after N operations to remove N characters of string S with given constraints

Given a string S of Size N. Initially, the value of count is 0. The task is to find the value of count after N… Read More »

## Check if a number N can be expressed in base B

Given a number N and any base B. The task is to check if N can be expressed in the form a1*b0 + a2*b1 +… Read More »

## Queries to find the Minimum Weight from a Subtree of atmost D-distant Nodes from Node X

Given an N-ary Tree rooted at 1, and an array val[] consisting of weights assigned to every node, and a matrix Q[][], consisting of queries… Read More »

## Minimum count of elements required to obtain the given Array by repeated mirror operations

Given an array arr[] consisting of N integers, the task is to find the array K[] of minimum possible length such that after performing multiple… Read More »

## Count distinct elements after adding each element of First Array with Second Array

Given two arrays arr1[] and arr2[]. We can generate another array arr3[] by adding each element of the array arr1[] to each element arr2[]. The… Read More »