1. Given an array A[] and a number x, check for pair in A[] with sum as x
Explanation: NA
Category: Drill Down, Binary Map
2. Majority Element
Explanation: A majority element in an array A[] of size n is an element that
appears more than n/2 times (and hence there is at most one such element).
Write a function which takes an array and emits the majority element (if it
exists), otherwise prints NONE as follows:
I/P : 3 3 4 2 4 4 2 4 4
O/P : 4
I/P : 3 3 4 2 4 4 2 4
O/P : NONE
Category:
3. Find the Number Occurring Odd Number of Times
Explanation: Given an array of positive integers. All numbers occur even
number of times except one number which occurs odd number of times. Find
the number in O(n) time & constant space.
Example:
I/P = [1, 2, 3, 2, 3, 1, 3]
O/P = 3
Category: Similarity XOR
4. Largest Sum Contiguous Subarray
Explanation: NA
Category: Keep Track Sum
5. Find the Missing Number
Explanation: You are given a list of n-1 integers and these integers are in the
range of 1 to n. There are no duplicates in list. One of the integers is missing in
the list. Write an efficient code to find the missing integer.
Example:
Explanation: NA
Category: Swap/Reversal
11.Reversal algorithm for array rotation
Explanation: NA
Category: Swap/Reversal
12.Block swap algorithm for array rotation
Explanation: NA
Category: Swap/Reversal
13.Maximum sum such that no two elements are adjacent
Explanation: Given an array of positive numbers, find the maximum sum of a
subsequence with the constraint that no 2 numbers in the sequence should
be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3
2 5 10 7 should return 15 (sum of 3, 5 and 7).
Category:
14.Leaders in an array
Explanation: An element is leader if it is greater than all the elements to its
right side. And the rightmost element is always a leader. For example int the
array {16, 17, 4, 3, 5, 2}, leaders are 17, 5 and 2.
Category: Backward Processing
15.Sort elements by frequency
Explanation: Print the elements of an array in the decreasing frequency if 2
numbers have same frequency then print the one which came 1 st.
E.g. 2 5 2 8 5 6 8 8 output: 8 8 8 2 2 5 5 6.
Category: Binary Map
16.Count Inversions in an array
Explanation: Two elements a[i] and a[j] form an inversion if a[i] > a[j] and i <
j
Category: Merge
17.Two elements whose sum is closest to zero
Explanation: An Array of integers is given, both +ve and -ve. You need to find
the two elements such that their sum is closest to zero.
Category: Sorting, 2-Pointers
18.Find the smallest and second smallest element in an array
Explanation: NA
Category: Simple Scan
19.Check for Majority Element in a sorted array
Explanation: NA
Category: Sorted B-Search
20.Maximum and minimum of an array using minimum number of comparisons
Explanation: NA
example, let the input array be {1, 2, 8, 10, 10, 12, 19}
x = 0: floor doesn't exist in array, ceil = 1
x = 1: floor = 1, ceil = 1
x = 5: floor = 2, ceil = 8
x = 20: floor = 19, ceil doesn't exist in array
Explanation: NA
Category: 2-Pointers
28.Find the two repeating elements in a given array
Explanation: You are given an array of n+2 elements. All elements of the
array are in range 1 to n. And all elements occur once except two numbers
which occur twice. Find the two repeating numbers.
For example, array = {4, 2, 4, 5, 2, 3, 1} and n = 5
The above array has n + 2 = 7 elements with all elements occurring once
except 2 and 4 which occur twice. So the output should be 4 2.
Category: Number Property
29.Sort an array of 0s, 1s and 2s
Explanation: NA
Category: 2-Pointers
30.Find the Minimum length Unsorted Subarray
Explanation: Given an unsorted array arr[0..n-1] of size n, find the minimum
length subarray arr[s..e] such that sorting this subarray makes the whole
array sorted.
Examples:
1) If the input array is [10, 12, 20, 30, 25, 40, 32, 31, 35, 50, 60], your
program should be able to find that the subarray lies between the indexes 3
and 8.
2) If the input array is [0, 1, 15, 25, 6, 7, 30, 40, 50], your program should be
able to find that the subarray lies between the indexes 2 and 5.
Category: Scan
31.sorting which makes the complete array sorted
32.Find duplicates in O(n) time and O(1) extra space
33.Equilibrium index of an array
34.Linked List vs Array
35.Which sorting algorithm makes minimum number of memory writes?
36.Turn an image by 90 degree
37.Next Greater Element
38.Check if array elements are consecutive | Added Method 3
39.Find the smallest missing number
40.Count the number of occurrences in a sorted array
41.Interpolation search vs Binary search
42.Given an array arr[], find the maximum j i such that arr[j] > arr[i]