Consider n machines which produce same type of items but at different rate i.e., machine 1 takes a1 sec to produce an item, machine 2 takes a2 sec to produce an item....

Share

Given a string, build it’s Suffix Array
We have already discussed following two ways of building suffix array:
Naive O(n2Logn) algorithm
Enhanced O(nLogn) alg...

Share

Prerequisite : Introduction and DFS
The task is to find LCA of two given nodes in a tree (not necessarily a Binary Tree). In previous posts, we have seen how to calcu...

Share

Given an array of size n and multiple values around which we need to left rotate the array. How to quickly print multiple left rotations?
Examples :
Input : arr[] = {...

Share

An array contains both positive and negative numbers in random order. Rearrange the array elements so that positive and negative numbers are placed alternatively. Num...

Share

We recommend to read following post as a prerequisite of this post.
K’th Smallest/Largest Element in Unsorted Array | Set 1
Given an array and a number k where...

Share

We recommend reading following posts as a prerequisite of this post.
K’th Smallest/Largest Element in Unsorted Array | Set 1
K’th Smallest/Largest Eleme...

Share

Given an array of size N which is initialized with all zeros. We are given many range add queries, which should be applied to this array. We need to print final updat...

Share

Given an array of numbers of size N and Q queries. Each query or a range can be represented by L (LeftIndex) and R(RightIndex). Find the XOR-sum of the numbers that a...

Share

Given a Binary Search Tree, find median of it.
If no. of nodes are even: then median = ((n/2th node + (n+1)/2th node) /2
If no. of nodes are odd : then median = (n+1...

Share