JP Morgan Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

The HashMap gives you an unsorted, unordered Map. When you
need a Map and you don't care about the order (when you iterate through it), then
HashMap is the way to go; the other maps add a little more overhead. Where the
keys land in the Map is based on the key's hashcode, so, like HashSet, the more efficient
your hashCode() implementation, the better access performance you'll get.
HashMap allows one null key and multiple null values in a collection.

- Anonymous May 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Java a HashMap is a key value pair data structure that is not thread safe. A hashmap internally uses an array. This internal array contains Entry objects with fields that encapsulates the key, value and some other fields used internally by the hashmap. Hashmaps are generally used when you need to access data in constant time O(1) and order is not a concern when traversing the elements of the hashmap. Objects are stored in the hashmap using the key's hashcode to calculate the location in the hashmap. If an object already exist at a location where new object is to be inserted then a comparison is done on the two objects keys, hashvalue and equals is also called on the 2 keys to see if they are equal. If they are equal the old value is replaced with the new, if not the object is inserted into the hashmap.

- Jovaughn July 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

HashMap is data structure which provides constant time performance for get and put operation. It uses the hashing mechanism to identify of the key object. Hashing means assigning the number to object. During put operation key is used to store the object in 'hashtable(normally array)' for get operation key(object) is calculated from the key object. which provides O(1) time lookup

- monty January 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

HashMap is a data structure which stores data in the form of key-value pair.
A Hashmap is used implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found.

If we talk in terms of Space complexity and TimeComplexity.
It stores data the form of key-value, hence data can be inserted anywhere in memory location and based on key(which cannot be duplicated) value can be searched and deleted in constant time. Therefore,
In average case,

Space O(n)
Search, Insert, Delete O(1).

In Worst case,
Space O(n)
Search, Insert, Delete O(n).

In Java, Hashmap is a class used to implement Map(I).

The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

An instance of HashMap has two parameters that affect its performance: initial capacity and load factor.

- Utsav Parashar February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In java hashmap works on Key and value pair.Hashmap consists of hashtable.
An instance of Hashtable has two parameters that affect its performance: initial capacity and load factor.
The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created
The initial capacity is 16 and default load factor is 0.75.The threshold value come around 12.
When we call put method :
put<K,V>
then the hashcode is generated for the key and then it will call the hash function to get the index value in the range of hash bucket and value is getting stored at that particular generated index.If the hashcollision happens then equals come in to the picture and will check the hashcode and if it is same then will override the value or else create the linklist and shift the original value to next and stored in first.
The hashbucket contain the <K, V, hascode, next pointer>

When we call get method:
get<k> then the hashcode is generated for the key and then it will call the hash function to get the index value in the range of hash bucket.
If the entry is null then it will return null or else will check with K key with equals method and if found return the value.

Hashmap follows one thumb rule:
if two values are equals means the hashcode will be same but the vise-versa is not applicable.

- pankajpimpalkar1989 November 03, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More