💡 Day 56 of LeetCode Problem Solved! 🔧 🌟 Mirror of an Integer 🌟 🔗 Solution Code: https://lnkd.in/gvaEY4Sw 🧠 Approach: • Digit Extraction & Reversal Extract digits from right to left using modulo (% 10) and rebuild the reversed number dynamically. • Calculate the absolute difference abs(n - reversed) at the end to find the mirror distance. ⚡ Key Learning: • Mastering number manipulation with fundamental math operators (% and /) is a game-changer for processing integers efficiently without relying on space-consuming String conversions. ⏱️ Complexity: • Time: O(log₁₀(n)) (proportional to the number of digits) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfCode #CodingJourney #MathLogic #DataStructures
LeetCode Day 56: Mirror of an Integer Solution
More Relevant Posts
-
Day 6 of #100DaysOfLeetCode ✅ Today I solved LeetCode 128 — Longest Consecutive Sequence. 🧩 Problem Summary: Given an unsorted array of integers, the task is to find the length of the longest sequence of consecutive numbers. The challenge is to solve it in O(n) time complexity, which means sorting is not allowed. 💡 Key Learning: Instead of sorting, I used a HashSet for O(1) lookup. The main intuition: 👉 A number starts a sequence only if (num - 1) does NOT exist in the set. Then we expand forward (num + 1) to count the sequence length. ⚡ Concepts Practiced: • HashSet / Hashing • Optimized Searching (O(1) lookup) • Sequence Detection Pattern • Time Complexity Optimization 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Every day improving problem-solving skills and understanding data structures deeper 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
💡 Day 57 of LeetCode Problem Solved! 🔧 🌟 Maximum Distance Between a Pair of Values 🌟 🔗 Solution Code: https://lnkd.in/gSP_QePE 🧠 Approach: • Two-Pointer Strategy: Maintain two indices (i for nums1 and j for nums2) to scan both non-increasing arrays in a single efficient pass. • Greedy Search: If nums1[i] <= nums2[j], calculate j - i and expand j to find the maximum possible distance. If the value in nums1 is too large, move i forward. ⚡ Key Learning: • Leveraging the non-increasing nature of arrays with two pointers eliminates the need for nested loops, reducing complexity from O(N^2) to linear O(N+M). ⏱️ Complexity: • Time: O(n + m) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfCode #CodingJourney #Algorithms #TwoPointers
To view or add a comment, sign in
-
-
🚀 Day 8/100 — #100DaysOfLeetCode Another day, another concept unlocked 💻🔥 ✅ Problem Solved: 🔹 LeetCode 73 — Set Matrix Zeroes 💡 Problem Idea: If any element in a matrix is 0, its entire row and column must be converted to 0 — and the challenge is to do this in-place without using extra space. 🧠 Algorithm & Tricks Learned: Instead of using extra arrays, we can use the first row and first column as markers. First pass → mark rows and columns that should become zero. Second pass → update the matrix based on those markers. Carefully handle the first row and first column separately to avoid losing information. ⚡ Key Insight: The matrix itself can act as storage, reducing extra memory usage. 📊 Complexity Analysis: Time Complexity: O(m × n) → traverse matrix twice Space Complexity: O(1) → solved in-place without extra data structures This problem taught me how small optimizations can significantly improve space efficiency. Learning to think beyond brute force every day 🚀 #100DaysOfLeetCode #LeetCode #DSA #MatrixProblems #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
📌 Median of Two Sorted Arrays Platform: LeetCode #4 Difficulty: Hard ⚙️ Approach • Apply binary search on the smaller array for efficiency • Define search space from 0 to n1 • Partition both arrays such that: – Left half contains (n1 + n2 + 1) / 2 elements – Right half contains remaining elements • Identify boundary elements: – l1, l2 → left side elements – r1, r2 → right side elements • Check valid partition: – l1 <= r2 and l2 <= r1 • If valid: – For even length → median = average of max(left) and min(right) – For odd length → median = max(left) • If not valid: – If l1 > r2, move left – Else move right 🧠 Logic Used • Binary Search on partition index • Dividing arrays into balanced halves • Handling edge cases using boundary values • Achieving optimal O(log(min(n1, n2))) time complexity 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 36 Completed – Revised advanced binary search and partition-based problem. #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #Algorithms #DataStructures #LeetCode #CodingPractice #CodeEveryDay #BinarySearch #ArrayProblems
To view or add a comment, sign in
-
-
Day 70 of My DSA Journey Problem: Linked List Cycle (LeetCode 141) Today’s problem was all about detecting whether a linked list contains a cycle — a classic and very important concept in data structures. Key Idea: Floyd’s Cycle Detection Algorithm (Tortoise & Hare) Instead of using extra memory, we use two pointers: • Slow pointer → moves 1 step • Fast pointer → moves 2 steps If there’s a cycle, these two pointers will eventually meet. If not, the fast pointer will reach the end (null). Insight: This approach is efficient because it avoids using extra space like a HashSet and still guarantees detection in linear time. Complexity: • Time: O(n) • Space: O(1) What I learned: Sometimes, the smartest solutions don’t require extra space — just a clever observation and pointer manipulation! Consistency > Perfection 💯 On to Day 71 🚀 #DSA #100DaysOfCode #Java #CodingJourney #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 51 Today I solved the Diameter of Binary Tree problem. Problem Insight: The task is to find the length of the longest path between any two nodes in a binary tree. The path does not necessarily pass through the root. Approach: Used Depth First Search (DFS) to calculate the height of each subtree For every node: Calculated left subtree height Calculated right subtree height Updated the maximum diameter as the sum of left and right heights Returned the maximum diameter found during traversal Key Learning: Tree problems often combine multiple concepts. Here, calculating height and updating diameter together in a single traversal makes the solution efficient. Complexity: Time: O(n) Space: O(h) This problem helped me understand how recursion can be used to compute multiple values in a single traversal. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🚀 Day 566 of #750DaysOfCode 🚀 🔍 Problem Solved: Mirror Distance of an Integer Today’s problem was simple but a great reminder of how powerful basic number manipulation can be. 💡 Problem Insight: We define the mirror distance of a number as: 👉 abs(n - reverse(n)) So the task is: Reverse the digits of the number Compute the absolute difference 🧠 Approach: Extract digits using % 10 Build the reversed number Compute absolute difference 📊 Complexity: Time: O(d) → where d = number of digits Space: O(1) 🔥 Key Takeaway: Even the easiest problems reinforce fundamentals like digit extraction, reversal, and absolute difference — building blocks for more complex algorithms. #Day566 #750DaysOfCode #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #BeginnerFriendly
To view or add a comment, sign in
-
-
🔥 Day 63 of #100DaysOfCode Solved – Missing Number 🔍 What I did: Calculated the expected sum of numbers from 0 to n and subtracted the actual sum of the array to find the missing number efficiently. 💡 Key Learning: Learned how to use mathematical formula (n × (n+1) / 2) Practiced optimizing from brute force to O(n) solution Improved understanding of number patterns in arrays 🎯 Takeaway: Using mathematical insights can simplify problems and eliminate the need for extra loops or space. #Day62 #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
Today I solved LeetCode 104 – Maximum Depth of Binary Tree. 🧩 Problem Summary: Given the root of a binary tree, return its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 💡 Key Concepts Used: Binary Trees Recursion Depth First Search (DFS) Tree traversal 🧠 Approach: Use DFS (recursion) to explore the tree. For each node: Recursively calculate the depth of the left subtree. Recursively calculate the depth of the right subtree. The depth of the current node = 1 + max(left depth, right depth) Base case: if node is null, return 0. ⏱ Time Complexity: O(N) — Each node is visited once. 📚 What I Learned: Understanding tree depth calculation. Strengthening recursion and DFS concepts. Difference between maximum depth vs minimum depth. Building intuition for tree-based problems. Strong fundamentals in trees make advanced problems easier Consistency is the key to improvement #LeetCode #DSA #BinaryTree #MaximumDepth #DFS #Recursion #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 563 of #750DaysOfCode 🚀 📌 Problem Solved: Shortest Distance to Target String in a Circular Array Today I explored a clean and optimized approach to solving a circular array problem 🔄 💡 Key Insight: Instead of checking all indices, we can expand from the start index in both directions simultaneously 👉 At each step i, we check: Forward → (start + i) % n Backward → (start - i + n) % n ⏱️ The moment we find the target, we return i → which is guaranteed to be the minimum distance 🧠 Why this works: We are exploring layer by layer (like BFS on array) First match = shortest path ✅ No need to scan entire array unnecessarily 🔥 What I Learned: Circular problems can often be solved using modulo arithmetic Expanding outward is more efficient than brute force Think in terms of minimum steps, not positions Consistency is the real game changer 💯 On to Day 564 🚀 #LeetCode #Java #Algorithms #DataStructures #CodingJourney #ProblemSolving #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