Solved LeetCode 290 Word Pattern with Python

Day 58/100 – #100DaysOfCode 🚀 Solved LeetCode #290 – Word Pattern (Python). Today I practiced hashmap (dictionary) and string manipulation to check whether a pattern matches a given string. Approach: 1) Split the string into words. 2) Check if the length of pattern and words list is equal. 3) Use two hashmaps to maintain mapping:   - character → word   - word → character 4) Traverse both together using zip(). 5) Ensure mapping consistency in both directions. 6) If any mismatch occurs, return False; otherwise return True. Time Complexity: O(n) Space Complexity: O(n) Understanding bidirectional mapping helps solve pattern-matching problems 💪 #LeetCode #Python #DSA #HashMap #Strings #ProblemSolving #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories