## Count of pairs violating BST property

Given a Binary tree and number of nodes in the tree, the task is to find the number of pairs violating the BST property. Binary… Read More »

## Expressing a fraction as a natural number under modulo ‘m’

Given two integers A and B where A is not divisible by B, the task is to express A / B as a natural number… Read More »

## Horizontally Flip a Binary Matrix

Given a binary matrix. The task is to flip the matrix horizontally(find the image of the matrix), then invert it. Note: To flip a matrix… Read More »

## Counting inversions in an array using segment tree

Given an array of integers arr, the task is to count the number of inversions in the array. If A[i] > A[j] and i <… Read More »

## Count inversions of size k in a given array

Given an array of n distinct integers and an integer k. Find out the number of sub-sequences of a such that , and . In… Read More »

## Counting cross lines in an array

Given an unsorted array of distinct elements. Task is to count number of cross lines formed in an array elements after sorting the array elements.… Read More »

## Counting inversions in all subarrays of given size

Given an array and an integer k, count all inversions in all subarrays of size k. Example: Input : a[] = {7, 3, 2, 4,… Read More »

## Subarray Inversions

We have an array A of n integers that we’re planning on sorting. Specifically, we want to know how close the array is to sorted.… Read More »

## Minimum swaps to reach permuted array with at most 2 positions left swaps allowed

Given a permuted array of length N of first N natural numbers, we need to tell the minimum number of swaps required in the sorted… Read More »

## Sorting possible using size 3 subarray rotation

Given an array of integer values which need to be sorted by only one operation – subarray rotation where subarray size should be 3. For… Read More »

## Count pairs in an array that hold i*arr[i] > j*arr[j]

Given an array of integers arr[0..n-1], count all pairs (arr[i], arr[j]) in the such that i*arr[i] > j*arr[j], 0 =< i < j < n.… Read More »

## Number of swaps to sort when only adjacent swapping allowed

Given an array arr[] of non negative integers. We can perform a swap operation on any two adjacent elements in the array. Find the minimum… Read More »

## Number of permutation with K inversions

Given an array, an inversion is defined as a pair a[i], a[j] such that a[i] > a[j] and i < j. We are given two… Read More »

## Find Surpasser Count of each element in array

A surpasser of an element of an array is a greater element to its right, therefore x[j] is a surpasser of x[i] if i <… Read More »

## Count Inversions of size three in a given array

Given an array arr[] of size n. Three elements arr[i], arr[j] and arr[k] form an inversion of size 3 if a[i] > a[j] >a[k] and… Read More »