Category Archives: Arrays

Questions regarding Arrays

Range Queries for Frequencies of array elements

Given an array of n non-negative integers. The task is to find frequency of a particular element in the arbitrary range of array[]. The range is given as positions (not 0 based indexes) in array. There can be multiple queries of given type. For example:- Input : arr[] = {2, 8, 6, 9, 8, 6,… Read More »

Sum of the products of all possible Subsets

Given an array of n non-negative integers. The task is to find the sum of the product of elements of all the possible subsets. It may be assumed that the numbers in subsets are small and computing product doesn’t cause arithmetic overflow. Example: Input : arr[] = {1, 2, 3} Output : 23 Possible Subset… Read More »

Find a subset with greatest geometric mean

Given an array of positive integers, the task is that we find a subset of size greater than one with maximum product. Input : arr[] = {1, 5, 7, 2, 0}; Output : 5 7 The subset containing 5 and 7 produces maximum geometric mean Input : arr[] = { 4, 3 , 5 ,… Read More »

Find a local minima in an array

Given an array arr[0 .. n-1] of distinct integers, the task is to find a local minima in it. We say that an element arr[x] is a local minimum if it is less than or equal to both its neighbors. For corner elements, we need to consider only one neighbor for comparison. There can be… Read More »

Make two sets disjoint by removing minimum elements

Given two sets of integers as two arrays of size m and n. Find count of minimum numbers that should be removed from the sets so that both set become disjoint or don’t contains any elements in common. We can remove elements from any set. We need to find minimum total elements to be removed.… Read More »

Pairs of Amicable Numbers

Given an array of integers, print the number of pairs in the array that form an amicable pair. Two numbers are amicable if the first is equal to the sum of divisors of the second, and if the second number is equal to the sum of divisors of the first. Examples: Input : arr[] =… Read More »