🚀 Day 14 of #100DaysOfCode Problem Solved: 3783. Mirror Distance of an Integer Small problems often hide powerful insights. Today’s challenge revolved around understanding how numbers behave when reversed and measuring the difference between the original and its mirror form. Approach The solution is built on a straightforward idea: Reverse the given integer using mathematical operations. Calculate the absolute difference between the original number and its reversed value. Instead of relying on string conversion, I focused on a digit-by-digit reversal approach, which keeps the logic efficient and avoids unnecessary space usage. Complexity Time Complexity: O(d), where d is the number of digits Space Complexity: O(1), constant extra space Key Learnings Even simple number manipulation problems strengthen core logic. Avoiding extra space can lead to cleaner and more optimized solutions. Consistency in solving problems daily builds strong problem-solving intuition. Every day adds a small improvement — and those small improvements compound over time. #100DaysOfCode #DSA #Java #ProblemSolving #CodingJourney #LeetCode #Consistency #Learning
Mirror Distance of an Integer Problem Solved with Efficient Approach
More Relevant Posts
-
At first, checking prime numbers one by one felt simple… but not efficient. Then came the Sieve of Eratosthenes — a smarter way to eliminate non-primes step by step. This visualization helped me truly understand how optimization works in real coding scenarios. Small improvements in logic can lead to huge performance gains 💡 #DSA #Java #CodingJourney #LearnByDoing #Algorithms #Optimization
To view or add a comment, sign in
-
-
🚀 Day 38 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Maximum Product of Two Elements in an Array. Problem Insight: Given an integer array, the goal is to find two elements such that: (nums[i] - 1) * (nums[j] - 1) is maximized Approach: • First, sort the array using Arrays.sort() • Use two nested loops to check all possible pairs • For each pair, calculate → (nums[i] - 1) * (nums[j] - 1) • Keep track of the maximum product Time Complexity: • O(n²) — due to nested loops Space Complexity: • O(1) — no extra space used Key Learnings: • Understanding operator precedence is very important in expressions • Sorting helps in simplifying many problems • Even simple problems can have optimized solutions beyond brute force Takeaway: Brute force helps in understanding the problem deeply, but optimization (like using the two largest elements directly) makes the solution efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Arrays
To view or add a comment, sign in
-
-
🚀 Day 76 — Slow & Fast Pointer (Find the Duplicate Number) Continuing the cycle detection pattern — today I applied slow‑fast pointers to an array problem where the values act as pointers to indices. 📌 Problem Solved: - LeetCode 287 – Find the Duplicate Number 🧠 Key Learnings: 1️⃣ The Problem Twist Given an array of length `n+1` containing integers from `1` to `n` (inclusive), with one duplicate. We must find the duplicate without modifying the array and using only O(1) extra space. 2️⃣ Why Slow‑Fast Pointer Works Here - Treat the array as a linked list where `i` points to `nums[i]`. - Because there’s a duplicate, two different indices point to the same value → a cycle exists in this implicit linked list. - The duplicate number is exactly the entry point of the cycle (same logic as LeetCode 142). 3️⃣ The Algorithm in Steps - Phase 1 (detect cycle): `slow = nums[slow]`, `fast = nums[nums[fast]]`. Wait for them to meet. - Phase 2 (find cycle start): Reset `slow = 0`, then move both one step at a time until they meet again. The meeting point is the duplicate. 4️⃣ Why Not Use Sorting or Hashing? - Sorting modifies the array (not allowed). - Hashing uses O(n) space (not allowed). - Slow‑fast pointer runs in O(n) time and O(1) space — perfect for the constraints. 💡 Takeaway: This problem beautifully demonstrates how the slow‑fast pattern transcends linked lists. Any structure where you can define a “next” function (here: `next(i) = nums[i]`) can be analyzed for cycles. Recognizing this abstraction is a superpower. No guilt about past breaks — just another pattern mastered, one day at a time. #DSA #SlowFastPointer #CycleDetection #FindDuplicateNumber #LeetCode #CodingJourney #Revision #Java #ProblemSolving #Consistency #GrowthMindset #TechCommunity #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 39 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Concatenation of Array Problem Insight: Given an integer array nums, the goal is to create a new array by concatenating the array with itself. Approach: • Created a new array of size 2 * nums.length • Used a single loop to iterate through the array • Stored elements at two positions: - result[i] = nums[i] - result[i + nums.length] = nums[i] • This avoids using extra loops and keeps the solution efficient Time Complexity: • O(n) — only one traversal required Space Complexity: • O(n) — new array is created Key Learnings: • Efficient index handling can simplify problems • Avoid unnecessary loops for better performance • Strong fundamentals make simple problems powerful Takeaway: Smart thinking beats brute force — even simple problems can be solved in an optimal and elegant way . #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Arrays
To view or add a comment, sign in
-
-
🚀 Day 34 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Maximum Product of Two Digits Problem Insight: Given a number, find the maximum product of any two digits in it. Approach: • Traverse the number digit by digit • Keep track of the two largest digits (large1 and large2) • Multiply the two largest digits to get the answer • No extra data structures required, simple comparison logic Time Complexity: • O(log n) — proportional to the number of digits Space Complexity: • O(1) — only a few variables used Key Learnings: • Simple comparison logic can replace sorting or extra arrays • Breaking down the number digit by digit is often sufficient • Edge cases like single-digit numbers should be considered Takeaway: Finding the largest values while iterating can simplify problems and reduce complexity. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #MathTricks
To view or add a comment, sign in
-
-
🚀 Day 570 of #750DaysOfCode 🚀 🔍 Problem Solved: Words Within Two Edits of Dictionary Today’s problem was a nice mix of strings + observation. At first glance, it feels like a transformation problem, but it simplifies beautifully. 💡 Key Insight: We don’t actually need to perform edits. We just need to check how many characters are different between two words. 👉 If the difference (Hamming distance) ≤ 2 → it's valid 🧠 Approach: For each word in queries, compare it with every word in dictionary Count character differences If any comparison has ≤ 2 differences → include the word in result ⚡ Early break helps optimize the solution! 📈 Complexity: Time: O(Q × D × n) Space: O(1) ✨ Takeaway: Not every problem needs simulation — sometimes reducing it to a simple comparison metric (like character differences) makes it much easier. Consistency > Complexity 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Tech #LearningEveryday #Strings
To view or add a comment, sign in
-
-
Day 40 of consistency 💻🔥 Today’s problem: Roman to Integer — sounds simple, but it really tests attention to detail and handling edge cases correctly. Key takeaway: Sometimes it’s not about complex algorithms, but about understanding patterns and applying logic cleanly. Traversing from right to left made the subtraction cases much easier to handle. ✅ Problem solved efficiently ⚡ 100% runtime 📈 Progress continues Every day I’m getting a little better at thinking like a problem solver. No shortcuts, just showing up and putting in the work. #Day40 #LeetCode #Consistency #ProblemSolving #DSA #CodingJourney #Java #KeepGrinding
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 49 🔍 Solved: Largest Number Today I worked on an interesting problem where the goal was to arrange numbers such that they form the largest possible number. 💡 Key Insight: Instead of normal sorting, we compare numbers based on their string combinations (like "ab" vs "ba"). 📌 Approach: ✔ Converted integers to strings ✔ Used a custom comparator for sorting ✔ Compared (a + b) and (b + a) ✔ Sorted in descending order based on best combination ✔ Handled edge case when all elements are 0 Why this works: By comparing two numbers in different orders, we ensure that the arrangement always produces the maximum possible value when concatenated. 🎯 What I Learned: This problem taught me that sorting can go beyond numbers—custom logic and string manipulation are powerful tools in problem solving. #Java #DSA #LeetCode #Sorting #Comparator #CodingJourney #ProblemSolving #TechSkills 🚀
To view or add a comment, sign in
-
-
🚀 Day 47of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Mirror Distance of an Integer Problem Insight: Given a number, the task is to find the absolute difference between the original number and its reversed form. Approach: • Stored the original number in a temporary variable • Reversed the number using digit extraction (modulo and division) • Calculated the absolute difference between the original and reversed number Time Complexity: O(d), where d = number of digits Space Complexity: O(1) Key Learnings: • Digit manipulation using modulo and division is a powerful technique • Always store the original value before modifying the input • Reversing numbers is a fundamental pattern in many DSA problems Takeaway: Breaking the problem into simple steps makes even tricky-looking logic easy to solve. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
Explore related topics
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