How to find the first unique character in a string using HashMap in Java

🚀 Day 14 — Data Structures & Algorithms in Java 🔹 Topic: First Unique Character in a String (Using HashMap) Today, I explored how to identify the first non-repeating character in a given string using HashMap — an efficient and flexible approach that works for all character types. 💡 Concept We store each character’s frequency in a HashMap, then find the first index with frequency 1. 🧠 Example 📥 Input: "loveleetcode" 📤 Output: 2 (Character 'v' is the first unique one) ⚙️ Complexity ⏱ Time: O(n) 💾 Space: O(n) ✨ Key Takeaway HashMaps are incredibly powerful for frequency-based problems — offering both simplicity and efficiency in solving string and array challenges. #Java #Coding #30DaysOfCode #LeetCode #DSA #ProblemSolving #LearningJourney #WomenInTech #1000coders

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories