🎉 Day 13 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Minimum Absolute Distance Between Mirror Pairs” problem on LeetCode. The goal is to find the minimum index distance between pairs where one number is the reverse of the other. 🧩 🔍 Approach: I used a HashMap + number reversal technique to efficiently track and compare mirror pairs. ⚙️ Steps: • Traverse the array from left to right • Reverse the current number • Check if the current number already exists in the map • If yes → calculate distance using i - previousIndex • Store the reversed number in the map for future matches 💡 Key Insights: ✔ Reversing numbers helps identify mirror pairs quickly ✔ HashMap enables O(1) lookup for efficient comparison ✔ Single pass solution makes it optimal 🧠 Complexity: • Time Complexity: O(n × d) (d = number of digits) • Space Complexity: O(n) A great problem to strengthen concepts in Hashing, Number Manipulation, and Optimization. Consistency continues — let’s keep building! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #HashMap #Programming #CodingChallenge
Solved Minimum Absolute Distance Between Mirror Pairs on LeetCode with HashMap
More Relevant Posts
-
🎉 Day 9 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Number of Steps to Reduce a Number to Zero” problem on LeetCode. The task is simple yet interesting — reduce a number to zero by applying the following rules: • If the number is even → divide it by 2 • If the number is odd → subtract 1 🔍 Approach: I used a recursive approach to repeatedly apply the rules until the number becomes zero, while counting the number of steps taken. ⚙️ Steps: • Check if the number is zero → return steps • If even → divide by 2 and increment steps • If odd → subtract 1 and increment steps • Continue recursively until reaching zero 💡 Key Insights: ✔ Demonstrates the concept of recursion and base condition ✔ Simple logic but helps build strong fundamentals ✔ Can also be solved iteratively for better space optimization 🧠 Complexity: • Time Complexity: O(log n) • Space Complexity: O(log n) (due to recursion stack) Another great problem to strengthen problem-solving and recursion skills. Consistency is key — onto Day 10! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #Recursion #Programming #CodingChallenge
To view or add a comment, sign in
-
-
🎉 Day 8 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Sqrt(x)” problem on LeetCode. The task is to compute the square root of a non-negative integer and return the result rounded down to the nearest integer, without using built-in functions like pow() or sqrt(). 🧩 🔍 Approach: I used the Binary Search technique to efficiently find the square root. ⚙️ Steps: • Define the search space from 1 to x. • Calculate the middle value (mid). • Check if mid * mid is equal to x. • If less than x, move right and store the potential answer. • If greater than x, move left. • Continue until the search space is exhausted. 💡 Key Insights: ✔ Binary Search reduces time complexity significantly. ✔ Avoids overflow using mid <= x / mid instead of mid * mid. ✔ Efficient way to compute roots without built-in functions. 🧠 Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) Another great problem to strengthen Binary Search fundamentals and mathematical problem-solving skills. On to the next challenge! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #BinarySearch #Programming #CodingChallenge
To view or add a comment, sign in
-
-
Today’s session was focused on understanding the core concepts of Map and its implementations — HashMap, LinkedHashMap, and TreeMap. 🔹 Learned about their properties, hierarchy, and internal behavior 🔹 Explored key methods like put(), get(), containsKey(), and remove() 🔹 Understood how to access and iterate elements efficiently 🔹 Compared when to use each: • ⚡ HashMap → Fast access (no order) • 🔗 LinkedHashMap → Maintains insertion order • 🌳 TreeMap → Sorted keys 💡 Gaining clarity on choosing the right data structure based on requirements is a big step toward writing efficient code. @tapacademy #Java #DataStructures #CollectionsFramework #LearningJourney #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 6 of Solved LeetCode Problem 66 – Plus One 💡 📌 Problem Summary: Given an array of digits representing a large number, increment the number by 1 and return the updated array. 🔍 Key Learning: Traverse from the last digit (right to left) Handle carry (especially when digit = 9) If all digits are 9 → create a new array like [1,0,0,...] Time Complexity: O(n) () 💻 Approach: Instead of converting to an integer (which may overflow), we simulate manual addition digit by digit. #Day6 #LeetCode #Java #CodingJourney #ProblemSolving #Programming #DSA
To view or add a comment, sign in
-
-
🔥 Day 36 of #LeetCode Journey ✅ Problem: Minimum Distance Between Three Equal Elements I Today’s problem was about finding the minimum distance between three equal elements in an array. 💡 Key Idea: Instead of checking all combinations, we track indices efficiently: Store the last two occurrences of each number When a third occurrence appears, calculate the distance Keep updating the minimum distance 🧠 What I Learned: Optimizing from brute force to O(n) approach Using HashMap effectively for tracking indices Thinking in terms of patterns instead of combinations ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 🔍 Example: Input: [1,2,1,1,3,1] Output: 3 Small optimizations make a big difference 💡 Staying consistent and improving every day! #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #Programming #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 568 of #750DaysOfCode 🚀 🔍 Problem Solved: Two Furthest Houses With Different Colors Today’s problem looked simple at first, but it had a nice twist that tested observation skills more than brute force thinking. 💡 Key Insight: To maximize the distance between two houses with different colors, we don’t need to check all pairs. The answer will always involve either: the first house, or the last house Why? Because the maximum distance comes from the edges of the array. ⚡ Approach: Compare every house with the first and last house If colors are different → calculate distance Keep track of the maximum distance 🧠 Optimization: Instead of an O(n²) brute-force approach, we can solve this in O(n) time with constant space. 📈 Complexity: Time: O(n) Space: O(1) ✨ Takeaway: Sometimes the best solution isn’t about trying everything — it’s about spotting the right pattern. #LeetCode #Java #DSA #CodingJourney #ProblemSolving #100DaysOfCode #Programming #Tech #LearningEveryday
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 48 Today I solved the House Robber problem. Problem Insight: Given an array where each element represents money in a house, the goal is to find the maximum amount that can be robbed without robbing two adjacent houses. Approach: At each house, there are two choices: Rob the current house and add its value to the maximum from two houses back Skip the current house and take the maximum till the previous house Used a dynamic programming approach to make this decision efficiently Key Learning: Dynamic Programming becomes easier when we break the problem into small decisions. At each step, we only need to decide whether to pick or skip the current element. Complexity: Time: O(n) Space: O(1) This problem helped me understand how to make optimal decisions using previous results. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
Excited to share my first C++ project – Simple Calculator! 💻 Here is the code for a basic calculator that performs: ✔ Addition ✔ Subtraction ✔ Multiplication ✔ Division 📌 Logic: Takes two numbers and an operator as input Uses switch-case to perform operations Displays result based on user input 🔗 Code attached / GitHub link in comments I am continuously learning and improving my coding skills. 💡 Feedback is welcome! #cpp #coding #github #beginners #learningjourney
To view or add a comment, sign in
-
Day 60 of My 90-Day Coding Challenge Today I worked on a classic recursion + backtracking problem — and it really tested how well I understand breaking problems into smaller decisions. At first, it feels messy: multiple partitions, multiple choices, and many possible paths. But once you start thinking in terms of: -“Try every possible cut and validate it” the structure becomes clear. Key learning: • Recursion is about exploring all paths, not rushing to the answer • Validity checks (like palindrome here) are what control the tree • Clean backtracking (add → recurse → remove) is everything One thing that really helped today: Even if you don’t know where to start, just begin drawing the recursion tree. As you expand it step by step, the logic starts revealing itself — what choices to make, when to stop, and how to backtrack. What stood out today: Clarity in recursion doesn’t come from memorizing patterns — it comes from visualizing the process. Still improving. #90DaysOfCode #DSA #Java #Recursion #Backtracking #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 54 – 100 Days Coding Challenge 📌 Problem: Three Sum ⚙️ Approach • First, sort the array to make it easier to apply the two-pointer technique • Iterate through the array and fix one element at a time • For each fixed element, use two pointers (left and right) to find pairs whose sum equals the negative of the fixed element • Skip duplicate elements to avoid repeating triplets • Move pointers based on the sum: – If sum == 0 → store the triplet and move both pointers – If sum < 0 → move left pointer forward – If sum > 0 → move right pointer backward 🧠 Logic Used • Sorting + Two Pointer Technique • Handling duplicates efficiently to ensure unique triplets • Reducing time complexity from brute force O(n³) to O(n²) 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 54 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #TwoPointers #ArrayProblems
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