𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 | 𝗠𝗲𝗿𝗴𝗲 𝗧𝘄𝗼 𝗦𝗼𝗿𝘁𝗲𝗱 𝗟𝗶𝘀𝘁𝘀 Day 36 ✅ — Recursion over iteration. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟭: Merge Two Sorted Lists (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Merge two sorted linked lists. Instead of the iterative dummy node approach, I used 𝗿𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻. Compare the heads. Attach the smaller one, then recursively merge the rest. Base case: if one list is empty, return the other. Elegant. Three lines of logic. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Base cases: if l1 is null, return l2 (and vice versa) 👉 Compare l1.val and l2.val 👉 Attach smaller node and recurse with remaining lists Time: O(n + m), Space: O(n + m) for recursion stack 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Seven linked list problems, and recursion just made this one cleaner than iteration. Sometimes the simplest code is the most powerful. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/g4f4_B69 𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 ✅ | 𝟲𝟰 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #Recursion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming
More Relevant Posts
-
🚀 Day 10/30 – Strengthening String Processing Fundamentals Today’s problem focused on determining whether two strings are anagrams of each other. Instead of sorting both strings (which would take O(n log n) time), I implemented a frequency-count approach using a fixed-size array to track character occurrences. 💡 Approach First, check if the lengths differ — if so, they cannot be anagrams. Use an integer array of size 26 (for lowercase letters). Increment counts for characters in the first string. Decrement counts for characters in the second string. If all values return to zero, the strings are valid anagrams. This approach ensures: ⏱ O(n) time complexity 📦 O(1) space complexity (constant size array) 📊 Performance ✅ All test cases passed ⚡ Efficient runtime 💾 Optimized space usage 📚 Key Takeaway Optimizing from a sorting-based solution to a frequency-count approach highlights the importance of understanding constraints. Sometimes improving complexity from O(n log n) to O(n) is not about writing more code — it's about choosing the right idea. Ten days completed. Small improvements every day compound over time. #Day10 #30DaysOfCode #LeetCode #Java #Algorithms #StringManipulation #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 11/30 – Working with Numbers Without Converting to Strings Today’s problem involved checking whether a given integer is a palindrome. While one straightforward approach would be converting the number into a string and reversing it, I chose to solve it mathematically — by reversing the digits of the number itself. 💡 Approach Immediately return false for negative numbers Store the original number Reverse the digits using modulo (% 10) and division (/ 10) Compare the reversed number with the original This avoids unnecessary string conversion and keeps the logic purely numerical. 📊 Performance ✅ All test cases passed ⚡ Efficient runtime ⏱ O(log₁₀ n) time complexity 📦 O(1) space complexity 📚 Key Takeaway Sometimes the better solution isn’t the easiest one — it’s the one that respects constraints and demonstrates deeper understanding of number manipulation. Day 11 complete. Building stronger fundamentals, one problem at a time. #Day11 #30DaysOfCode #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Consistency #TechGrowth
To view or add a comment, sign in
-
-
Day 7 of Daily DSA 🚀 Solved LeetCode 238: Product of Array Except Self ✅ 🔍 Approach: Built the solution using prefix and suffix products. First pass stores left-side products in the result array Second pass multiplies them with right-side products using a single variable No division used, and handled edge cases like zeros efficiently. ⏱ Complexity: • Time: O(n) • Space: O(1) extra space (output array excluded) 📊 LeetCode Stats: • Runtime: 2 ms (Beats 94.19%) • Memory: 72.23 MB This problem is a great example of how space optimization + traversal logic can turn a seemingly tricky problem into a clean, interview-ready solution. #DSA #LeetCode #Java #Arrays #PrefixSum #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 17/100 – Sorted Squares (Two Pointer Approach) Today I solved the “Sorted Squares” problem on LeetCode. 🔹 Problem: Given a sorted array (non-decreasing order), return an array of the squares of each number, also sorted. 🔹 Brute Force Idea: 1. Square each element. 2. Sort the array again. Time Complexity: O(n log n) ❌ (Not optimal because sorting takes extra time.) 🔹 Optimal Approach (Two Pointer Technique): Since the array is already sorted, the largest square will come from either: - The leftmost negative number - Or the rightmost positive number So I used: • left pointer at start • right pointer at end • filled the result array from the back At each step: Compare absolute values Place the larger square at the current index Move the corresponding pointer ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✨ Key Learning: Instead of blindly sorting again, understanding the pattern of negative numbers helped me optimize the solution. #Day17 #100DaysOfCode #LeetCode #Java #DataStructures #Arrays.
To view or add a comment, sign in
-
-
Day 58/100 – LeetCode Challenge ✅ Problem: Longest Balanced Substring II Difficulty: Medium Language: Java Approach: Multiple Pattern Detection + Prefix Difference Mapping Time Complexity: O(n) Space Complexity: O(n) Key Insight: Balanced substrings must have equal counts of characters in three possible patterns: Single character run - consecutive same characters Two characters - equal occurrences of two specific chars Three characters - all three chars appear same number of times Solution Brief: countOne(): Track longest consecutive run of same character. countTwo(): For two chars (like 'a'/'b'), use prefix sum where n1=+1, n2=-1; reset on other chars. countThree(): Track differences (a-b) and (a-c) as state; when same state repeats, balanced substring found. #LeetCode #Day58 #100DaysOfCode #String #HashMap #Java #Algorithm #CodingChallenge #ProblemSolving #LongestBalancedSubstringII #HardProblem #PrefixSum #StateTracking #DSA
To view or add a comment, sign in
-
-
Day 44: Avoiding the O(n²) Trap 🔍 Problem 3714: Longest Balanced Substring II Today’s goal: find the longest substring where all present characters appear equally. Since we only had 'a', 'b', and 'c' to deal with, I split the logic into three cases (1, 2, or 3 unique characters). Pro tip: I almost nuked my runtime by using map.clear() inside a loop. Since clear() iterates over the map to nullify entries, it’s O(n). Switching to new HashMap<>() kept the complexity at a clean O(1) reset and a total O(n) pass. Don't let built-in methods turn your linear solution into a nested nightmare. Complexity matters. 🧗♂️ #LeetCode #Java #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
📌 LeetCode Daily Challenge — Day 4 Problem: 1582. Special Positions in a Binary Matrix Topic: Array, Matrix 🧠 Approach (Simple Thinking): 🔹 A position is special only if it holds a 1 that is alone in its entire row AND its entire column 🔹 Checking row and column for every cell separately is slow and repetitive 🔹 So we pre-compute rowSum and colSum in one pass before making any decisions 🔹 rowSum[i] == 1 means no other 1 exists in that row 🔹 colSum[j] == 1 means no other 1 exists in that column 🔹 If mat[i][j] == 1 and both sums equal 1 — that's your special position 🔹 Preprocessing once and reusing is the real trick here ⏱️ Time Complexity: Two passes through the full matrix → O(m × n) Every cell is visited exactly twice, nothing more 📦 Space Complexity: Two small arrays for row and column sums → O(m + n) No recursion, no extra grid, just two lightweight arrays doing all the work I wrote a full breakdown with dry run, analogy and step by step code walkthrough here: https://lnkd.in/gFgQxQRP If you approached this differently or have a cleaner way to think about it, drop it in the comments — always curious to see different perspectives 💬 See you in the next problem 👋 #LeetCode #Java #SoftwareEngineer #ProblemSolving #BackendDeveloper
To view or add a comment, sign in
-
-
🎯 Day 67 of #100DaysOfCode 📌 Problem: Combination Sum Today's challenge was all about finding all unique combinations of candidates where the chosen numbers sum to a given target. The same number can be used unlimited times, and combinations must be unique. 🧠 Approach: Used dynamic programming with a 3D list structure dp[t] stores all combinations that sum to target t Iterated through candidates and built combinations from smaller sums Extended each valid combination by adding current candidate 📊 Stats: ✅ 160/160 test cases passed ⚡ Runtime: 5 ms | Beats 10.10% 💾 Memory: 46.71 MB | Beats 5.88% 📝 Takeaway: This problem highlighted the trade-off between intuitive DP solutions and optimization. While the approach works, there's room for improvement in both runtime and memory efficiency. Backtracking might be a more elegant solution here! 🔗 Problem: Combination Sum 🏷️ #LeetCode #CodingChallenge #Java #DynamicProgramming #Backtracking #Algorithms #TechJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfCode Solved 54. Spiral Matrix on LeetCode 🌀 🧠 Key insight: Spiral traversal is all about maintaining boundaries. By shrinking the top, bottom, left, and right limits after each pass, we can cover every element exactly once. ⚙️ Approach: 🔹Maintain four pointers: top, down, left, right 🔹Traverse: 🔹Left → Right (top row) 🔹Top → Bottom (right column) 🔹Right → Left (bottom row) 🔹Bottom → Top (left column) 🔹Update boundaries after each traversal ⏱️ Time Complexity: O(m × n) 📦 Space Complexity: O(1) (excluding output list) #100DaysOfCode #LeetCode #DSA #Matrix #Java #ProblemSolving #LearningInPublic #CodingJourney
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