🚀 Day 35 of #100DaysOfDSA (Java) Today I explored Hashing, one of the most important concepts in Data Structures for efficient problem solving. Topics covered: 🔹 Introduction to Hashing 🔹 HashMap and HashSet in Java 🔹 Understanding key-value storage 🔹 Handling collisions (basic idea) 🔹 Frequency counting using HashMap 🔹 Common problems using Hashing Key takeaway: Hashing helps reduce time complexity significantly by enabling constant time (O(1)) operations for search, insert, and delete (on average). Also realized how powerful HashMap and HashSet are for solving problems related to duplicates, frequency, and lookups. Day 35 ✅ Leveling up problem-solving with faster approaches. #DSA #Java #Hashing #HashMap #HashSet #DataStructures #100DaysOfCode #ProblemSolving #DeveloperJourney #LearningInPublic
Mohammed Kaif’s Post
More Relevant Posts
-
Today I finally learned something I had been using for years: How HashMap actually works internally in Java I have used HashMap many times in coding, DSA, and projects but today I went beyond syntax and understood the internals. Key Learnings: ✅ HashMap stores data in **key-value pairs** ✅ Internally it uses an **array of buckets** ✅ When we insert data: * `hashCode()` of key is calculated * Bucket index is found * Data is stored in that bucket ✅ If two keys go to same bucket → **Collision Handling** Earlier via Linked List, modern Java can convert long chains into **Red-Black Trees** ✅ During retrieval: * `hashCode()` finds the bucket * `equals()` finds the exact key Biggest Realization: I was using HashMap for years, but understanding *why it gives near O(1) performance* and *how collisions are managed* made the concept much more powerful. Sometimes we know how to use a tool, but learning how it works internally changes our confidence completely. Learning Mindset: Syntax helps you code. Internals help you think like an engineer. #Java #CoreJava #HashMap #Programming #SoftwareEngineering #CodingInterview #Developers #DSA #LearningJourney #JVM
To view or add a comment, sign in
-
-
Your HashSet bug might not be a collection problem… it might be your equals() and hashCode(). 🚨 I’ve seen this happen in real projects: Two objects look identical. Same values. Same business meaning. But Java treats them as completely different. Why? 👇 Because equals() and hashCode() were not implemented correctly. The result: → Duplicate entries in HashSet → Failed lookups in HashMap → Strange behavior in caching → Unexpected JPA/Hibernate issues What I always remember 👇 ✔ If two objects are equal using equals(), they MUST have the same hashCode() ✔ Override both together — never just one ✔ Base equality on meaningful business fields, not random mutable values One wrong implementation can create bugs that are painful to trace. Especially when everything “looks correct.” Java collections trust your contract. Break it… and production will remind you. Have you ever debugged an equals()/hashCode() issue? 👇 #Java #HashMap #HashSet #OOP #BackendDevelopment #SoftwareEngineering #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 04/60 of My Consistency Challenge – Mastering Java Map Implementations Today I explored three core Map implementations in the Java Collection Framework: 🔹 HashMap 🔹 LinkedHashMap 🔹 TreeMap This infographic clearly highlights their internal working, performance, ordering behavior, null handling, and real-world use cases. 💡 Key Takeaways: ✔️ HashMap Stores data using hashing (bucket structure) Provides O(1) average time complexity Does not maintain order Allows one null key and multiple null values Best for fast retrieval and general-purpose usage ✔️ LinkedHashMap Maintains insertion order using a linked structure Slight overhead compared to HashMap Supports predictable iteration order Commonly used in caching (LRU Cache implementation) ✔️ TreeMap Stores data in sorted order (Red-Black Tree) Provides O(log n) performance Does not allow null keys Supports natural ordering or custom Comparator Ideal for sorted data, range queries, and navigation ⚡ Key Insight: Choosing between these is not just about storing data — it’s about balancing performance, ordering, and business requirements. 🧠 This understanding helps in: Writing optimized backend logic Designing scalable systems Cracking Java & DSA interviews 📌 Consistency + Clarity = Growth #Java #CollectionsFramework #HashMap #LinkedHashMap #TreeMap #DataStructures #JavaDeveloper #BackendDevelopment #CodingJourney #LearnInPublic #SoftwareEngineering #DSA #TechCareers #Programming #Consistency
To view or add a comment, sign in
-
-
Day 2/30 of #30DaysOfDSA 🔹 Problem: Two Sum 💡 Approach: I first thought of a brute-force approach. I checked all possible pairs using two loops and returned the indices where the sum equals the target. This works fine but takes O(n²) time. Then I optimized the solution using HashMap. Instead of checking every pair, I stored each element with its index in a HashMap. For every element, I calculated the complement (target - current value) and checked if it already exists in the map. This reduced the time complexity to O(n) and made the solution more efficient. ⚡ What I Learned: I learned how to optimize a problem by reducing unnecessary comparisons. Using HashMap helps achieve faster lookups and improves time complexity significantly. #DSA #Coding #Consistency #Java
To view or add a comment, sign in
-
-
I used to think HashMap and ConcurrentHashMap were almost the same — until I started learning multithreading properly. In Java, choosing the right data structure matters a lot, especially in concurrent applications. Here’s what I understood: 1. HashMap is not thread-safe 2. ConcurrentHashMap allows multiple threads to work without locking the entire map 3. It improves performance in multi-threaded environments Small concepts like this make a big difference when building scalable backend systems. Still learning something new every day. Java developers — when do you prefer using ConcurrentHashMap over HashMap? #Java #Multithreading #ConcurrentHashMap #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
🚀 LeetCode Challenge 13/50 💡 Approach: Bidirectional HashMap Mapping One HashMap isn't enough here! If we only map s → t, we miss cases where two different characters in s map to the same character in t. The trick is to maintain mappings in BOTH directions simultaneously! 🔍 Key Insight: → Map every character of s to its corresponding character in t → Also map every character of t back to s → If either mapping is inconsistent at any point → return false → Both directions must agree throughout the string 📈 Complexity: ✅ Time: O(n) — single pass through both strings ✅ Space: O(1) — at most 256 unique ASCII characters in the maps Isomorphic strings taught me that in problem solving, perspective matters — always check both sides of the equation! 🔄 #LeetCode #DSA #HashMap #Java #ADA #PBL2 #LeetCodeChallenge #Day13of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #IsomorphicStrings
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟕𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on detecting duplicates within a given index range. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Contains Duplicate II --- 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐇𝐚𝐬𝐡𝐌𝐚𝐩 • Stored each number with its latest index • For every element: • Checked if it already exists in the map • If yes → verified index difference ≤ k • Updated index to keep the most recent occurrence --- 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Storing indices helps solve range-based problems • HashMap enables O(1) lookup • Updating latest index ensures correctness • Small constraints can change the approach --- 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(n) --- 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Adding constraints doesn’t always make problems harder — it often makes them more interesting to solve. --- 73 days consistent 🚀 On to Day 74. #DSA #Arrays #HashMap #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟖𝟑/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐌𝐢𝐧𝐢𝐦𝐮𝐦 𝐃𝐢𝐬𝐭𝐚𝐧𝐜𝐞 𝐁𝐞𝐭𝐰𝐞𝐞𝐧 𝐓𝐡𝐫𝐞𝐞 𝐄𝐪𝐮𝐚𝐥 𝐄𝐥𝐞𝐦𝐞𝐧𝐭𝐬 𝐈𝐈 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Store indices of each value using a HashMap. For values appearing at least 3 times, check consecutive triplets of indices. Compute distance using the formula: |i-j| + |j-k| + |i-k| Track the minimum distance. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: HashMap + sliding window on index lists. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Grouping indices by value can drastically reduce complexity in duplicate-based problems. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #HashMap #Arrays #Optimization #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
🚀 Day 03/60 of My Consistency Challenge – Java Collection Framework Deep Dive Today I explored the differences between three important Set implementations in Java: 🔹 TreeSet 🔹 HashSet 🔹 LinkedHashSet This infographic breaks down their internal working, performance, ordering behavior, and real-world use cases in a clear and structured way. 💡 What I Learned: ✔️ TreeSet Maintains sorted order (natural/comparator) Uses Red-Black Tree internally Best for scenarios like sorted data, range queries, navigation ✔️ HashSet Uses hashing (HashMap internally) Provides O(1) performance for basic operations Best for fast lookups of unique elements ✔️ LinkedHashSet Maintains insertion order Combines HashSet + Linked structure Useful when order matters along with uniqueness ⚡ Key Insight: Choosing the right data structure is not just about storing data — it's about performance, ordering, and use case optimization. 🧠 Understanding these differences helps in: Writing efficient backend logic Cracking technical interviews Designing scalable systems 📌 Small improvements daily → Big results over time. #Java #CollectionsFramework #DataStructures #JavaDeveloper #SoftwareEngineering #CodingJourney #LearnInPublic #BackendDevelopment #DSA #TechGrowth #Consistency
To view or add a comment, sign in
-
-
🚀 Java Full Stack Journey – Day 33 Today I dived deeper into Java Collections and explored the Set & Map Interfaces, along with their internal working. This session helped me move beyond just using collections to actually understanding what happens behind the scenes — which is crucial for writing efficient and optimized code. ✨ Key takeaways from today: ✔️ Difference between Set and Map ✔️ How HashSet stores only unique elements using hashing ✔️ Internal structure of HashMap (Buckets, Hashing, Collisions) ✔️ Collision handling techniques (LinkedList → Balanced Tree in Java 8+) ✔️ How TreeMap maintains sorted order using Red-Black Tree ✔️ Performance comparison between HashMap, HashSet, and TreeMap 💡 What I understood: Choosing the right data structure is not just about functionality, but also about performance and scalability. Knowing internal working makes a big difference in real-world applications. Big thanks to CoderArmy, Aditya Tandon, and Rohit Negi for simplifying these complex concepts 🙌 Step by step, improving my problem-solving skills and moving closer to becoming a Java Full Stack Developer 💻🔥 #Day33 #Java #JavaCollections #HashMap #HashSet #TreeMap #FullStackDevelopment #DataStructures #CodingJourney #DeveloperGrowth
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development