Category Archives: Hash

Find All Duplicate Subtrees

Given a binary tree, find all duplicate subtrees. For each duplicate subtrees, we only need to return the root node of any one of them.… Read More »

Minimum number of distinct elements after removing m items

Given an array of items, an i-th index element denotes the item id’s and given a number m, the task is to remove m elements… Read More »

Maximum possible sum of a window in an array such that elements of same window in other array are unique

Given two arrays A and B of equal number of elements. Task is to find the maximum sum possible of a window in array B… Read More »

Find top k (or most frequent) numbers in a stream

Given an array of n numbers. Your task is to read numbers from the array and keep at-most K numbers at the top (According to… Read More »

Minimum Index Sum for Common Elements of Two Lists

Ram and Shyam want to choose a website to learn programming and they both have a list of favorite websites represented by strings. You need… Read More »

Find any one of the multiple repeating elements in read only array

Given a read only array of size ( n+1 ), find one of the multiple repeating elements in the array where the array contains integers… Read More »

Hash Table vs STL Map

This article focus on : Compare and contrast Hash table and an STL Map. How is the hash table implemented? If the number of inputs… Read More »

All unique triplets that sum up to a given value

Given an array and a sum value, find all possible unique triplets in that array whose sum is equal to the given sum value. If… Read More »

Minimum insertions to form a palindrome with permutations allowed

Given a string of lowercase letters. Find minimum characters to be inserted in string so that it can become palindrome. We can change positions of… Read More »

Find four elements that sum to a given value | Set 3 (Hashmap)

Given an array of integers, Check if there exist four elements at different indexes in the array whose sum is equal to a given value… Read More »

Count quadruples from four sorted arrays whose sum is equal to a given value x

Given four sorted arrays each of size n of distinct elements. Given a value x. The problem is to count all quadruples(group of four numbers)… Read More »

Count pairs from two linked lists whose sum is equal to a given value

Given two linked lists(can be sorted or unsorted) of size n1 and n2 of distinct elements. Given a value x. The problem is to count… Read More »

Nuts & Bolts Problem (Lock & Key problem) | Set 2 (Hashmap)

Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Match… Read More »

Count number of triplets with product equal to given number

Given an array of distinct integers(considering only positive numbers) and a number ‘m’, find the number of triplets with product equal to ‘m’. Examples: Input… Read More »

Second most repeated word in a sequence

Given a sequence of strings, the task is to find out the second most repeated (or frequent) string in the given sequence.(Considering no two words… Read More »