🚀 Day 19 of #100DaysOfCode Solved 2. Add Two Numbers on LeetCode ➕🔗 (in-place linked list approach) 🧠 Key insight: Instead of creating a new list, we can reuse the longer linked list and perform addition in place, handling carry carefully across nodes. ⚙️ Approach: 🔹Calculate the size of both linked lists 🔹Use the longer list as the result list 🔹Traverse both lists, adding values with carry 🔹Continue processing remaining nodes of the longer list 🔹Append a new node if a carry remains at the end ⏱️ Time Complexity: O(max(n, m)) 📦 Space Complexity: O(1) (no extra list created) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
Adding Two Numbers in Place with Linked List Approach
More Relevant Posts
-
Solved "Container With Most Water" on LeetCode today using the Two-Pointer Technique. 🚀 The key insight is that the area formed by two lines depends on the shorter height and the distance between them. Starting with pointers at both ends of the array, we compute the area and move the pointer at the smaller height inward to potentially find a taller boundary and maximize the area. This approach efficiently reduces the problem from O(n²) brute force to O(n) time with O(1) space. Problems like this are a great reminder that the right observation can drastically optimize a solution. 💡 #LeetCode #DSA #TwoPointers #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 48 / 100 | Combinations Intuition: The idea is to gradually build combinations by choosing numbers starting from a given index. By always moving forward, we avoid duplicates and ensure each combination is unique. Approach: Use backtracking to generate all possible combinations. Maintain a list to store the current combination. Start selecting numbers from a given starting point. Add a number to the list and recursively continue building the combination. Once the size of the list becomes k, we store it as a valid combination. After exploring a choice, remove the last number (backtrack) and try the next possible number. Complexity: Time Complexity: O(k*C(n,k)) Space Complexity: O(k) #100DaysOfCode #Java #DSA #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 Day 33 of #100DaysOfCode Solved 25. Reverse Nodes in K-Group on LeetCode 🔁 🧠 Key Idea: Reverse nodes of a linked list k at a time, while keeping the remaining nodes unchanged if they are fewer than k. ⚙️ Approach: 🔹Traverse the list to check if k nodes exist. 🔹If fewer than k nodes remain → return the list as it is. 🔹Reverse the current k-group using a helper reverse function. 🔹Recursively apply the same logic to the remaining list. 🔹Connect the reversed group with the result of the recursive call. This approach makes the solution clean and modular by separating the logic of: 🔹Finding k nodes 🔹Reversing a segment 🔹Connecting segments ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n/k) (due to recursion stack) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 25 of #100DaysOfCode Solved 24. Swap Nodes in Pairs on LeetCode 🔗🔄 🧠 Key insight: Swapping nodes in a linked list doesn’t require extra memory—careful pointer updates are enough to reverse every adjacent pair. ⚙️ Approach: 🔹Traverse the list two nodes at a time 🔹Reverse links between each adjacent pair 🔹Maintain connections with the previous pair to keep the list intact 🔹Handle edge cases for odd-length lists ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 40 of 100 Days of Code 🚀 Solved Maximum Consecutive Ones today. 🔹 Problem: Find the longest streak of 1’s in a binary array. 🔹 Approach: Single pass with running counter. Key idea: - Increment count when we see 1 - Reset when we see 0 - Track maximum during traversal ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Small problems strengthen logical thinking and loop control. #LeetCode #DSA #Java #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 31/100 – LeetCode Challenge 🚀 Problem: Roman to Integer Approach: Mapped Roman symbols to their integer values Traversed the string once If the current value was less than the next value, subtracted it Otherwise, added it to the total Time Complexity: O(n) Space Complexity: O(1) Key takeaway: When dealing with special formatting rules (like subtraction cases), comparing the current and next element often simplifies the logic. #LeetCode #100DaysOfCode #DSA #Java #Strings #ProblemSolving
To view or add a comment, sign in
-
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 44 / 100 | Subsets Intuition: The task is to generate all possible subsets of a given array. Each element has two choices: either include it in the subset or exclude it. By exploring every possible combination of these choices, we can generate all subsets. Backtracking helps us build subsets step by step and explore all possibilities. Approach: O(n * 2^n) Start with an empty subset. Use backtracking to explore all subset combinations. At each step, add the current subset to the result list. Iterate through the remaining elements of the array. Include the current element in the subset and move forward recursively. After recursion, remove the element (backtrack) to explore other possibilities. Continue this process until all subsets are generated. Complexity: Time Complexity: O(n * 2^n) Space Complexity: O(n) #100DaysOfCode #Java #DSA #LeetCode #Backtracking
To view or add a comment, sign in
-
-
Day 36/100 – LeetCode Challenge 🚀 Problem: 3Sum Closest Approach: Sorted the array Fixed one element and applied the two-pointer technique Tracked the closest sum by comparing absolute differences Returned immediately if an exact match was found Time Complexity: O(n²) Space Complexity: O(1) Key takeaway: Many optimization problems are variations of classic patterns. Understanding 3Sum deeply makes solving 3Sum Closest straightforward. #LeetCode #100DaysOfCode #DSA #Java #TwoPointers #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 23/100 – LeetCode Challenge Today’s problem: Partitioning Into Minimum Number of Deci-Binary Numbers 🔹 Key Insight: The minimum number of deci-binary numbers required is equal to the maximum digit present in the string. 🔹 Approach: Traverse through each character in the string Convert it to integer (ch - '0') Track the maximum digit Return the maximum value 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) ✨ Simple logic, but powerful observation! Instead of constructing numbers, we just analyze the digits. Consistency > Motivation 💪 #Day23 #100DaysOfCode #LeetCode #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