# Category Archives: Divide and Conquer

## Expected number of moves to reach the end of a board | Matrix Exponentiation

Given a linear board of length N numbered from 1 to N, the task is to find the expected number of moves required to reach… Read More »

## Place the prisoners into cells to maximize the minimum difference between any two

Given an array cell[] of N elements, which represent the positions of the cells in a prison. Also, given an integer P which is the… Read More »

## Find N in the given matrix that follows a pattern

Given an infinite matrix filled with the natural numbers as shown below: 1 2 4 7 . . . 3 5 8 . . .… Read More »

## Find the count of distinct numbers in a range

Given an array of size N containing numbers only from 0 to 63, and you are asked Q queries regarding it. Queries are as follows:… Read More »

## Smallest subarray with GCD as 1 | Segment Tree

Given an array arr[], the task is to find the smallest sub-arrays with GCD equal to 1. If there is no such sub-array then print… Read More »

## Significant Inversions in an Array

Given an array arr[], the task is to finds the total significant inversion count for the array. Two elements arr[i] and arr[j] form a significant… Read More »

## Find an N x N grid whose xor of every row and column is equal

Given an integer N which is a multiple of 4, the task is to find an N x N grid for which the bitwise xor… Read More »

## Modular Exponentiation of Complex Numbers

Given four integers A, B, K, M. The task is to find (A + iB)K % M which is a complex number too. A +… Read More »

## Cost Based Tower of Hanoi

The standard Tower of Hanoi problem is explained here . In the standard problem, all the disc transactions are considered identical. Given a 3×3 matrix… Read More »

## Cartesian tree from inorder traversal | Segment Tree

Given an in-order traversal of a cartesian tree, the task is to build the entire tree from it. Examples: Input: arr[] = {1, 5, 3}… Read More »

## Kth smallest element in the array using constant space when array can’t be modified

Given an array arr[] of size N and an integer K, the task is to find the Kth smallest element from the array in constant… Read More »

## Complexity Analysis of Binary Search

Complexities like O(1) and O(n) are simple to understand. O(1) means it requires constant time to perform operations like to reach an element in constant… Read More »

## Sum of maximum of all subarrays | Divide and Conquer

Given an array arr[] of length N, the task is to find the sum of the maximum elements of every possible sub-array of the array.… Read More »

## Count the triplets such that A[i] < B[j] < C[k]

Given three array A[], B[] and C[] of N integers each. The task is to find the count of triplets (A[i], B[j], C[k]) such that… Read More »

## Find minimum steps required to reach the end of a matrix | Set 2

Given a 2d-matrix consisting of positive integers, the task is to find the minimum number of steps required to reach the end of the matrix.… Read More »