Given that integers are read from a data stream. Find median of elements read so for in efficient way. For simplicity assume there are no duplicates. For example, let...
Share
Given an array (or string), the task is to reverse the array/string.
Examples :
Input : arr[] = {1, 2, 3}
Output : arr[] = {3, 2, 1}
Input : arr[] = {4, 5, 1, 2}
...
Share
Given an array A[] consisting 0s, 1s and 2s, write a function that sorts A[]. The functions should put all 0s first, then all 1s and all 2s in last.
Examples:
Input :...
Share
Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many di...
Share
Heap sort is a comparison based sorting technique based on Binary Heap data structure. It is similar to selection sort where we first find the maximum element and pl...
Share
A number ‘n’ is called Bleak if it cannot be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to...
Share
Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return the minimum n...
Share
Given an array of N integers. You are allowed to rearrange the element of the array. The task is to find the maximum value of Σarr[i]*i, where i = 0, 1, 2, ...
Share
Given an array of numbers, find GCD of the array elements. In a previous post we find GCD of two number.
Examples:
Input : arr[] = {1, 2, 3}
Output : 1
Input : arr...
Share
LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.
For example LCM of 15 and 20 is 60 and LCM of 5 and 7 is 35.
...
Share