Browsing the topic Arrays
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For example, in an arrya A:
Read More »Given an array of n elements which contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space.
Read More »Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
23 Comments | Filed under ArraysGiven 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.
Read More »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.
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 two numbers which occur twice. Find the two repeating numbers.
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.
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 the elements of arr[] except arr[i]. Solve it without division operator and in O(n).
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 the floor is the greatest element smaller than or equal to x. Assume than the array is sorted in non-decreasing order. Write efficient functions to find floor and ceiling of [...]
Read More »For example, if the input arrays are: arr1[] = {1, 3, 4, 5, 7} arr2[] = {2, 3, 5, 6} Then your program should print Union as {1, 2, 3, 4, 5, 6, 7} and Intersection as {3, 5}.
Read More »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[].
Read More »Given a binary matrix, find out the maximum size square sub-matrix with all 1s. For example, consider the below binary matrix.
Read More »k largest(or smallest) elements in an array | added Min Heap method
36 Comments | Filed under ArraysQuestion: Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.
Read More »Asked by kapil. 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.
Read More »Maximum and minimum of an array using minimum number of comparisons
20 Comments | Filed under ArraysWrite a C function to return minimum and maximum in an array. You program should make minimum number of comparisons.
Read More »Question: Write a C function to find if a given integer appears more than n/2 times in a sorted array of n integers.
Read More »Asked by Vikas Question: Write an efficient C program to find smallest and second smallest element in an array. Difficulty Level: Rookie
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 zero. For the below array, program should print -80 and 85.
Read More »Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.
Read More »Asked By Binod
Read More »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.
Read More »Asked by SG. .. Question: Given an array all of whose elements are 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 [...]
Read More »Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.
Read More »Write a function rotate(arr[], d, n) that rotates arr[] of size n by d elements.
Read More »Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.
Read More »Iterative way: 1) Initialize start and end indexes.
Read More »