Skip to main content
added 2 characters in body; edited title
Source Link
Blackbam
  • 19.7k
  • 31
  • 112
  • 167

why Why would someone use Array over hashmap even whenHashMap if the situation allows us to dofor HashMap?

I was reading thea solution here (https://leetcode.com/problems/longest-substring-without-repeating-characters/solution/).They say that in normal cases when we havethere is no idea about key's (character's) range we use hash maphashmap. And

And there is another solution which says that when we are particular about the character set we can use array instead.

The previous implements all have no assumption on the charset of the string s. If we know that the charset is rather small, we can replace the Map with an integer array as direct access table. Commonly used tables are: int[26] for Letters 'a' - 'z' or 'A' - 'Z' int[128] for ASCII int[256] for Extended ASCII 

The previous implements all have no assumption on the charset of the string s.

If we know that the charset is rather small, we can replace the Map with an integer array as direct access table.

Commonly used tables are:

int[26] for Letters 'a' - 'z' or 'A' - 'Z' int[128] for ASCII int[256] for Extended ASCII 

Not only here, but also in several locations in Cracking the Coding interview book they use an array where the characters are keys by representing a character by the equivalent integer and storing the value at a corresponding location in that array.

Why would we struggle with array's when we have hashmap at our hand ? Is there any reason ?

why would someone use Array over hashmap even when situation allows us to do?

I was reading the solution here (https://leetcode.com/problems/longest-substring-without-repeating-characters/solution/).They say that in normal cases when we have no idea about key's (character's) range we use hash map. And there is another solution which says that when we are particular about the character set we can use array instead.

The previous implements all have no assumption on the charset of the string s. If we know that the charset is rather small, we can replace the Map with an integer array as direct access table. Commonly used tables are: int[26] for Letters 'a' - 'z' or 'A' - 'Z' int[128] for ASCII int[256] for Extended ASCII 

Not only here, but also in several locations in Cracking the Coding interview book they use array where the characters are keys by representing character by the equivalent integer and storing the value at corresponding location in array.

Why would we struggle with array's when we have hashmap at our hand ? Is there any reason ?

Why would someone use Array over HashMap if the situation allows for HashMap?

I was reading a solution here (https://leetcode.com/problems/longest-substring-without-repeating-characters/solution/).They say that in normal cases when there is no idea about key's (character's) range we use hashmap.

And there is another solution which says that when we are particular about the character set we can use array instead.

The previous implements all have no assumption on the charset of the string s.

If we know that the charset is rather small, we can replace the Map with an integer array as direct access table.

Commonly used tables are:

int[26] for Letters 'a' - 'z' or 'A' - 'Z' int[128] for ASCII int[256] for Extended ASCII 

Not only here, but also in several locations in Cracking the Coding interview book they use an array where the characters are keys by representing a character by the equivalent integer and storing the value at a corresponding location in that array.

Why would we struggle with array's when we have hashmap at our hand ? Is there any reason ?

Source Link

why would someone use Array over hashmap even when situation allows us to do?

I was reading the solution here (https://leetcode.com/problems/longest-substring-without-repeating-characters/solution/).They say that in normal cases when we have no idea about key's (character's) range we use hash map. And there is another solution which says that when we are particular about the character set we can use array instead.

The previous implements all have no assumption on the charset of the string s. If we know that the charset is rather small, we can replace the Map with an integer array as direct access table. Commonly used tables are: int[26] for Letters 'a' - 'z' or 'A' - 'Z' int[128] for ASCII int[256] for Extended ASCII 

Not only here, but also in several locations in Cracking the Coding interview book they use array where the characters are keys by representing character by the equivalent integer and storing the value at corresponding location in array.

Why would we struggle with array's when we have hashmap at our hand ? Is there any reason ?