Category Archives: Hash

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 »

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 »

Find pair with greatest product in array

Given an array of n elements, the task is to find the greatest number such that it is product of two elements of given array. If no such element exists, print -1. Elements are within the range of 1 to 10^5. Input : arr[] = {10, 3, 5, 30, 35} Output: 30 Explanation: 30 is… Read More »

Find all permuted rows of a given row in a matrix

We are given a m*n matrix of positive integers and a row number. The task is to find all rows in given matrix which are permutations of given row elements. It is also given that values in every row are distinct. Examples: Input : mat[][] = {{3, 1, 4, 2}, , {1, 6, 9, 3},… Read More »