🚀 Day 64 of #100DaysOfCode Today, I solved LeetCode 290 – Word Pattern, a problem that focuses on pattern matching and mapping relationships. 💡 Problem Overview: Given a pattern and a string, the task is to determine if the string follows the same pattern, ensuring a one-to-one mapping between characters in the pattern and words in the string. 🧠 Approach: To solve this problem efficiently, I focused on: ✔️ Using a hashmap to map pattern characters to words ✔️ Ensuring a bijection (one-to-one mapping) between pattern and words ✔️ Validating consistency throughout the traversal This approach ensures correctness while maintaining simplicity. ⚡ Key Takeaways: Hashmaps are powerful for mapping relationships Ensuring bijection is crucial in pattern problems Clean validation logic avoids edge-case errors 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Building strong fundamentals one problem at a time 🚀 #LeetCode #100DaysOfCode #DSA #HashMap #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
Solving LeetCode 290 Word Pattern with HashMap
More Relevant Posts
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 216 of #300DaysOfCoding 💡 Solved: Minimum Absolute Distance Between Mirror Pairs (LeetCode 3761) Today’s problem was a great mix of hashing + number manipulation that tested both logic and attention to detail. 🔍 Problem Summary: Given an array, find the minimum distance between indices (i, j) such that: 👉 reverse(nums[i]) == nums[j] and i < j ⚡ Key Insight: Instead of checking all pairs (which would be O(n²)), we optimize using a HashMap. Store reversed values while iterating Check if the current number already exists in the map Update the minimum distance 🧠 What I Learned: Direction of logic matters a lot in hashing problems Small mistakes in mapping can lead to wrong answers Always dry run edge cases like [120, 21] ⏱️ Complexity: Time: O(n) Space: O(n) 🔥 Takeaway: Efficient problem solving is not just about knowing concepts, but applying them in the right direction. Consistency is the real game changer — showing up every single day 💯 #LeetCode #DSA #CodingJourney #PlacementPreparation #SoftwareEngineering #HashMap #ProblemSolving #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 78 of #100DaysOfCode Today, I solved LeetCode 154 – Find Minimum in Rotated Sorted Array II, a problem that focuses on binary search and handling edge cases with duplicates. 💡 Problem Overview: Given a rotated sorted array that may contain duplicates, the goal is to find the minimum element efficiently. 🧠 Approach: ✔️ Applied modified binary search ✔️ Compared mid element with the right boundary ✔️ Carefully handled duplicate values to avoid incorrect elimination of search space This approach ensures correctness even when duplicates are present. ⚡ Key Takeaways: Binary search can be adapted for complex scenarios Duplicates introduce edge cases that must be handled carefully Choosing the correct condition is key to narrowing the search space 📊 Complexity Analysis: Time Complexity: O(log n) (average), O(n) (worst case due to duplicates) Space Complexity: O(1) Strengthening problem-solving with optimized approaches 🚀 #LeetCode #100DaysOfCode #DSA #BinarySearch #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 79 of #100DaysOfCode Today, I solved LeetCode 32 – Longest Valid Parentheses, a challenging problem that focuses on stack-based logic and string processing. 💡 Problem Overview: Given a string containing only '(' and ')', the goal is to find the length of the longest valid (well-formed) parentheses substring. 🧠 Approach: ✔️ Used a stack-based approach to track indices ✔️ Initialized stack with -1 to handle edge cases ✔️ For every closing bracket, popped from stack ✔️ Calculated valid substring length using current index and stack top This approach efficiently tracks valid sequences and avoids reprocessing. ⚡ Key Takeaways: Stack is powerful for handling matching problems Index-based tracking simplifies substring calculations Handling edge cases (like invalid starting brackets) is crucial 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Solving hard problems step by step and improving every day 🚀 #LeetCode #100DaysOfCode #DSA #Stack #Strings #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep #HardProblems
To view or add a comment, sign in
-
-
Day 105 of #200DaysOfCode Leveling up Consistency is turning into strength. Today I solved "Top K Frequent Elements" on LeetCode using a Min Heap + HashMap approach. Key Idea: Instead of sorting all elements by frequency, we maintain a heap of size k to efficiently track the top k frequent elements. Approach: • Use a hash map to count frequencies • Use a min heap (size k) to store {frequency, element} • If heap size exceeds k remove the least frequent • Remaining elements in heap = top k frequent Concepts Used: • HashMap (unordered_map) • Heap / Priority Queue • Top K Pattern Time Complexity: O(n log k) Space Complexity: O(n) Takeaway: Using a min heap of size k is a powerful optimization over full sorting when dealing with frequency-based problems. Small improvements daily = Big results over time Let’s keep going #Day105 #200DaysOfCode #LeetCode #Heap #HashMap #Cpp #CodingJourney #ProblemSolving #KeepGoing
To view or add a comment, sign in
-
-
🔥 Day 171 of My LeetCode Journey Problem 112: Path Sum 💡 Problem Insight: Today’s problem was about checking whether a binary tree has a root-to-leaf path whose sum equals a target value. The key detail here is root-to-leaf — not any path. Missing that leads to wrong answers. 🧠 Concept Highlight: The solution is a clean use of DFS (recursion): Subtract the current node’s value from the target Move to left and right subtrees When you reach a leaf, check if the remaining sum is zero This ensures you explore all valid paths without unnecessary work. 💪 Key Takeaway: Tree problems often reduce to accumulating state along a path. Instead of storing paths, update the condition as you traverse. ✨ Daily Reflection: This problem reinforced how recursion naturally fits tree traversal. Once you think in terms of paths and state, the solution becomes straightforward. #Day171 #LeetCode #BinaryTree #DFS #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 73 of #100DaysOfCode 💻 Problem 39: Combination Sum ✅ Successfully solved on LeetCode! 🔍 Problem Summary: Given an array of distinct integers candidates and a target integer target, return all unique combinations where the chosen numbers sum to target. You can use the same number unlimited times. 🧠 Approach (Backtracking): • Explore all possible combinations recursively • Stop when sum exceeds target (pruning) • Store valid combinations when target becomes 0 • Reuse same element to allow unlimited picks ⚡ Key Insight: Backtracking helps efficiently generate combinations while avoiding unnecessary computations using pruning. 💡 What I Learned: • Strong grip on recursion + backtracking • How to reduce search space using pruning • Writing clean and optimized recursive solutions 🔥 73 days strong — consistency is paying off! #Day73 #100DaysOfCode #LeetCode #DSA #Backtracking #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 12 of #LeetCode Top Interview 150 Just solved LeetCode 380 – Insert Delete GetRandom O(1) 💻 This problem really tested my understanding of data structures + optimization. The challenge was to design a system that supports insert, delete, and random access — all in constant time O(1). 🔑 Key Learnings: Combining HashMap + Dynamic Array (vector) for efficiency Smart use of index mapping to handle deletions in O(1) Understanding how to balance time vs space complexity Writing clean and optimized logic under constraints ⚡ Result: ✅ All test cases passed ⏱ Runtime: 32 ms (Beats 91.12%) 💾 Memory optimized Every day I’m getting better at breaking down problems and thinking in terms of optimal solutions, not just working ones. Consistency is slowly turning into confidence 💪 #Day12 #LeetCode #DSA #CodingJourney #100DaysOfCode #ProblemSolving #Cpp #TechGrowth #WomenInTech
To view or add a comment, sign in
-
-
🔥 Day 173 of My LeetCode Journey Problem 113: Path Sum II 💡 Problem Insight: Today’s problem extends Path Sum — instead of just checking existence, you must return all root-to-leaf paths whose sum equals the target. This shift from a Boolean list makes the problem more complex. 🧠 Concept Highlight: The solution uses DFS + backtracking: Traverse the tree while maintaining the current path Subtract node values from the target sum When a valid leaf is reached, store the path Backtrack to explore other possibilities Backtracking is essential to avoid mixing paths. 💪 Key Takeaway: Whenever a problem asks for all possible paths/combinations, backtracking is the go-to technique. Managing state correctly is more important than traversal itself. ✨ Daily Reflection: This problem reinforced the need for discipline when storing results. Without proper backtracking, solutions become incorrect quickly. #Day173 #LeetCode #BinaryTree #DFS #Backtracking #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 43 | 100 Days of Coding Challenge #DrGViswanathanChallenge 📘 Problem Solved: LFU Cache (LeetCode - Hard) 🔧 Approach Used (HashMap + Doubly Linked List + Frequency Mapping): • Stored {key → (value, frequency)} using hashmap • Maintained freq → list of keys to track LRU within same frequency • Used another hashmap to store iterators for O(1) deletion • On every get/put, updated frequency and moved key accordingly • Removed Least Frequently Used and Least Recently Used key when capacity exceeded 📌 Key Idea: Combine frequency tracking + LRU policy to maintain correct eviction order in O(1). ⏳ Complexity: Time: O(1) for both get & put Space: O(n) 🧠 Key Learning: Design problems require combining multiple data structures efficiently — here hashmap + list + frequency mapping. 💡 Optimization Insight: Maintaining a minFreq variable helps quickly identify which keys to evict. 📂 Topics Covered: Design, HashMap, Doubly Linked List, LRU, LFU Cache 📊 Example Insight: When two keys have same frequency → remove the least recently used among them. 🔥 One of the toughest design problems — great learning on writing optimized real-world systems! #100DaysOfCode #DSA #CPP #LeetCode #CodingJourney #SystemDesign #CompetitiveProgramming
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