Day 92/100 Completed ✅ 🚀 Solved LeetCode: Median of Two Sorted Arrays (Java) ⚡ Used a two-pointer approach to efficiently find the median without fully merging the arrays. Focused only on tracking the required middle elements, reducing unnecessary space usage. 🧠 Key Learnings: • Applying two-pointer technique on sorted arrays • Handling edge cases when one array is exhausted • Understanding median logic for even vs odd total length • Optimizing space by avoiding full array merge 💡 This problem highlighted how tracking only what’s necessary can lead to better performance and cleaner solutions. Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #twopointers #array #coding #problemSolving
Solved LeetCode Median of Two Sorted Arrays (Java)
More Relevant Posts
-
Solved the Copy List with Random Pointer problem using an in-place approach. Instead of using extra space like HashMap, the solution inserts copied nodes in between original nodes, sets random pointers, and then separates both lists. This keeps the solution efficient in both time and space. Time Complexity: O(n) Space Complexity: O(1) #Java #DSA #LinkedList #LeetCode #Coding
To view or add a comment, sign in
-
-
🚀100 Days of Code Day-26 LeetCode Practice – Remove Duplicates from Sorted Array Solved a classic problem using the Two Pointer Technique 💡 📌 Problem: Given a sorted array, remove duplicates in-place and return the number of unique elements. 🔍 Key Idea: Since the array is sorted, duplicates are adjacent. Using two pointers helps efficiently overwrite duplicates without extra space. ⚡ Complexity: Time → O(n) Space → O(1) 💻 Clean and optimized approach makes this problem a great example of in-place array manipulation! #LeetCode #Java #DataStructures #CodingPractice #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 35 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Valid Anagram Problem Insight: Given two strings, check if one is an anagram of the other. Approach: • First, check if the strings have the same length; if not, return false • Convert both strings to character arrays • Sort both arrays • Compare the sorted arrays — if equal, the strings are anagrams Time Complexity: • O(n log n) — due to sorting the arrays Space Complexity: • O(n) — for the character arrays Key Learnings: • Sorting is a simple and effective way to compare character compositions • Edge cases like different lengths should be handled first • Breaking the problem into small steps makes it easy to reason about Takeaway: Sometimes, sorting can reduce a seemingly complex problem into a simple comparison. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Strings
To view or add a comment, sign in
-
-
Solved the Remove Duplicates from Sorted Linked List problem using iterative traversal. The idea is to traverse the list and compare current node with next node. If values are same, skip the duplicate node by adjusting pointers; otherwise move forward. Since the list is sorted, duplicates are always adjacent, making it efficient. Time Complexity: O(n) Space Complexity: O(1) #Java #DSA #LinkedList #LeetCode #Coding
To view or add a comment, sign in
-
-
Day 80/90 Solved: Largest Rectangle in Histogram Core idea: → Use monotonic stack to find nearest smaller to left & right → Width = (right - left - 1), maximize area This is one of those problems where the pattern isn’t obvious at first. Once the left/right boundary logic clicks, the solution becomes systematic. #Consistency #DSA #LeetCode #Stack #MonotonicStack #ProblemSolving #Java #Algorithms
To view or add a comment, sign in
-
-
Day 79 - Binary Tree Paths Solved a problem on generating all root-to-leaf paths in a binary tree using DFS recursion. This improves understanding of tree traversal and path construction techniques. Time Complexity: O(N) Space Complexity: O(N) #Day79 #CodingChallenge #LeetCode #BinaryTree #DSA #Java #Recursion #CodingJourney
To view or add a comment, sign in
-
-
Day 75 - Count Complete Tree Nodes Finding the total number of nodes in a complete binary tree using recursion. Approach: • Traverse the tree recursively • Count left subtree • Count right subtree • Add 1 for current node Time Complexity: O(n) Space Complexity: O(h) #Day75 #LeetCode #Java #CodingPractice #TechJourney #DSA #BinaryTree
To view or add a comment, sign in
-
-
🔥 Today’s DSA Update— #Day58 #MonotonicStack Today I worked on finding Next Greater Element I (Leetcode 496). 💡 What I understood This pattern is useful for problems where we need to find things like: 1. Next greater element 2. Next smaller element Instead of using nested loops (which take O(n²)), we can solve it in O(n) using a stack. 💡 The key idea We use a stack to keep elements that are still “waiting” for their answer. When we find a bigger element: 1. We pop all smaller elements from the stack 2. For each popped element, we now know its next greater value 3. Each element is pushed and popped only once. 🧠 What I learned today Today’s lesson was that stacks are not just for push and pop operations — they can be used to store state while processing elements. This pattern feels different from normal array traversal because we are managing a “waiting list” of elements. #Java #DSA #Stack #DataStructures #LeetCode #ConsistencyCurve
To view or add a comment, sign in
-
-
Day 64 - Intersection of Two Linked Lists Solved by using a two-pointer technique to find the intersection node of two linked lists. Instead of calculating lengths, both pointers traverse both lists to align automatically. Time Complexity: O(n + m) Space Complexity: O(1) #Day64 #LeetCode #Java #LinkedList #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 78 – Next Greater Node in Linked List Solved a problem to find the next greater value for each node in a linked list by combining linked list traversal with a monotonic stack approach. Key Learnings: Converted a linked list into an array to enable index-based processing Applied the monotonic stack technique to efficiently find next greater elements #DSA #Java #LinkedList #Stack #ProblemSolving #CodingPractice
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