Java HashMap Word Pattern Challenge

100 Days of Coding Challenge – Day 21 📌 Problem: Word Pattern 💻 Language: Java 🧠 Concept Used: HashMap + String Mapping 🔍 Platform: LeetCode A valid pattern means there must be a one-to-one mapping (bijection) between characters in the pattern and words in the string. In other words: • Each pattern character maps to exactly one unique word • Each word maps to only one pattern character Example: pattern = "abba" s = "dog cat cat dog" → ✅ true Approach: ✔ Split the string into words using split(" ") ✔ Use a HashMap to map pattern characters to words ✔ Ensure no two characters map to the same word ✔ Verify consistency during traversal Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem Link: https://lnkd.in/grDzg_82 🔗 Code: https://lnkd.in/gA9CCyc5 #100DaysOfCode #Day21 #Java #DSA #LeetCode #HashMap #Strings #ProblemSolving #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories