Day 60: Work Smarter, Not Harder 🧠 Problem 1689: Partitioning Into Minimum Number Of Deci-Binary Numbers Today’s problem was a classic example of why you should analyze test cases before over-engineering a solution. The Strategy: • Initial Fail: Tried calculating the maximum deci-binary value before the target. Too complex, didn't work. 💀 • The "Aha" Moment: Realized that since deci-binary numbers only use 0s and 1s, the minimum number of partitions needed is simply determined by the largest digit in the string. • Logic: If you have a '9', you need at least nine deci-binary numbers to sum up to it. O(N) time, O(1) space, and zero stress. Sometimes the hardest part of a "Medium" problem is realizing how easy it actually is. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode #CleanCode
Deci-Binary Partitioning Strategy
More Relevant Posts
-
🚀 Day 34 of #100DaysOfCode Solved 852. Peak Index in a Mountain Array on LeetCode ⛰️📈 🧠 Key Insight: A mountain array strictly increases to a peak and then decreases. Instead of scanning the whole array, we can use Binary Search to efficiently find the peak. ⚙️ Approach: 🔹Use binary search with two pointers left and right 🔹Compare arr[mid] with arr[mid + 1] 🔹If arr[mid] > arr[mid + 1] → peak is on the left side (including mid) 🔹Otherwise → peak is on the right side 🔹Continue until left == right, which gives the peak index ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Arrays #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
Day 100/100 – LeetCode Challenge ✅ Problem: #41 First Missing Positive Difficulty: Hard Language: Java Approach: In-Place Index Marking Time Complexity: O(n) Space Complexity: O(1) Key Insight: Place each positive integer in its correct position (index i should contain i+1). Mark presence using negative values without extra space. Solution Brief: First pass: replace numbers outside range [1, n] with n+1 (ignore them) Second pass: treat each number as index, mark that index negative Third pass: first positive index = missing number If all marked, answer is n+1 #LeetCode #Day100 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #FirstMissingPositive #HardProblem #InPlace #Optimization #DSA
To view or add a comment, sign in
-
-
🚀 Day 47 / 100 | Combination Sum Intuition: We are given a list of numbers and a target value. The goal is to find all combinations of numbers that add up to the target. we can use the same number multiple times. So instead of moving forward immediately, we can stay at the same index and keep using that number until the target is reached or exceeded. Approach: O(2^n) Use backtracking to explore all possible combinations. Maintain a list that stores the current combination. If the target becomes 0, we found a valid combination. If the target becomes negative or we reach the end of the array, return. At each step we have two choices: Pick the current number and reduce the target. Skip the current number and move to the next index. After exploring a choice, remove the number to try other possibilities (backtracking). Complexity: Time Complexity: O(2^n) Space Complexity: O(n) #100DaysOfCode #Java #DSA #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 Day 88- #100DaysOfCode Today I solved Peak Index in a Mountain Array using Binary Search. 🔹 Problem Idea A mountain array increases strictly and then decreases. The goal is to find the index of the peak element. 🔹 Approach Used: Binary Search Instead of checking every element (O(n)), we can use the mountain property: • If arr[mid] > arr[mid+1] → we are in the descending part, so the peak lies on the left side. • Otherwise → we are in the ascending part, so move to the right side. This helps us find the peak in O(log n) time. 📊 Time Complexity: O(log n) 📦 Space Complexity: O(1) #DSA #Java #BinarySearch #LeetCode #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 89/100 – LeetCode Challenge ✅ Problem: #459 Repeated Substring Pattern Difficulty: Easy Language: Java Approach: Substring Division Check Time Complexity: O(n²) worst case Space Complexity: O(n) Key Insight: A string can be formed by repeating its substring if the substring length divides the string length. Check all divisors of length from largest to smallest for efficiency. Solution Brief: Iterated i from l/2 down to 1 (larger substrings first). If l % i == 0, substring length divides string length. Constructed repeated pattern by appending substring m = l/i times. Compared constructed string with original. #LeetCode #Day89 #100DaysOfCode #String #Java #Algorithm #CodingChallenge #ProblemSolving #RepeatedSubstring #EasyProblem #Substring #Pattern #DSA
To view or add a comment, sign in
-
-
🚀 Day 50 / 100 | Median of Two Sorted Arrays Intuition: We are given two sorted arrays and need to find the median of the combined numbers. Since both arrays are already sorted, we can merge them in sorted order. Once we have the merged array, finding the median becomes simple. If the total number of elements is odd, the median is the middle element. If it's even, the median is the average of the two middle elements. Approach: Use two pointers to traverse both arrays. Compare the elements and insert the smaller one into a new array. Continue this process until all elements are merged. Finally, calculate the median based on the length of the merged array. Complexity: Time Complexity: O(n + m) Space Complexity: O(n + m) #100DaysOfCode #Java #DSA #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
This problem is labeled Hard... But my approach wasn't. 🚀 Day 79/365 — DSA Challenge Median of Two Sorted Arrays The requirement says: ⚡ Solve in O(log (m+n)) But today... I focused on clarity over optimization 💡 My Approach: 1. Merge both sorted arrays 2. Find the median from the merged array While merging: • Compare elements from both arrays • Add the smaller one • Continue until fully merged Then: If total length is odd → pick middle If even → take average of two middle values ⏱ Time: O(m + n) 📦 Space: O(m + n) What I learned: You don't always need the optimal solution first. A clear solution builds understanding. Optimization can come next. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #LearningInPublic #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
Solved a matrix problem : checking whether one matrix can be obtained from another using rotations. At first it looked a bit tricky, but the key idea was simple: 👉 A 90° rotation can be done using transpose + reverse each row This makes the solution clean and efficient (O(n²)) and is a useful pattern to remember for similar problems. #DataStructures #Algorithms #DSA #Java #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 35/75 — Generate Parentheses (Backtracking) Today’s problem was about generating all valid combinations of parentheses. Instead of brute force, I used backtracking with constraints. Key conditions: • Add '(' if open < n • Add ')' if close < open Base case: if (open == n && close == n) This ensures only valid sequences are generated. Time Complexity: ~ O(2ⁿ) Space Complexity: O(n) This problem helped strengthen my understanding of recursive decision trees. 35/75 🚀 #Day35 #DSA #Backtracking #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
🧠 Problem Statement: Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays after combining them. ⚙️ Approach: ✔️ Combine both arrays into a single array ✔️ Sort the merged array ✔️ If the length is odd → return the middle element ✔️ If the length is even → return the average of the two middle elements ⏱ Time Complexity: O((m+n) log(m+n)) 📦 Space Complexity: O(m+n) 📌 Learning: This problem helped me understand array merging and median calculation concepts. 🔥 Consistency in solving problems daily helps improve problem-solving skills and algorithmic thinking. #Day9 #DSA #LeetCode #Java #ProblemSolving #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