Unlike C++, arrays are first class objects in Java. For example, in the following program, size of array is accessed using length which is a… Read More

# Category Archives: Arrays

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

Given an array A[] consisting 0s, 1s and 2s. The task is to write a function that sorts the given array. The functions should put… Read More

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

Given an array A[], write a function that segregates even and odd numbers. The functions should put all even numbers first, and then odd numbers. Example: … Read More

Given an array arr[] of n integers, construct a Product Array prod[] (of same size) such that prod[i] is equal to the product of all… Read More

Given a sorted array and a value x, the ceiling of x is the smallest element in array greater than or equal to x, and… Read More

Given two sorted arrays, find their union and intersection. Example: Input : arr1[] = {1, 3, 4, 5, 7} arr2[] = {2, 3, 5, 6}… Read More

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

Question: Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.For example, if given… Read More

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

Write a C function to return minimum and maximum in an array. Your program should make the minimum number of comparisons. Recommended: Please try your… Read More

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. Basically, we… Read More

Write an efficient C program to find smallest and second smallest element in an array. Example: Input: arr[] = {12, 13, 1, 10, 34, 1}… Read More

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