# Category Archives: Hash

## Longest subarray having difference in the count of 1’s and 0’s equal to k

Given a binary array arr[] of size n and a value k. The task is to find the length of the longest subarray having difference… Read More »

## Queries to check if it is possible to join boxes in a circle

Consider n boxes numbered arranged in a circle in increasing order in clockwise direction (numbered from 1 to n). You are given q queries, each… Read More »

## For each element in 1st array count elements less than or equal to it in 2nd array | Set 2

Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in… Read More »

## Count elements that are divisible by at-least one element in another array

Given two arrays arr1[] and arr2[]. The task is to find the count of such elements in the first array whose at-least one factor is… Read More »

Prerequisites: Hashing Introduction and Collision handling by separate chaining How hashing works: For insertion of a key(K) – value(V) pair into a hash map, 2… Read More »

## Minimum array element changes to make its elements 1 to N

Suppose you are given an array with N elements with any integer values. You need to find the minimum number of elements of the array… Read More »

## Distinct Prime Factors of Array Product

Given an array of integers.Let us say P is the product of elements of the array. Find the number of distinct prime factors of product… Read More »

## Hashing in Java

In hashing there is a hash function that maps keys to some values. But these hashing function may lead to collision that is two or… Read More »

## Longest subarray having maximum sum

Given an array arr[] containing n integers. The problem is to find the length of the subarray having maximum sum. If there exists two or… Read More »

## Numbers with sum of digits equal to the sum of digits of its all prime factor

Given a range, the task is to find the count of the numbers in the given range such that the sum of its digit is… Read More »

## HashSet vs TreeSet in Java

Speed and internal implementation HashSet : For operations like search, insert and delete. It takes constant time for these operations on average. HashSet is faster… Read More »

## Check if the first and last digit of the smallest number forms a prime

Given an array arr[] containing numbers from 0 to 9 only, the task is to form the minimum possible number from the given digits and… Read More »

## Preorder from Inorder and Postorder traversals

Given Inorder and Postorder traversals of a binary tree, print Preorder traversal. Example: Input: Postorder traversal post[] = {4, 5, 2, 6, 3, 1} Inorder… Read More »

## Majority element in a circular array of 0’s and 1’s

Given a circular array containing only 0’s and 1’s, of size n where n = p*q (p and q are both odd integers). The task… Read More »

## Elements that occurred only once in the array

Given an array arr that has numbers appearing twice or once. The task is to identify numbers that occurred only once in the array. Note:… Read More »