Java: Design HashSet

Level : Intermediate
Mentor: Amit Kumar Ghosh
Type : GuidedLab
Points : 10
Duration : 00:25:00

Lab Details

Difficulty Level: EASY

Problem Statement:

Design and implement a HashSet without using any built-in hash table libraries.

  • ‘add(key)’: Insert a value into the HashSet.
  • ‘remove(key)’: Remove a value from the HashSet if it exists.
  • ‘contains(key)’: Return whether the value exists in the HashSet or not.

Example Usage:

MyHashSet hashSet = new MyHashSet();

     hashSet.add(1);

     hashSet.add(2);

     hashSet.contains(1); // returns true

     hashSet.contains(3); // returns false (not found)

     hashSet.add(2);

     hashSet.contains(2); // returns true

     hashSet.remove(2);

     hashSet.contains(2); // returns false (already removed)

Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this