🚀 Day 49 of #100DaysOfCode Solved 86. Partition List on LeetCode 🔗 🧠 Key Insight: We need to rearrange a linked list such that: 🔹All nodes < x come before nodes ≥ x 🔹While maintaining the original relative order This is a classic linked list partitioning problem. ⚙️ Approach: 1️⃣ Create two dummy lists: 🔹small → nodes with values < x 🔹large → nodes with values ≥ x 2️⃣ Traverse the original list: 🔹Append each node to the appropriate list 3️⃣ Connect both lists: 🔹small → large 4️⃣ Return the head of the new list 🎯 This ensures: 🔹Stable ordering 🔹Clean and efficient separation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (no extra nodes, just pointers) #100DaysOfCode #LeetCode #DSA #LinkedList #Algorithms #Java #CodingPractice #InterviewPrep
Partitioning a Linked List on LeetCode
More Relevant Posts
-
Day 41 of Daily DSA 🚀 Solved LeetCode 20: Valid Parentheses ✅ Problem: Given a string containing only (), {}, [], determine if the input string is valid. Rules: Open brackets must be closed by the same type Open brackets must be closed in the correct order Every closing bracket must have a matching opening bracket Approach: Used a Stack to track opening brackets and validate matching pairs. Steps: Traverse the string Push opening brackets onto the stack For closing brackets → check top of stack If it matches → pop Else → return false At the end, stack should be empty ⏱ Complexity: • Time: O(n) • Space: O(n) 📊 LeetCode Stats: • Runtime: 3 ms (Beats 87.41%) ⚡ • Memory: 43.37 MB A classic stack problem that builds strong fundamentals for expression parsing & validation. #DSA #LeetCode #Java #Stack #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 51 of #100DaysOfCode Solved 328. Odd Even Linked List on LeetCode 🔗 🧠 Key Insight: We need to rearrange the linked list such that: 🔹All odd-indexed nodes come first 🔹Followed by all even-indexed nodes 🔹While preserving the relative order ⚠️ Important: This is based on node position (index), not value. ⚙️ Approach: 1️⃣ Create two separate lists: 🔹odd → nodes at odd positions 🔹even → nodes at even positions 2️⃣ Traverse the list and distribute nodes accordingly 3️⃣ Connect: 🔹End of odd list → head of even list 4️⃣ Return the new head 🎯 This ensures a clean separation while maintaining order. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (in-place re-linking) #100DaysOfCode #LeetCode #DSA #LinkedList #Algorithms #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Solved 222. Count Complete Tree Nodes on LeetCode 🔗 🧠 Key Insight: In a complete binary tree, all levels are fully filled except possibly the last, and nodes are as left as possible. 👉 This property helps us optimize beyond simple traversal ⚙️ Approach (Simple DFS - Your Solution): 1️⃣ If root is null → return 0 2️⃣ Recursively count: 🔹 left = countNodes(root.left) 🔹 right = countNodes(root.right) 3️⃣ Total nodes: 👉 1 + left + right ⏱️ Time Complexity: Current → O(n) Optimized → O(log² n) 📦 Space Complexity: O(h) #100DaysOfCode #LeetCode #DSA #BinaryTree #Recursion #DivideAndConquer #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🧠 Day 32 / 100 – DSA Practice Solved Symmetric Tree on LeetCode 🌳✅ 🔹 Problem: Check whether a binary tree is a mirror of itself (symmetric around its center). 🔹 Approach: Used a recursive mirror check: Compare left subtree with right subtree Check if: ✔️ Values are equal ✔️ Left of one == Right of other ✔️ Right of one == Left of other 🔁 Recursively verified symmetry at each level 🔹 Complexity: ⏱ Time → O(n) 📦 Space → O(n) (recursion stack) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Understanding recursion patterns in trees is getting stronger day by day 🚀 #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinaryTree #Recursion #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 62 of #100DaysOfCode 🌱 Topic: Trees / Recursion ✅ Problem Solved: LeetCode 112 – Path Sum 🛠 Approach: Used DFS (recursion) to explore all root-to-leaf paths. Base Case: If node is null → return false If leaf node: Check if target == node.val → return result Otherwise: Reduce target → target - node.val Recurse on left and right subtree #100DaysOfCode #Day62 #DSA #Trees #Recursion #DFS #LeetCode #Java #BinaryTree #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀Day 40 LeetCode 1161 – Maximum Level Sum of a Binary Tree Ever wondered how to find the level of a binary tree with the maximum sum of node values? 🤔 Here’s the idea: We traverse the tree level by level (BFS) and compute the sum at each level. The trick is to keep track of the maximum sum and return the smallest level where this occurs. 💡 Key Insight: Level-order traversal (using a queue) naturally processes nodes one level at a time, making it perfect for this problem. 🔧 Approach: ✔ Use a queue for BFS ✔ For each level: • Calculate sum of nodes ✔ Track maximum sum and corresponding level 🔥 Takeaway: Whenever a problem involves levels in a tree, think BFS first — it often leads to the cleanest solution. #LeetCode #DataStructures #Java #CodingInterview #BinaryTree #BFS #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 76 of #100DaysOfCode Solved 725. Split Linked List in Parts on LeetCode 🔗 🧠 Key Insight: We need to split a linked list into k parts such that: 👉 Sizes are as equal as possible 👉 Earlier parts can have at most one extra node ⚙️ Approach (Length + Distribution): 1️⃣ Find length of linked list → len 2️⃣ Compute: 🔹 partSize = len / k 🔹 extra = len % k 👉 First extra parts will have partSize + 1 nodes 3️⃣ Traverse and split: 🔹 For each part: • Assign size = partSize + (extra > 0 ? 1 : 0) • Move pointer that many nodes • Break link (next = null) • Decrement extra 4️⃣ If len < k: 🔹 Some parts will be null ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) (result array) #100DaysOfCode #LeetCode #DSA #LinkedList #Simulation #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode Solved 107. Binary Tree Level Order Traversal II on LeetCode 🔗 🧠 Key Insight: This is just level order traversal (BFS) but: 👉 Return levels from bottom to top instead of top to bottom ⚙️ Approach (DFS with Level Tracking): 1️⃣ Start traversal with level = 0 2️⃣ For each node: 🔹 If level not present → insert new list at front 🔹 Add value at correct position: 👉 res.get(res.size() - 1 - level) 3️⃣ Recurse: 🔹 Left → level + 1 🔹 Right → level + 1 ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #100DaysOfCode #LeetCode #DSA #BinaryTree #BFS #DFS #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 34/50 🚀 — Score of a String Today’s problem was all about observing patterns in characters and keeping the approach simple. 🔹 Compared ASCII values of adjacent characters 🔹 Used absolute difference to calculate contribution 🔹 Built the result in a single pass (no extra space) Key insight: Sometimes you don’t need complex data structures—just a clean loop and understanding how characters behave as numbers. 💡 Simple logic, implemented cleanly, is often the most efficient solution. Performance: ⚡ Runtime: 1 ms (99%+) 📦 Memory: Efficient #Day34 #50DaysOfCode #Java #DSA #ProblemSolving
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