🚀 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
Minimum Absolute Distance Between Mirror Pairs in Array
More Relevant Posts
-
🔥 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 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
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 37/75 Solved Path Sum III (LeetCode 437) today! 🌳 ✅ All 130/130 test cases passed ⚡ Runtime: 7 ms (Beats ~59%) 💾 Memory: 18.94 MB (Beats ~76%) 🔍 Approach: Used DFS (recursion) to explore all possible paths in the binary tree. ✔️ For each node, calculated cumulative sum along the path ✔️ Checked if the current sum matches the target ✔️ Started fresh DFS from every node to cover all paths ✔️ Counted all valid paths where sum equals target This ensures we consider every possible path efficiently. 💡 Key Learning: Tree problems often require exploring every node as a starting point. Combining recursion with careful state tracking makes solutions more effective. Consistency + practice = better problem solving 🚀 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
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
-
-
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
-
-
🚀 LeetCode Day Problem Solving 🚀 Day-45 📌 Problem: Given an array nums[], find a good tuple (i, j, k) such that: ✔ nums[i] == nums[j] == nums[k] ✔ i < j < k 👉 Distance of tuple = |i - j| + |j - k| + |k - i| 🎯 Return the minimum possible distance among all such tuples ❌ If no valid tuple exists → return -1 🧠 Example: Input: nums = [1,2,1,1,3] ✅ Output: 6 📖 Explanation: Tuple → (0, 2, 3) Distance = 2 + 1 + 3 = 6 💡 Key Insight: ✔ For same values, indices matter ✔ Distance simplifies to: 👉 2 * (k - i) (since i < j < k) ✔ So we just need: 👉 Closest 3 indices of same number ⚡ Optimized Approach: ✔ Use HashMap / Array of lists to store indices ✔ For each value: 👉 Traverse indices and check every consecutive triplet 📊 Complexity Analysis: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 🧠 What I Learned: ✔ Pattern observation simplifies formula ✔ Grouping indices using hashmap ✔ Optimization by avoiding brute force O(n³) ✅ Day 45 Completed 🚀 Leveling up in Arrays + Optimization + Math Tricks 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency #MilanSahoo 🚀
To view or add a comment, sign in
-
-
LeetCode Progress 44/50 — Find the Index of the First Occurrence in a String Today I worked on a fundamental problem focused on string searching and pattern matching 🧩 💡 The challenge was to find the first occurrence of a pattern string inside a larger string. 🧠 Approach: Used a sliding window / direct substring comparison approach to check each possible starting position and identify where the pattern matches. ⏱ Time Complexity: O(n * m) (basic approach) 💡 What I learned: This problem helped me understand how brute force string matching works and built a base for more advanced algorithms like KMP in the future. 📈 Strengthening fundamentals of strings and improving pattern matching logic step by step. #LeetCode #DSA #Strings #PatternMatching #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 #LeetCode Day Problem Solving 🚀 Day-35 📌 Problem: You are given two arrays source[] and target[], along with a list of allowed swaps between indices. 👉 You can swap elements in source[] using the allowed pairs any number of times. 🎯 Goal: Minimize the Hamming Distance between source and target. 📌 Hamming Distance = Number of positions where source[i] ≠ target[i] 🛠 Key Idea: ✔ Swaps create connected components (groups) ✔ Within a group, elements can be rearranged freely ✔ So, match as many elements as possible with target 🧠 Approach: ✔ Use Disjoint Set (Union-Find) to group indices ✔ For each group: 👉 Count frequency of elements in source 👉 Try to match with target 👉 Reduce mismatches 💡 Example: Input: source = [1,2,3,4] target = [2,1,4,5] allowedSwaps = [[0,1],[2,3]] ✅ After swaps → [2,1,4,3] ❌ Only 1 mismatch → Answer = 1 📊 Complexity Analysis: ⏱ Time Complexity: O(n α(n)) (Union-Find) 📦 Space Complexity: O(n) 🧠 What I Learned: ✔ Power of Union-Find (DSU) in grouping ✔ Converting swap problems into component problems ✔ Frequency matching for minimizing mismatches ✅ Day 35 Completed 🚀 Improving in Graph + DSU + Greedy Thinking 💪 #Leetcode #DSA #ProblemSolving #BitManipulation #CodingJourney #InterviewPreparation #Consistency
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
Wow 216 days streak