# Category Archives: Arrays

## Find closest number in arrayNovember 23, 2017

Given an array of sorted integers. We need to find the closest value to the given number. Array may contain duplicate values and negative numbers.… Read More »

## Number of pairs with maximum sumNovember 22, 2017

Given an array arr[], count number of pairs arr[i], arr[j] such that arr[i] + arr[j] is maximum and i < j. Example: Input : arr[]… Read More »

## Maximizing array sum with given operation

There is an array consisting of (2 * n – 1) integers. We can change sign of exactly n elements in the array. In other… Read More »

## Minimizing array sum by subtracting larger elements from smaller ones

Given an array of n elements perform, we need to minimize array sum. We are allowed to perform below operation any number of times. Choose… Read More »

## Closest greater element for every array element from another array

Given two arrays a[] and b[], we need to build an array c[] such that every element c[i] of c[] contains a value from a[]… Read More »

## Find element in array that divides all array elements

Given an array of n non-negative integers. Find such element in the array, that all array elements are divisible by it. Examples: Input : arr[]… Read More »

## Maximum array sum with prefix and suffix multiplications with -1 allowedNovember 21, 2017

Given N elements (both positive and negative). Find the maximum sum, provided that the first operation is to take some prefix of the sequence and… Read More »

## Program for Bridge and Torch problem

Given an array of positive distinct integer denoting the crossing time of ‘n’ people. These ‘n’ people are standing at one side of bridge. Bridge… Read More »

## Find maximum in an array without using Relational Operators

Given an array A[] of non-negative integers, find the maximum in the array without using Relational Operator. Examples: Input : A[] = {2, 3, 1,… Read More »

## Construct a distinct elements array with given size, sum and element upper boundNovember 20, 2017

Given N size of the original array, SUM total sum of all elements present in the array and K such that no element in array… Read More »

## Number of subarrays with maximum values in given range

Given an array of N elements and L and R, print the number of sub-arrays such that the value of the maximum array element in… Read More »

## Find minimum in an array without using Relational Operators

Given an array A[] of non-negative integers, find the minimum in the array without using Relational Operators. Examples: Input : A[] = {2, 3, 1,… Read More »

## Minimum flips to make all 1s in left and 0s in right | Set 2November 19, 2017

Given a binary array, we can flip all the 1 are in the left part and all the 0 to the right part.Calculate the minimum… Read More »

## Minimum flips to make all 1s in left and 0s in right | Set 1 (Using Bitmask)

Given a binary array, we can flip all the 1 are in the left part and all the 0 to the right part.Calculate the minimum… Read More »

## Minimum gcd operations to make all array elements one

Given an array A[] of size N. You can replace any number in the array with the gcd of that element with any of its… Read More »