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
Reverse Linked List Nodes in k-Group
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 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
-
💡 LeetCode 191 — Number of 1 Bits (Hamming Weight) Recently solved an interesting bit manipulation problem that highlights the power of low-level optimization 🚀 🔍 Problem Statement: Given an unsigned integer, count the number of set bits (1s) in its binary representation. 🧠 Key Insight: Instead of checking every bit individually, we can use a clever trick: 👉 n & (n - 1) removes the rightmost set bit in each operation. This allows us to count only the set bits, making the solution more efficient. ⚙️ Approach Used (Brian Kernighan’s Algorithm): Initialize a counter Repeatedly apply n = n & (n - 1) Increment count until n becomes 0 📈 Time Complexity: O(k), where k = number of set bits (faster than checking all 32 bits) 📦 Space Complexity: O(1) ✨ Why this problem is important: Strengthens understanding of bit manipulation Frequently asked in interviews Useful in low-level optimization and system design 💬 Takeaway: Sometimes the best solutions come from understanding how data is represented at the binary level. Small tricks can lead to big optimizations! #LeetCode #DSA #CodingInterview #Java #BitManipulation #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
Day 65/100 | #100DaysOfDSA 🧩🚀 Today’s problem: N-Queens A classic hard backtracking problem. Problem idea: Place N queens on an N×N chessboard such that no two queens attack each other. Key idea: Use backtracking with efficient conflict checking. Why? • We must explore all valid board configurations • Reject placements that cause conflicts • Continue building only valid states How it works: • Place one queen per row • Track columns, diagonals, anti-diagonals • Use bit masking for faster checks ⚡ • Try placing → recurse → backtrack Optimization: Using bitmasks drastically reduces time compared to naive checking. Time Complexity: Exponential (but optimized with pruning) Space Complexity: O(n) recursion depth Big takeaway: Efficient state tracking (cols + diagonals) turns a brute-force problem into a much faster solution. 🔥 One of the most important backtracking problems to master! Day 65 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Recursion #BitManipulation #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
-
Day 79/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Flatten Binary Tree to Linked List A powerful tree transformation problem using pointer manipulation. Problem idea: Convert a binary tree into a linked list in-place following preorder traversal. Key idea: Iterative traversal + rewiring (similar to Morris traversal idea). Why? • We need preorder sequence (Root → Left → Right) • Instead of extra space, we modify pointers in-place • Efficient and avoids recursion stack How it works: • Traverse using a pointer curr • If left child exists: → Find rightmost node of left subtree → Connect it to current’s right subtree → Move left subtree to right → Set left = null • Move to next node (curr.right) Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Tree problems can often be optimized using in-place pointer rewiring, avoiding extra space. 🔥 This pattern is very useful for tree flattening and traversal optimizations. Day 79 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #MorrisTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 85/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Populating Next Right Pointers in Each Node A clean pointer-manipulation problem that strengthens tree traversal intuition without extra space. Problem idea: Given a perfect binary tree, connect each node to its next right node using a next pointer. Key idea: Level-by-level traversal using already established next pointers (no queue needed). Why? • The tree is perfect → every level is fully filled • We can use existing next links to move horizontally • This avoids extra space (unlike BFS with a queue) How it works: • Start from the leftmost node of each level • Connect left child → right child • If a next node exists, connect right child → next node’s left child • Move across the level using next pointers • Then go down to the next level Time Complexity: O(n) Space Complexity: O(1) Big takeaway: When a tree is perfect, you can often avoid extra space by cleverly using existing structure (like next pointers). 🔥 This is a powerful pattern for constant-space tree traversal problems. Day 85 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #Pointers #TreeTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 30/50 💡 Approach: HashSet (Sequence Start Detection) Sorting would give O(n log n) — but the problem demands O(n)! The trick? Use a HashSet and only start counting from the BEGINNING of each sequence! 🔍 Key Insight: → Add all numbers to a HashSet (O(1) lookup) → For each number, check if (num - 1) exists in set → If NOT → it's the start of a new sequence! → Count upward (num+1, num+2...) while consecutive numbers exist → Update maxLength at each sequence end 📈 Complexity: ❌ Sorting approach → O(n log n) Time ✅ HashSet approach → O(n) Time, O(n) Space Each number is visited at most twice across all sequences! 🎉 Day 30/50 — 60% done and still going strong! The best optimizations come from asking: ‘What information can I precompute?’ A HashSet turned O(n log n) into O(n)! 🔥 #LeetCode #DSA #HashSet #Java #ADA #PBL2 #LeetCodeChallenge #Day30of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #LongestConsecutiveSequence
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
-
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