Day 23 — Medium — Partition List Today’s problem was “Partition List.” At first, it wasn’t obvious how to rearrange nodes while keeping their relative order intact. I tried a few approaches but eventually had to look at the answer to understand the right method. Once I saw the solution, it clicked — building two separate lists (one for nodes smaller than the target value, and another for nodes greater or equal) and then connecting them gives the correct partition while preserving order. It took me a while, but after revisiting the explanation, I was able to crack the algorithm on my own. Key takeaway: Sometimes checking the answer isn’t failure — it’s just another step in learning. What matters is revisiting, rethinking, and making the solution your own. #100DaysOfCode #DSA #Java #LinkedLists #ProblemSolving #CodingJourney
Mohammad Taufeeq’s Post
More Relevant Posts
-
🚀Day 12/100 - Problem of the day :- Binary Tree Preorder Traversal. 🎯 Goal: To perform a Preorder Traversal of a Binary Tree and return the sequence of nodes in root → left → right order. 💡 Core Idea: Use recursion to visit the root node first, then traverse the left subtree, followed by the right subtree. 📘 Key Takeaway: Preorder traversal is ideal for creating a copy of a tree or expressing it in prefix form — where each node is processed before its subtrees. ⚙️ Method Used: Recursive Depth-First Search (DFS) approach Visit the current node (root) Recursively traverse the left child Recursively traverse the right child 💾 Space Complexity: O(n) — due to recursion stack and list storing the traversal output. ⏱️ Time Complexity: O(n) — every node is visited exactly once. #100DaysChallenge #DSA #Java #Day12 #PreOrderTraversal #BinaryTree #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 45 of #100DaysOfCode 🔥 💡 Problem: Length of Last Word ✨ Approach: Trimmed the trailing spaces and used the power of lastIndexOf(' ') to pinpoint the final space — subtracting positions gives the length of the last word. Simple, clean, and blazing fast ⚡ ⚡ Complexity: Time Complexity: O(n) — linear scan through the string. Space Complexity: O(1) — no extra memory used. 📊 Result: ✔️ Accepted (60/60 test cases passed) ⚡ Runtime: 0 ms (🚀 Beats 100.00%) 💾 Memory: 41.55 MB (🔥 Beats 91.62%) 🔑 Key Insight: Elegance in code often comes from simplicity — a single line of logic can beat brute force every time 💫 #LeetCode #100DaysOfCode #Java #StringManipulation #ProblemSolving #CodingChallenge #CleanCode #DSA
To view or add a comment, sign in
-
-
🧮 LeetCode 2652 – Sum Multiples 🧮 Today I solved LeetCode Problem #2652: Sum Multiples, a simple yet insightful problem that reinforces the fundamentals of loops, conditional logic, and divisibility checks in Java. 📝 Problem Overview: Given an integer n, calculate the sum of all numbers between 1 and n that are divisible by 3, 5, or 7. 👉 Example: Input: n = 7 → Output: 21 Explanation: 3 + 5 + 6 + 7 = 21 💡 Approach: Loop through all numbers from 1 to n. Check if the number is divisible by 3, 5, or 7. If it is, add it to the running total. Return the final sum. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single loop through the range. ✅ Space Complexity: O(1) — Constant space usage. ✨ Key Takeaways: Practiced looping and modular operations in Java. Strengthened logical reasoning for filtering conditions. Reinforced the idea that clarity and simplicity lead to clean, efficient solutions. 🌱 Reflection: Even straightforward problems like this one help in developing consistency and precision — both essential for mastering problem-solving and preparing for advanced challenges. #LeetCode #2652 #Java #DSA #ProblemSolving #CodingJourney #LogicBuilding #ConsistencyIsKey #DailyCoding
To view or add a comment, sign in
-
-
✨ Day 46 of 100: Simplify Path ✨ Today’s challenge was LeetCode 71 – Simplify Path 🧭 🧩 Problem Summary: Given an absolute path in a Unix-style file system, simplify it so that it represents the canonical path. We need to correctly handle ".", "..", and multiple slashes "/" while maintaining the correct directory structure. 💡 Key Takeaways: 🔹 Strengthened understanding of stack-based path traversal. 🔹 Learned how ".." can be used to move up directories and "." can be ignored. 🔹 Practiced string manipulation using split() and String.join() in Java. 🔹 Reinforced handling of edge cases like multiple consecutive slashes. 🧠 Core Idea: Use a Stack to keep track of valid directory names and rebuild the simplified path at the end. 💻 Language: Java ☕ #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #DSA #SimplifyPath #WomenWhoCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 33 of #50DaysOfLeetCodeChallenge Problem: 3Sum Given an integer array, find all unique triplets that sum up to zero. 🔍 Approach: Used the Two Pointer Technique after sorting the array. For each element, I fixed one number and used two pointers (left and right) to find pairs that complement it to make zero — skipping duplicates along the way for efficiency. 🧠 Key Takeaways: Sorting simplifies duplicate handling. Two pointers help reduce time complexity from O(n³) → O(n²). Clean implementation using conditions to skip repeated numbers. ⏱️ Runtime: 31 ms (beats 56.43%) 💾 Memory: 51.76 MB #LeetCode #CodingChallenge #ProblemSolving #Java #DSA #TwoPointers #50DaysOfCode
To view or add a comment, sign in
-
-
LeetCode Question #199 — Binary Tree Right Side View Thrilled to share another Accepted Solution (100% Runtime 🚀) on LeetCode! This problem focuses on Binary Trees — specifically, how to capture the view of a tree from its right side 🌳➡️. I implemented a Modified Pre-Order Traversal (Root → Right → Left) in Java, ensuring that the first node at each level (from the right) gets recorded. 💡 Key Idea: Use recursion with a level tracker — when the current level equals the list size, it means we’re seeing the rightmost node for the first time. Here’s the performance snapshot: ⚙️ Runtime: 0 ms (Beats 100% of Java submissions) 💾 Memory: 42.4 MB Every problem like this sharpens my understanding of tree traversal patterns and depth-first search optimization. #LeetCode #Java #DataStructures #BinaryTree #ProblemSolving #CodingJourney #DSA #100PercentRuntime
To view or add a comment, sign in
-
-
🔹 Day 23: Power of Three (LeetCode #326) 📌 Problem Statement: Given an integer n, return true if it is a power of three. Otherwise, return false. (i.e., there exists an integer x such that n == 3^x). ✅ My Approach (Java): If n ≤ 0, return false (since powers of 3 are always positive). Keep dividing n by 3 while it’s divisible by 3. If the final result becomes 1, it’s a power of three. 📊 Complexity: Time Complexity: O(log₃ n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 8 ms (beats 81.49%) Memory: 44.95 MB 💡 Reflection: This was a neat math-based problem. It’s always satisfying to see how simple logic — dividing repeatedly — can lead to a clean and efficient solution. Mathematics + Programming = 🔥 #LeetCode #Java #ProblemSolving #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
📌 Day 13/100 - Valid Anagram (LeetCode 242) 🔹 Problem: Given two strings s and t, determine whether t is an anagram of s. An anagram is formed by rearranging the letters of one word to create another word — meaning both strings must have the same characters with the same frequency. 🔹 Approach: First, check if both strings are of equal length — if not, they can’t be anagrams. Convert both strings into character arrays. Sort both arrays and compare them using Arrays.equals(). If both sorted arrays are identical, the strings are anagrams. 🔹 Key Learning: Sorting can simplify comparison-based string problems. Always check base conditions (like length) to avoid unnecessary computation. This approach has a time complexity of O(n log n) due to sorting, which is efficient enough for this problem. Every solved challenge is another letter added to the dictionary of progress! 🚀 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
23/30 days✅ Solved LeetCode Problem : #70 – Climbing Stairs The challenge was to determine how many distinct ways one can reach the top of a staircase with n steps, where at each step you can either climb 1 or 2 steps. The logic behind the problem is similar to the Fibonacci sequence, where each state depends on the sum of the previous two states. I implemented the solution in Java, using an iterative approach with three variables to optimize space complexity. Instead of using recursion or an array, the approach updates values in constant space (O(1)) while maintaining linear time complexity (O(n)). Here’s the logic in brief: Initialize a = 0, b = 1, and c = 1. For each step, compute c = a + b, then shift values forward (a = b, b = c). Return c as the total number of distinct ways to reach the top. #LeetCode #Java #DynamicProgramming #ProblemSolving #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