# Category: Hash Table

## Find two elements whose sum is closest to zero

Objec­tive: Given an array of pos­i­tive and neg­a­tive inte­gers, write a algo­rithm to find the two ele­ments such their sum is clos­est to zero. Exam­ple: int a [] = {1, 4, –5, 3, –2, 10,…

## Find the element which appears maximum number of times in the array.

Objec­tive: Given an array of inte­gers, write a algo­rithm to find the ele­ment which appears max­i­mum num­ber of times in the array. Exam­ple: int [] arrA = {4, 1, 5, 2, 1, 5, 9, 8,…

## Find duplicates in an given array in O(n) time and O(1) extra space.

Objec­tive: Given an array of inte­gers, find out dupli­cates in it. Exam­ple: int [] a = {4, 6, 2, 1, 2, 5}; Out­put: Array has dupli­cates : 2 int a [] = {1, 6, 5,…

## Find the last non repeating character in a given string.

Objec­tive: Given a string, write an algo­rithm to find the last non repeat­ing char­ac­ter in it. Exam­ple: String input = “algo­rithms tuto­ri­als” Out­put: ‘u’ String input = “aab­bc­cdd” Out­put: No repeat­ing char­ac­ter found. Approach: Naive…

## Find the last repeating character in a given string.

Objec­tive: Given a string, write an algo­rithm to find the last repeat­ing char­ac­ter in it. Exam­ple: String input = “hori­zon tuto­ri­als” Out­put: ‘i’ String input = “algo­rithms” Out­put: No repeat­ing char­ac­ter found. Approach: Naive approach:…

## The Word Break Problem

Objec­tive : Given an string and a dic­tio­nary of words, find out if the input string can be bro­ken into a space-separated sequence of one or more dic­tio­nary words. Exam­ple: dic­tio­nary = [“I” , “have”,…

## Find Whether Two Strings are Permutation of each other

Objec­tive: Given Two Strings, check whether one string is per­mu­ta­tion of other Input: Two Strings Out­put: True or false based on whether strings are per­mu­ta­tion of other or not. Exam­ple: “sumit” and “tiums” are per­mu­ta­tions of…

## Hash Table Implementation

Objec­tive : To imple­ment a Hash Table Input:  A set of pairs of keys and val­ues Approach: Cre­ate a Hash Table Hashtable<Integer, String> ht = new Hashtable<Integer, String>(); Insert val­ues in hash table using put(key,value)…