𝗗𝗮𝘆 𝟱𝟭/𝟭𝟬𝟬 | 𝗜𝗻𝘀𝗲𝗿𝘁𝗶𝗼𝗻 𝗦𝗼𝗿𝘁 𝗟𝗶𝘀𝘁 Day 51 ✅ — Second half begins. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟭𝟰𝟳: Insertion Sort List (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Sort a linked list using insertion sort. The algorithm everyone learns with arrays—now applied to pointers. For each unsorted node, find its correct position in the sorted portion and insert it there. The dummy node pattern made this clean—find the insertion point, adjust pointers, move forward. Day 51. The second half of the journey starts here. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Dummy node for sorted list head 👉 Keep sorted and unsorted portions 👉 For each unsorted node, find insertion position 👉 Adjust pointers to insert node 👉 Continue until entire list is sorted Time: O(n²), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Twenty-two linked list problems. Insertion sort on arrays is basic. On linked lists? It tests if you truly understand pointer manipulation. Yesterday was celebration. Today is execution.𝟰𝟵 𝗺𝗼𝗿𝗲 𝗱𝗮𝘆𝘀. 𝗟𝗲𝘁'𝘀 𝗴𝗼. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gR6h_43V 𝗗𝗮𝘆 𝟱𝟭/𝟭𝟬𝟬 ✅ | 𝟰𝟵 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #InsertionSort #SortingAlgorithms #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming #SecondHalf
More Relevant Posts
-
📌 LeetCode Daily Challenge — Day 16 Problem: 1878. Biggest Three Rhombus Sums in a Grid Topic: Array, Matrix, Sorting, Simulation 📌 Quick Problem Sense: You're given an m × n integer grid. A rhombus is a square rotated 45°, you sum only its border cells, not the inside. Find the top 3 distinct rhombus sums across all valid sizes and positions in descending order. A rhombus of size 0 is just a single cell, every cell counts! 🧠 Approach (Simple Thinking): 🔹 Every cell (i, j) can be the center of a rhombus of size r = 0, 1, 2, ... 🔹 Size 0 = just the cell itself, add it directly 🔹 For size r ≥ 1, walk the 4 diagonal sides of the rhombus border 🔹 Start at the top tip (i-r, j) and walk with directions: (+1,+1), (+1,-1), (-1,-1), (-1,+1) 🔹 Each side has exactly r steps, skip the last cell to avoid double counting corners 🔹 Use a TreeSet capped at size 3 to track top 3 distinct sums automatically 🔹 TreeSet handles sorting + deduplication, just poll the top 3 at the end! ⏱️ Time Complexity: Iterating all centers and sizes → O(m × n × min(m,n)²) Manageable for given constraints! 📦 Space Complexity: TreeSet holds at most 3 values → O(1) No extra matrix or prefix array needed! I wrote a full breakdown with dry run, real-life analogy, and step-by-step code walkthrough here 👇 https://lnkd.in/ggewfAsx If you solved it using diagonal prefix sums or a different top-K trick, drop it in the comments, always curious to see how others think about it 💬 See you in the next problem 👋 #Java #ProblemSolving #DSA #CodingInterview
To view or add a comment, sign in
-
-
Today’s Problem of the Day was Trapping Rain Water — a classic but tricky problem that tests your understanding of two-pointer optimization. ✅ 1111 / 1111 test cases passed ✅ 1 / 1 attempt 🔥 4-day streak ⭐ 8/8 points Instead of using extra prefix/suffix arrays, I implemented the optimized O(n) time and O(1) space two-pointer approach. Key idea: At every index, trapped water depends on min(leftMax, rightMax) - height[i] The challenge isn’t writing code — it’s recognizing why the smaller boundary determines the water level. Problems like this reinforce: • Boundary thinking • Space optimization • Clean pointer movement logic Consistency > Motivation. On to Day 5. 💪 #GeeksforGeeks #ProblemOfTheDay #DataStructures #Algorithms #Java #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟱𝟰/𝟭𝟬𝟬 | 𝗦𝘄𝗮𝗽 𝗡𝗼𝗱𝗲𝘀 𝗶𝗻 𝗣𝗮𝗶𝗿𝘀 Day 54 ✅ — Pointer choreography. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅LeetCode 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟰: Swap Nodes in Pairs (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Swap every two adjacent nodes. Not their values—the actual nodes themselves. This is pure pointer manipulation. Three pointers (prev, first, second), six pointer adjustments per swap. Get one wrong and the list breaks. But when you visualize it? It's just a careful dance of reconnections. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Dummy node for clean head handling 👉 Track prev, first, and second nodes 👉 Reconnect: first.next = second.next 👉 Reconnect: second.next = first 👉 Reconnect: prev.next = second 👉 Move to next pair Time: O(n), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Twenty-five linked list problems. Yesterday swapped values. Today swapped the nodes themselves. The difference? Values = easy. Nodes = pointer precision. This is what 25 days of practice builds—the ability to rewire a data structure without breaking it. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gfn4EgTr 𝗗𝗮𝘆 𝟱𝟰/𝟭𝟬𝟬 ✅ | 𝟰𝟲 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #PointerManipulation #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming #MediumLevel #PrecisionCoding
To view or add a comment, sign in
-
🚀 Day 12 of My LeetCode Journey Today I solved Rotate Image (LeetCode 48). Problem: Given an n × n matrix representing an image, rotate the matrix by 90 degrees clockwise. The challenge is to perform the rotation in-place, without using another matrix. Approach: I used a simple two-step trick: 1️⃣ Transpose the matrix (swap rows and columns) 2️⃣ Reverse each row This combination effectively rotates the matrix by 90° clockwise. Time Complexity: O(n²) Space Complexity: O(1) Problems like this improve understanding of matrix manipulation and in-place transformations. #leetcode #datastructures #algorithms #java #codinginterview #softwareengineering
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟱𝟳/𝟭𝟬𝟬 — 𝗪𝗵𝗲𝗻 𝗦𝘁𝗮𝗰𝗸𝘀 𝗚𝗲𝘁 𝗚𝗿𝗲𝗲𝗱𝘆 Yesterday: Valid Parentheses. Basic stack. Today: Remove Duplicate Letters. Stack + greedy + frequency tracking. Level up. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟯𝟭𝟲: Remove Duplicate Letters (Medium) 𝗧𝗵𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲: Remove duplicate letters so the result is: Smallest in lexicographical order (dictionary order) Contains each letter exactly once Example: "bcabc" → "abc" The trick? Knowing when to remove a character from the stack to make room for a better one. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: Monotonic stack + greedy decisions. 👉 Track frequency: how many times each character appears ahead 👉 Track visited: have we already used this character? 👉 For each character, pop stack if: Stack top is larger (worse for lexicographical order) Stack top appears again later (we can use it then) 👉 Push current character and mark visited Time: O(n), Space: O(1) — only 26 letters max. 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: This combines three patterns: Monotonic stack (maintaining order) Greedy algorithm (making locally optimal choices) Frequency tracking (knowing what's ahead) Solving it wasn't about knowing one technique. It was about combining them. 𝗖𝗼𝗱𝗲: https://lnkd.in/gzw6ACFr 57 down. 43 to go. 𝗗𝗮𝘆 𝟱𝟳/𝟭𝟬𝟬 ✅ #100DaysOfCode #LeetCode #Stack #MonotonicStack #GreedyAlgorithm #DataStructures #Algorithms #CodingInterview #Programming #Java #MediumLevel #PatternCombination
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟳𝟰/𝟭𝟬𝟬 — 𝗠𝗮𝘅𝗶𝗺𝘂𝗺 𝗘𝗿𝗮𝘀𝘂𝗿𝗲 𝗩𝗮𝗹𝘂𝗲 Day 74. Sliding window + hash set. Two patterns, one problem. This is how you level up. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟭𝟲𝟵𝟱: Maximum Erasure Value (Medium) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Find the maximum sum of a subarray with all unique elements. Can't just find max sum. Can't just find unique elements. Need both. 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: Sliding window + hash set. Expand window by moving end. When you hit a duplicate: Shrink from start until duplicate is removed Track sum and uniqueness simultaneously The hash set ensures uniqueness. The sliding window finds the maximum. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Two pointers: start and end 👉 HashSet tracks seen elements 👉 While duplicate exists: remove from start, shrink window 👉 Add current element, update sum 👉 Track maximum sum Time: O(n), Space: O(n) 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: Combining patterns is the real skill. Sliding window alone isn't enough. Hash set alone isn't enough. Together? They solve it. 𝗖𝗼𝗱𝗲: https://lnkd.in/gU3xzr_H 𝗗𝗮𝘆 𝟳𝟰/𝟭𝟬𝟬 ✅ 𝟳𝟰 𝗱𝗼𝘄𝗻. 𝟮𝟲 𝘁𝗼 𝗴𝗼. #100DaysOfCode #LeetCode #SlidingWindow #HashSet #Algorithms #TwoPointer #CodingInterview #Programming #Java #MediumLevel #PatternCombination
To view or add a comment, sign in
-
Day 80/100 – LeetCode Challenge ✅ Problem: #6 Zigzag Conversion Difficulty: Medium Language: Java Approach: Direct String Traversal with Row Pattern Time Complexity: O(n) Space Complexity: O(n) Key Insight: Zigzag pattern repeats every 2 * (numRows - 1) characters. For each row, characters appear at fixed intervals with one middle character for non-first/last rows. Solution Brief: Handled special case numRows == 1 separately. For each row i: Start at index i Add character at current position For middle rows (not first or last), add second character at offset j + 2*(numRows-1) - 2*i Jump by 2*(numRows-1) for next cycle #LeetCode #Day80 #100DaysOfCode #String #Java #Algorithm #CodingChallenge #ProblemSolving #ZigzagConversion #MediumProblem #Pattern #Math #DSA
To view or add a comment, sign in
-
-
Day 51 – DSA Journey 🚀 | Practicing an Array Intersection Problem Continuing my daily DSA practice, today I solved an array intersection problem on LeetCode to strengthen my understanding of sorting and merge-style traversal. 📌 Problem Practiced: Intersection of Two Arrays (LeetCode 349) 🔍 Problem Idea: We are given two integer arrays and need to find their intersection. The result should contain only unique elements that appear in both arrays. 💡 Key Insight: By sorting both arrays, we can use a two-pointer (merge-style) approach to compare elements and identify common values while skipping duplicates. 📌 Approach Used: • Sort both arrays • Use two pointers to traverse them simultaneously • Compare elements and move pointers accordingly • Add common elements while ensuring uniqueness 📌 Concepts Strengthened: • Sorting arrays • Two-pointer technique • Merge-style traversal • Handling duplicates in arrays ⏱️ Time Complexity: O(n log n + m log m) 📦 Space Complexity: O(k) Today’s takeaway: Sorting combined with two-pointer logic is a powerful pattern for solving many array comparison problems. On to Day 52! 🚀 #Day51 #DSAJourney #LeetCode #Arrays #TwoPointers #Java #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟲𝟵/𝟭𝟬𝟬 — 𝗥𝗲𝗺𝗼𝘃𝗲 𝗞 𝗗𝗶𝗴𝗶𝘁𝘀 Day 69. One day from 70. This problem broke my brain. Then it clicked. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟰𝟬𝟮: Remove K Digits (Medium) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a number as a string and k, remove k digits to make the smallest possible number. Example: "1432219", k=3 → "1219" Which 3 digits do you remove? And in what order? 𝗧𝗵𝗲 𝗜𝗻𝘀𝗶𝗴𝗵𝘁: Greedy + Monotonic Stack. Remove a digit if the next digit is smaller. Keep the stack increasing. This builds the smallest number left-to-right. Example: "1432219" See '4' then '3'? Remove '4' See '3' then '2'? Remove '3' See '2' then '2'? Keep both Result: "12219" → remove trailing '9' → "1219" 𝗠𝘆 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: StringBuilder as stack. For each digit: While stack top > current digit AND k > 0: pop and decrement k Append current digit After loop, remove remaining k digits from the end. Strip leading zeros. Time: O(n), Space: O(n) 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: This combines greedy thinking with monotonic stack. Two patterns, one solution. Understanding when to be greedy and when to use a stack—that's the skill. 𝗖𝗼𝗱𝗲: https://lnkd.in/gv36YUfj 𝗗𝗮𝘆 𝟲𝟵/𝟭𝟬𝟬 ✅ 𝟲𝟵 𝗱𝗼𝘄𝗻. 𝟯𝟭 𝘁𝗼 𝗴𝗼. 𝗧𝗼𝗺𝗼𝗿𝗿𝗼𝘄 = 𝟳𝟬. #100DaysOfCode #LeetCode #MonotonicStack #GreedyAlgorithm #Algorithms #CodingInterview #Programming #Java #MediumLevel #PatternCombination #Day70Tomorrow
To view or add a comment, sign in
-
🚀 Day 22/30 – Product of Array Except Self Today’s challenge was to compute an array where each element represents the product of all other elements except itself, without using division and in O(n) time. 💡 Key Insight A naive solution would use division or nested loops, but that either: ❌ Breaks when zero exists ❌ Takes O(n²) time So I used the prefix & suffix product technique. ⚙️ Approach First pass → store left (prefix) product for each index Second pass → multiply with right (suffix) product No division used Constant extra space (excluding output array) ⏱ Complexity Time Complexity: O(n) Space Complexity: O(1) (optimal as per problem constraint) 📊 Performance ✅ All test cases passed ⚡ Faster than 94% of submissions 🧠 Interview-optimal solution 📚 What I Learned This problem strengthened my understanding of: Prefix sum/product patterns Space optimization techniques How to avoid division using traversal logic 📈 Growth Reflection Earlier, I used to think in terms of direct computation. Now I automatically look for: 👉 “Can I precompute values from left and right?” That shift in thinking is the real progress. 🎯 Day 22 complete — moving deeper into core array patterns. #Day22 #30DaysOfCode #LeetCode #Java #Arrays #PrefixSuffix #InterviewPreparation #ProblemSolving #CodingJourney #Consistency #TechGrowth
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