##
Union and Intersection of two sorted arrays
April 27, 2010

Given two sorted arrays, find their union and intersection. For example, if the input arrays are:

April 27, 2010

Given two sorted arrays, find their union and intersection. For example, if the input arrays are:

April 10, 2010

Given an array arr[] of integers, find out the difference between any two elements such that larger element appears after the smaller number in arr[].

March 1, 2010

Question: Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.

February 28, 2010

You are given an array of 0s and 1s in random order. Segregate 0s on left side and 1s on right side of the array. Traverse array only once.

February 11, 2010

Question: Write a C function to find if a given integer x appears more than n/2 times in a sorted array of n integers.

January 11, 2010

Write an efficient C program to find smallest and second smallest element in an array. Example: Input: arr[] = {12, 13, 1, 10, 34, 1} Output: The smallest element is 1 and second Smallest element is 10 A Simple Solution is to sort the array in increasing order. The first two elements in sorted array… Read More »

January 10, 2010

Question: 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. For the below array, program should print -80 and 85.

January 3, 2010

Print the elements of an array in the decreasing frequency if 2 numbers have same frequency then print the one which came first. Examples: Input: arr[] = {2, 5, 2, 8, 5, 6, 8, 8} Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6} Input: arr[] = {2, 5, 2, 6, -1, 9999999,… Read More »

December 7, 2009

Write a program to print all the LEADERS in the array. 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.

November 26, 2009

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… Read More »

November 14, 2009

Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.