Day 18/100 – LeetCode Challenge 🚀 Problem: Merge Sorted Array Approach: Used three pointers starting from the end of the arrays Compared elements from nums1 and nums2 Placed the larger element at the last available position in nums1 Time Complexity: O(m + n) Space Complexity: O(1) (in-place) Key takeaway: When merging arrays in-place, working from the end avoids unnecessary shifting of elements. #LeetCode #100DaysOfCode #DSA #Java #ProblemSolving #InterviewPrep #100DaysOfLeetCode
Merge Sorted Array in-place with O(m + n) Time Complexity
More Relevant Posts
-
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 27/100 – LeetCode Challenge 🚀 Problem: Sort List Approach: Applied Merge Sort on the linked list Used slow and fast pointers to find the middle Recursively sorted both halves Merged the sorted halves Time Complexity: O(n log n) Space Complexity: O(log n) (recursion stack) Key takeaway: Merge sort is the most efficient sorting technique for linked lists, as it avoids random-access operations required by other algorithms. #LeetCode #100DaysOfCode #DSA #Java #LinkedList #MergeSort #ProblemSolving
To view or add a comment, sign in
-
-
Day 20/100 – LeetCode Challenge 🚀 Problem: Subsets (Power Set) Approach: Started with an empty subset For each number in the array, created new subsets by adding the number to all existing subsets Appended the newly formed subsets to the result list Time Complexity: O(n × 2ⁿ) Space Complexity: O(n × 2ⁿ) (to store all subsets) Key takeaway: Many combinatorial problems can be solved by building results incrementally, expanding previously generated subsets. #LeetCode #100DaysOfCode #DSA #Java #ProblemSolving #Backtracking #100DaysOfLeetCode
To view or add a comment, sign in
-
-
🚀 Day 14 of #100DaysOfCode Solved Merge Two Sorted Lists on LeetCode 🔗🔀 🧠 Key insight: Using a dummy (sentinel) node simplifies pointer handling and avoids edge cases when building the merged list. ⚙️ Approach: 🔹Initialize a dummy node to act as the start of the merged list 🔹Compare nodes from both lists one by one 🔹Attach the smaller node and move the pointer forward 🔹Append remaining nodes once one list is exhausted ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 35/100 – LeetCode Challenge 🚀 Problem: 3Sum Approach: Sorted the array Fixed one element and used two pointers for the remaining two Skipped duplicates to ensure unique triplets Used early stopping when the current number became positive Time Complexity: O(n²) Space Complexity: O(1) Key takeaway: Many 3-element sum problems reduce to sorting + two-pointer pattern. #LeetCode #100DaysOfCode #DSA #Java #TwoPointers #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 13 of #100DaysOfCode Solved Remove Linked List Elements on LeetCode 🔗 🧠 Key insight: While traversing a linked list, careful pointer updates are needed—especially when the head node itself matches the value to be removed. ⚙️ Approach: 🔹Handle cases where the head contains the target value 🔹Traverse the list using a pointer 🔹Skip nodes whose value matches the given target by adjusting next pointers ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
📌 LeetCode Day 38/50 – Linked List Cycle Today’s problem was about detecting a cycle in a linked list. The challenge was to determine whether a linked list contains a loop without using extra memory. 🔍 Approach Used: Used two pointers moving at different speeds If a cycle exists, both pointers will eventually meet This approach runs in O(n) time and O(1) space 💡 Key Takeaway: Understanding pointer movement patterns helps solve complex linked list problems efficiently. 🚀 Consistency is the key — one problem a day brings clarity and confidence! #LeetCode #Day38 #50DaysOfLeetCode #LinkedList #FloydsAlgorithm #DSA #Java #CodingChallenge #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🌱 Day 24 of #100DaysOfCode 🚀 📍 Day 24 Progress Solved problems based on array rotations: 📌Rotate an array from the right 📌Rotate an array in cyclic manner (clockwise) Worked on understanding how shifting elements impacts time complexity and how optimized approaches improve efficiency compared to brute force rotations. #100DaysOfCode #DSA #Arrays #Java #RevisionMode #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
LeetCode Problem || Check if Binary String Has at Most One Segment of Ones(1784)🚀 we need to check: The string should have only one continuous block of '1's. After a '0' appears, '1' should never appear again. ✨ Insight: Instead of manually counting segments using loops, we can simply check if "01" exists in the string. 📌 Time Complexity: O(n) Practicing problems like these helps improve pattern recognition and problem-solving efficiency. #LeetCode #DSA #Java #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 16 of #100DaysOfCode Solved Remove Nth Node from End of List on LeetCode 🔗✂️ 🧠 Key insight: To remove the Nth node from the end, we need to carefully handle edge cases—especially when the node to remove is the head or when n equals the list length. ⚙️ Approach: 🔹First determine the length of the linked list 🔹Calculate the position from the start 🔹Traverse to the node just before the target 🔹Adjust pointers to remove the node safely ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
Explore related topics
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