Category Archives: Hash

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 »

Distinct strings with odd and even changes allowed

Given an array of lower case strings, the task is to find the number of strings that are distinct. Two strings are distinct if on applying the following operations on one string the second string cannot be formed. A character on odd index can be swapped with another character at odd index only. A character… Read More »