Day 70/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Reverse Linked List II A neat variation of linked list reversal where only a specific portion of the list is reversed. Problem idea: Reverse a linked list from position left to right, keeping the rest of the list unchanged. Key idea: In-place reversal using pointer manipulation. Why? • We don’t reverse the whole list, only a segment • Need to reconnect the reversed part correctly • Must carefully track boundaries (left and right) How it works: • Use a dummy node to handle edge cases • Move a pointer to the node just before left • Start reversing nodes one by one within the range • Adjust links to insert nodes at the front of the sublist • Reconnect the reversed portion with remaining list Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Partial reversal in linked lists requires precise pointer updates, not extra space. This builds strong intuition for advanced linked list problems. 🔥 Day 70 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #LinkedList #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Reverse Linked List II Problem Solution
More Relevant Posts
-
Day 72/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Rotate List A clean linked list manipulation problem that tests pointer handling. Problem idea: Rotate the linked list to the right by k places. Key idea: Convert list into a cycle + break at the right position. Why? • Direct shifting is inefficient • Linked list doesn’t allow random access • Forming a cycle simplifies rotation logic How it works: • Traverse list to find length • Connect tail → head (make it circular) • Reduce k using modulo 👉 k = k % length • Find new tail at (length - k - 1) • Break the cycle to form new head Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Many linked list problems become easier when you temporarily convert structure (like making a cycle) and then restore it. This trick is very powerful in pointer-based problems. 🔥 Day 72 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #LinkedList #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 68/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Add Two Numbers A fundamental linked list problem that mimics real-life addition. Problem idea: Add two numbers represented by linked lists (digits stored in reverse order). Key idea: Linked list traversal + carry handling. Why? • We process digits one by one (like manual addition) • Need to handle carry at each step • Lists can have different lengths How it works: • Use a dummy node to build the result • Traverse both lists simultaneously • Add values + carry • Create new node with (sum % 10) • Update carry = sum / 10 • Move pointers forward • Continue until both lists and carry are done Time Complexity: O(max(m, n)) Space Complexity: O(max(m, n)) Big takeaway: Using a dummy node simplifies linked list construction and avoids edge cases. This pattern is very common in linked list problems. 🔥 Day 68 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #LinkedList #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 66/100 🚀 | #100DaysOfDSA Solved LeetCode 14 – Longest Common Prefix today. The task was to find the longest common prefix string among an array of strings. Initially, I couldn’t come up with this optimal approach and first solved it using a brute-force O(n²) method, comparing characters across all strings. Approach (Optimized): Used sorting to simplify the problem. • Sorted the array of strings. • Took the first and last strings after sorting. • Compared characters of both strings until they differ. • The common prefix between these two will be the answer for all strings. This works because after sorting, the most different strings will be at the extremes. Time Complexity: O(n log n + m) (where n = number of strings, m = length of prefix comparison) Space Complexity: O(1) (ignoring sorting space) Key takeaway: Sorting can sometimes reduce multi-string comparison problems to just comparing two extreme cases, making the solution much simpler and efficient. #100DaysOfDSA #LeetCode #DSA #Java #Strings #Sorting #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 75 of 365 – Triangular Sum of an Array 🔺 One of those problems that looks harmless… until it quietly tests your fundamentals. My approach? Recursive reduction. Keep building the next array using adjacent sums until only one element remains. [1,2,3,4,5] [3,5,7,9] [8,2,6] [0,8] [8] ⚠️ Where I went wrong I initially messed up the base case and recursion flow. Returned from the wrong place Tried accessing values that didn’t exist Didn’t fully trust the recursion chain Classic case of: “Logic sahi tha, execution hil gaya.” ✅ Fix Correct base case → when size == 1, return it Build next array properly Pass result through recursion cleanly That’s it. No overthinking. 💡 What I learned Recursion is simple… until you break the base case Most bugs are not in logic, but in boundaries Clean recursion = clean thinking Day 75 done ✅ Still showing up. Still sharpening. #Day75 #365DaysOfDSAChallenge #LeetCode #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
Day 69/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Reverse Nodes in k-Group A challenging linked list problem focused on reversing nodes in fixed-size groups. Problem idea: Reverse nodes of a linked list in groups of size k, while keeping remaining nodes as it is. Key idea: Linked list manipulation + iterative reversal in segments. Why? • We need to reverse nodes in chunks, not the whole list • Careful pointer handling is required • Must preserve connections between groups How it works: • Use a dummy node for easier handling of head • Identify the k-th node from current position • Reverse nodes between current and k-th node • Connect reversed group back to the list • Move to next group and repeat • Stop if remaining nodes are less than k Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Mastering pointer manipulation in linked lists is key to solving advanced problems efficiently. This problem is a great example of combining reversal logic with structural control. 🔥 Day 69 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #LinkedList #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 67/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Subsets II Another classic backtracking problem with a twist (duplicates). Problem idea: Generate all possible subsets (power set), but avoid duplicate subsets. Key idea: Backtracking + sorting to handle duplicates. Why? • We need to explore all subset combinations • Duplicates in input can lead to duplicate subsets • Sorting helps us skip repeated elements efficiently How it works: • Sort the array first • At each step, add current subset to result • Iterate through elements • Skip duplicates using condition: 👉 if (i > start && nums[i] == nums[i-1]) continue • Choose → recurse → backtrack Time Complexity: O(2^n) Space Complexity: O(n) recursion depth Big takeaway: Handling duplicates in backtracking requires careful skipping logic, not extra data structures. This pattern appears in many problems (subsets, permutations, combinations). 🔥 Day 67 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Recursion #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 113 - LeetCode Journey Solved LeetCode 222 – Count Complete Tree Nodes ✅ This problem involves counting the total number of nodes in a complete binary tree, where all levels are fully filled except possibly the last, and nodes are as far left as possible. Approach: I implemented a recursive solution to count nodes. For each node, I recursively calculated the number of nodes in the left and right subtrees and added 1 for the current node. Although this solution works correctly, it follows a straightforward traversal approach and does not fully utilize the properties of a complete binary tree. A more optimized approach can reduce time complexity by comparing left and right subtree heights to detect perfect subtrees and compute their node count directly. Complexity Analysis: • Time Complexity: O(n) • Space Complexity: O(h), where h is the height of the tree (recursion stack) Key Takeaways: • Basic tree traversal (DFS) can solve counting problems effectively • Understanding tree properties can help in optimizing solutions further • Complete binary trees allow more efficient approaches than general trees All test cases passed successfully 🎯 #LeetCode #DSA #BinaryTree #Recursion #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟖𝟏/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐗𝐎𝐑 𝐀𝐟𝐭𝐞𝐫 𝐑𝐚𝐧𝐠𝐞 𝐌𝐮𝐥𝐭𝐢𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐐𝐮𝐞𝐫𝐢𝐞𝐬 𝐈𝐈 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Group queries based on step size k. For small k, use prefix multiplication (range product trick) to apply updates efficiently. For large k, process directly since updates are fewer. Maintain a multiplier array and apply all updates at the end. Finally compute XOR of the transformed array. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Sqrt decomposition + prefix product + modular inverse + hashing. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: ~𝐎(𝐧 √𝐧 + 𝐪 √𝐧) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: When operations vary by step size, splitting into small and large cases (sqrt decomposition) can drastically optimize performance. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #Optimization #Math #PrefixSum #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
🧠 Day 206 — Minimum Distance to Target 🎯📍 Today solved a simple yet important problem and did some revision alongside. 📌 Problem Goal Given an array, a target value, and a starting index: ✔️ Find the minimum distance between the start index and any index where the target exists 🔹 Core Idea Traverse the array and: ✔️ Check if current element matches the target ✔️ Calculate distance from the start index ✔️ Keep updating the minimum distance 🔹 Key Observation ✔️ Only indices with the target matter ✔️ Distance = absolute difference between indices ✔️ Simple linear scan gives optimal solution 🧠 Key Learning ✔️ Even easy problems strengthen fundamentals ✔️ Brute-force with clarity > overthinking ✔️ Absolute difference patterns are very common in arrays 💡 Today’s Realization Not every day needs to be a hard problem. Consistency with simple + revision days builds stronger intuition. 🚀 Momentum Status: Staying consistent and sharpening basics. On to Day 207. #DSA #Arrays #ProblemSolving #LeetCode #Java #CodingJourney #ConsistencyWins
To view or add a comment, sign in
-
Day 62/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Combination Sum Classic backtracking problem. Problem idea: Find all unique combinations where numbers sum up to a target. Each number can be used unlimited times. Key idea: Use backtracking (choose → explore → backtrack). Why? • We need to explore all possible combinations • Stop when sum exceeds target • Add result when sum == target How it works: • Pick a number • Stay on same index (reuse allowed) • Move forward when skipping • Backtrack to try other paths Time Complexity: Exponential (depends on combinations) Space Complexity: O(target) recursion depth Big takeaway: Backtracking is all about exploring choices and undoing them efficiently. This pattern is super important for recursion problems. 🔥 Day 62 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
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