You are using an outdated browser. Please update your browser for a better user experience.

Design HashMap

hashing

Design a HashMap without using any built-in hash table libraries.

To be specific, your design should include these functions:

  • put(key, value) : Insert a (key, value) pair into the HashMap. If the value already exists in the HashMap, update the value.
  • get(key): Returns the value to which...

N-Repeated Element in Size 2N Array

hashing

In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times.

Return the element that is repeated N times.

Example 1:

Input: [1,2,3,3]
Output: 3

In example 1, there are 3 unique elements, so we return the 3 since it's repeated 2 times.

E...

Subarray with 0 sum

hashing

Given an array of integers, check if array contains a sub-array having 0 sum.

Input: {3,4,-7,3,1,3,1,-4,-2,-2}

Output: Sub-array with 0 sum exists

The sub-arrays with a sum of 0 are:

{3,4,-7}

{4,-7,3}

{-7,3,1,3}

{3,1,-4}

{3,1,3,1,-4,-2,-2}

{3,4,-7,3,1,3,1,-4,-2,-2}

The prob...