Category Archives: Hash

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 »

Subarrays with distinct elements

Given an array, the task is to calculate the sum of lengths of contiguous subarrays having all elements distinct. Examples: Input : arr[] = {1, 2, 3} Output : 10 {1, 2, 3} is a subarray of length 3 with distinct elements. Total length of length three = 3. {1, 2}, {2, 3} are 2… Read More »

Count pairs whose products exist in array

Given an array, count those pair whose product value is present in array. Examples: Input : arr[] = {6, 2, 4, 12, 5, 3} Output : 3 All pairs whose product exist in array (6 , 2) (2, 3) (4, 3) Input : arr[] = {3, 5, 2, 4, 15, 8} Output : 2 A… Read More »