Conversation
Implement Hash Set (705DesignHashSet.js)Your approach shows understanding of double hashing, but there are critical issues to address:
Suggested correction for initialization and add method: var MyHashSet = function () {
this.size = 1000;
this.buckets = new Array(this.size);
};
MyHashSet.prototype.hash1 = function (key) {
return key % this.size;
};
MyHashSet.prototype.hash2 = function (key) {
return Math.floor(key / this.size);
};
MyHashSet.prototype.add = function (key) {
const h1 = this.hash1(key);
const h2 = this.hash2(key);
if (this.buckets[h1] === undefined) {
// Determine the size of the secondary array
const secondarySize = h1 === 0 ? this.size + 1 : this.size;
this.buckets[h1] = new Array(secondarySize).fill(false);
}
this.buckets[h1][h2] = true;
};Then, in VERDICT: NEEDS_IMPROVEMENT Implement Min Stack (155MinStack.js)Your solution is well-structured and meets all the problem requirements. Here are some strengths and minor suggestions: Strengths:
Areas for improvement:
Overall, your solution is excellent. VERDICT: PASS |
No description provided.