Designing a HashSet without built-in libraries for LeetCode 705

📌 Day 17/100 - Design HashSet (LeetCode 705) 🔹 Problem: Design a HashSet without using built-in hashing libraries. Support add(key), remove(key), and contains(key) efficiently. 🔹 Approach: Used a boolean array where the index directly maps to the key. This gives O(1) access to mark presence or absence: add(key) → arr[key] = true remove(key) → arr[key] = false contains(key) → return arr[key] 🔹 Time Complexity: O(1) for add, remove, and contains 🔹 Space Complexity: O(N), where N is the range of possible keys (e.g., 1,000,001) 🔹 Key Learnings: Simple data representations can be the most performant for bounded key ranges. Always consider time vs memory trade-offs when designing data structures. Recreating core data structures reinforces how built-ins work under the hood. #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #HashSet #CodingJourney

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories