Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new empty bucket (linked list) at the given index.
DSA Javascript
if (!this.buckets[index]) { this.buckets[index] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using an array [] instead of a linked list.
Setting the bucket to null or an empty object {}.
✗ Incorrect
We use a linked list to handle collisions by chaining, so we create a new LinkedList at the bucket index.
2fill in blank
mediumComplete the code to add a key-value pair to the linked list at the bucket index.
DSA Javascript
this.buckets[index].[1]({ key, value });Attempts:
3 left
💡 Hint
Common Mistakes
Using find or update which do not add new nodes.
Using remove which deletes nodes.
✗ Incorrect
We append the new key-value pair to the linked list to handle collisions by chaining.
3fill in blank
hardFix the error in the code to find a node with the matching key in the linked list.
DSA Javascript
const node = this.buckets[index].find(node => node.key [1] key);Attempts:
3 left
💡 Hint
Common Mistakes
Using single = which assigns instead of compares.
Using == which is loose equality and can cause bugs.
✗ Incorrect
Use strict equality === to correctly compare keys in JavaScript.
4fill in blank
hardFill both blanks to update the value if the key exists, or append a new node if it does not.
DSA Javascript
if (node) { node.value = [1]; } else { this.buckets[index].[2]({ key, value }); }
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning key instead of value in the update.
Using remove instead of append to add new nodes.
✗ Incorrect
If the node exists, update its value. Otherwise, append a new node with the key and value.
5fill in blank
hardFill all three blanks to remove a key-value pair from the linked list at the bucket index.
DSA Javascript
const removed = this.buckets[index].[1](node => node.key [2] [3]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using find instead of remove to delete nodes.
Using loose equality or assignment operators.
✗ Incorrect
Use remove method with a callback that checks if node.key strictly equals the key to remove.
