Skip to content

Category Archives: Arrays

Given a boolean matrix mat[M][N] of size M X N, modify it such that if a matrix cell mat[i][j] is 1 (or true) then make… Read More
Given an unsorted array of size n. Array elements are in the range from 1 to n. One number from set {1, 2, …n} is… Read More
Given an unsorted array arr[] and two numbers x and y, find the minimum distance between x and y in arr[]. The array might also… Read More
Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order. It… Read More
Given an array and an integer K, find the maximum for each and every contiguous subarray of size k. Examples :  Input: arr[] = {1,… Read More
Given an array arr[], find the maximum j – i such that arr[j] > arr[i]. Examples :  Input: {34, 8, 10, 3, 2, 80, 30,… Read More
  Given a sorted array arr[] and a number x, write a function that counts the occurrences of x in arr[]. Expected time complexity is… Read More
Given a sorted array of n distinct integers where each integer is in the range from 0 to m-1 and m > n. Find the… Read More
Given an unsorted array of numbers, write a function that returns true if the array consists of consecutive numbers. Examples: a) If the array is {5, 2,… Read More
Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element… Read More
Arrays store elements in contiguous memory locations, resulting in easily calculable addresses for the elements stored and this allows a faster access to an element… Read More
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… Read More
Given an array of n elements that contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find these… Read More
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