🔹 Day 52: Self Dividing Numbers (LeetCode #728) 📌 Problem Statement: A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is self-dividing because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Given two integers left and right, return a list of all self-dividing numbers in that range (inclusive). ✅ My Approach: I iterated through each number in the range [left, right] and checked if it was self-dividing using a helper function. For each number: Extract each digit using modulo and division. If any digit is zero or the number isn’t divisible by that digit, it’s not self-dividing. Otherwise, include it in the result list. 📊 Complexity: Time Complexity: O(n × d), where d is the number of digits. Space Complexity: O(1) (excluding the output list). ⚡ Submission Stats: Runtime: 2 ms (Beats 73.19%) Memory: 42.48 MB (Beats 10.09%) 💡 Reflection: This problem strengthened my skills in digit manipulation and modular arithmetic. It’s a great exercise for mastering number decomposition and iteration logic. ✨ #LeetCode #Java #Math #Loops #100DaysOfCode #Day52
"Self Dividing Numbers LeetCode Solution in Java"
More Relevant Posts
-
🚀 Day 80 of My #100DaysOfLeetCode Journey Problem: 719. Find K-th Smallest Pair Distance Difficulty: Hard 💥 Today I tackled another challenging problem that really tested my ability to optimize beyond brute force. At first, I wrote a simple solution: 👉 Generate all possible pairs 👉 Find their absolute differences 👉 Sort them and return the (k-1)th smallest It worked fine — until the 11th test case 😅 — Time Limit Exceeded (TLE) reminded me that brute force doesn’t scale! Then I explored the efficient approach: 🔹 Sort the array 🔹 Use binary search on the distance range (0 to max diff) 🔹 For each mid distance, use two pointers to count how many pairs have a distance ≤ mid This reduced the time complexity drastically and helped me understand how binary search can be used not only on arrays, but also on the answer space itself! 💡 Key Learnings: Think about what you’re searching for — sometimes the answer itself is the search space. Two-pointer patterns are incredibly powerful when combined with sorted data. Optimization is not just about speed — it’s about clarity and scalability. Every hard problem starts as a puzzle, but once you see the pattern, it becomes a story of logic. #LeetCode #100DaysOfCode #Java #ProblemSolving #BinarySearch #TwoPointers #CodingJourney
To view or add a comment, sign in
-
-
#Day_27 Today’s problem was an interesting twist on binary search — “Find Peak Element” 🔍 Given an array of numbers, the task is to find an index i such that nums[i] is greater than its neighbors — basically, a peak element. At first glance, it seems like a simple linear scan could solve it in O(n). But I wanted to do better — and that’s where binary search comes in 💡 🧠 Approach We observe that: If nums[mid] > nums[mid + 1], it means we are on a descending slope, so the peak lies on the left side (including mid). Otherwise, we’re on an ascending slope, so the peak lies on the right side (after mid). Using this logic, we can shrink our search space by half in every iteration — a classic divide and conquer move 🔥 ⏱ Complexity Time: O(log n) Space: O(1) This is a great example of how binary search isn’t just for sorted arrays — it can also be applied to problems involving patterns or directional decisions. 💬 Every day of this challenge reinforces that problem-solving isn’t just about writing code — it’s about recognizing patterns, making logical deductions, and applying optimized thinking. #CodingJourney #LeetCode #BinarySearch #ProblemSolving #100DaysOfCode #Java #LearnByDoing
To view or add a comment, sign in
-
-
🚀 Day 8 of #45DaysOfLeetCode Challenge 😎 📌Today's problem: Palindrome Number (LeetCode #9) 💡 🔹 Concept: Check whether a given integer reads the same backward and forward — without converting it to a string! 🔹 Logic Used: Instead of reversing the entire number, I reversed only half of it to improve efficiency. This avoids unnecessary computation and eliminates integer overflow risks. 🔹 Key Learnings: ✅ Optimized logic using mathematical manipulation ✅ Improved understanding of number reversal techniques ✅ Importance of edge case handling (negative numbers, trailing zeros) ⚙️ Result: 💻 Runtime: 4 ms (Beats 100%) 💾 Memory: 44.84 MB 😎Small optimizations make a big difference in performance! 💪 📌Problem: https://lnkd.in/ef6AC2j6 🔥Each day is a step closer to writing cleaner and more optimized code. ✨ Let’s keep pushing forward and refining our problem-solving skills! 💻🔥 #LeetCode #Day8 #100DaysOfCode #ProblemSolving #Java #CodingChallenge #PalindromeNumber #DataStructures #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
🗓️ Day 32 / 100 – Binary Tree Maximum Path Sum 🌳💻 Today’s challenge pushed my recursion and problem-solving skills to the limit. I worked on finding the Maximum Path Sum in a Binary Tree — a classic yet tricky problem that tests your understanding of recursion, global state management, and tree traversal. 🔁 It took me 10 submissions to finally get it right! Each attempt helped me uncover a new insight — from handling negative values to understanding how and where to update the global maximum. 💡 The major improvement came on the 11th attempt, when I replaced the static global variable with a local reference (int[] maxSum). This small design change made my code cleaner, reusable, and thread-safe — a great reminder that writing correct code is one thing, but writing robust code is another. 📈 Key Learnings: Manage global state carefully in recursive problems. Use reference wrappers (like int[] or small helper classes) to avoid side effects. Debugging recursion is easier when you visualize each return value and what it represents. 🧠 Code snippet (improved version): public int maxPathSum(TreeNode root) { int[] maxSum = {Integer.MIN_VALUE}; maxPath(root, maxSum); return maxSum[0]; } 🚀 Reflection: Persistence pays off! Every failed attempt was just one step closer to understanding the problem deeply. #100DaysOfCode #Day32 #Java #DSA #LeetCode #CodingJourney #LearningInPublic #ProblemSolving #BinaryTree
To view or add a comment, sign in
-
-
🔹 Day 54: Sign of the Product of an Array (LeetCode #1822) 📌 Problem Statement: You're given an integer array nums. Consider the product of all elements in the array. Based on this product: Return 1 if it is positive Return -1 if it is negative Return 0 if it is zero Instead of actually multiplying (which can overflow), you're asked to determine only the sign of the product. --- ✅ My Approach: I avoided calculating the full product because it can grow very large. Instead, I focused on the sign only. Here’s the logic I followed: Initialize a variable to track the sign. Iterate through each number: If any number is 0, the result is immediately 0, since the product becomes zero. If the number is negative, flip the sign. After processing all numbers, return the tracked sign. This avoids overflow and keeps the solution efficient. --- 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) --- ⚡ Submission Stats: Runtime: 0 ms (Beats 100%) 🚀 Memory: 45.32 MB (Beats 6.29%) --- 💡 Reflection: A simple yet elegant problem that highlights how sometimes we don't need the full value — only the effect of the operations. Great reminder to think efficiently! #LeetCode #Java #Math #Optimized #100DaysOfCode #Day54
To view or add a comment, sign in
-
-
🚀 Day 59 of #100DaysOfCode 🚀 🔹 Problem: Check if Digits Are Equal in String After Operations I – LeetCode ✨ Approach: Used an iterative reduction strategy 🔁 — repeatedly combined adjacent digits (mod 10) until only two numbers remained. Finally checked if both digits are equal! Simple yet logical 🧠 ⚡ Complexity Analysis: Time Complexity: O(n²) – iterative pairwise reduction until only two digits remain Space Complexity: O(n) – storing intermediate list of digits 📊 Performance: ✅ Runtime: 10 ms (Beats 35.69%) ✅ Memory: 45.51 MB (Beats 12.86%) 🔑 Key Insight: Sometimes, brute-force reduction problems aren’t about optimization — they’re about translating logic into clean code that mirrors the operation flow perfectly. ✨ #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #CodingChallenge #LogicBuilding #ProgrammingJourney #DailyCoding
To view or add a comment, sign in
-
-
🔍 Day 30 | Shift Happens (and That’s Beautiful) Today’s LeetCode challenge was #848 – Shifting Letters 🌀 At first glance, it looks like a simple “shift characters” task — but under the hood, it’s a neat example of prefix-sum logic meets modular arithmetic. 💡 The Problem: For each index i, shift the first i+1 letters by shifts[i] times — wrapping around from 'z' to 'a'. 🧠 The Trick: If we start from the end of the string and move backward, we can keep a cumulative shift sum that already accounts for all later shifts. This avoids repeatedly looping over the prefix and keeps our time complexity O(n) instead of O(n²). ⚙️ Approach: Traverse from right to left Keep adding each shift to a running total (totalShift) Apply totalShift % 26 to shift the current character efficiently Update the string using a StringBuilder 💨 Why It’s Optimal: ✅ Single pass — linear time ✅ Constant extra space ✅ Clean and scalable even for large inputs (up to 10⁵ length! Sometimes the cleanest solutions come from flipping your perspective — literally shifting your direction Shishir chaurasiya and PrepInsta #LeetCode #CodingChallenge #Java #Algorithms #ProblemSolving #LearningEveryday
To view or add a comment, sign in
-
-
🌳 Day 60 of 100: Maximum Depth of Binary Tree 🌳 Today’s challenge was LeetCode 104 – Maximum Depth of Binary Tree 🌲 The task? Given the root of a binary tree, find the maximum depth — the number of nodes along the longest path from the root to a leaf node 🍃 💡 Intuition: A binary tree’s depth can be thought of as its “height”. To find it, we just need to know the depth of the left and right subtrees — and the answer is the greater of the two, plus one for the current node. This is a classic example of recursion done right — breaking a big problem into smaller ones that mirror the original. ⏱ Time Complexity: O(n) – visit every node once 🗂 Space Complexity: O(h) – h is the height of the tree (recursion stack) ✨ Key Takeaway: This problem beautifully highlights the power of divide and conquer — by solving smaller subproblems (left and right trees), we can elegantly solve the bigger one. #100DaysOfCode #Day60 #LeetCode #Java #CodingJourney #BinaryTree #Recursion #DataStructures #CodingPractice #ProblemSolving #WomenWhoCode #CodeNewbie #LearnToCode
To view or add a comment, sign in
-
-
💻 Day 410 of #500DaysOfCode 🚀 Problem: Minimum One Bit Operations to Make Integers Zero (LeetCode #1611) Difficulty: Hard Today’s challenge was all about bit manipulation — one of those topics that looks simple on the surface but reveals some deep patterns when you dig in. The task: Given an integer n, you have to transform it into 0 using specific bit operations — flipping bits based on certain conditions. At first glance, it seems like a direct simulation problem, but the optimal approach lies in understanding Gray Code transformations! 💡 Key Idea: The number of operations needed to reduce n to 0 follows an inverse Gray code pattern. Using recursion and bitwise manipulation, we can calculate the answer efficiently in O(log n) time. ✨ Concepts Learned: Gray code transformation patterns Recursive bit manipulation How mathematical patterns simplify complex bit problems Each hard problem strengthens logical thinking a bit more 🔥 #Day410 #LeetCode #BitManipulation #Java #CodingChallenge #ProblemSolving #CodeEveryday #500DaysOfCode
To view or add a comment, sign in
-
-
#Day_34 Today’s problem was a satisfying one to solve — “Single Element in a Sorted Array” 🔍 Given a sorted array where every element appears twice except for one unique element, the task is to identify that single element. At first, it seems like a simple linear scan could do the job — and yes, it can. But I focused on building a clean and logical O(n) approach before thinking about optimization 🧠 Approach We observe that: Every element appears in pairs, and because the array is sorted, duplicates are adjacent. The unique element is the only one that doesn’t match its left or right neighbor. We can handle three cases: First element: If it’s not equal to the next one → it’s the single element. Last element: If it’s not equal to the previous one → it’s the single element. Middle elements: If an element is different from both its previous and next → that’s our answer. This way, we can detect the single element in just one pass through the array ⏱ Complexity Time: O(n) — We traverse the array once. Space: O(1) — No extra memory used. 💬 Reflection This problem is a good reminder that not every efficient solution has to start complex. Sometimes, the cleanest brute-force version gives a perfect foundation for further optimization — in this case, even leading to an O(log n) binary search variant. Each problem in this challenge pushes me to think deeper about patterns, structure, and clarity in problem-solving. #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode #Java #LearnByDoing #DSA
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