LeetCode — Problem 11 | Day 2 💡 Problem: Container With Most Water Given an array of heights, find two lines that together form a container which holds the maximum water. 🧠 My Approach: - Used two pointers (start & end) - Calculated area using "min(height) * width" - Moved the pointer with smaller height to maximize area - Repeated until pointers meet This problem gave a good understanding of: ✔️ Two Pointer Technique ✔️ Optimizing from brute force to O(n) ✔️ Logical thinking in arrays #LeetCode #DSA #Java #CodingJourney
Subham Mohanty’s Post
More Relevant Posts
-
Day 105 - LeetCode Journey Solved LeetCode 933: Number of Recent Calls ✅ Simple problem, but a great use of queue + sliding window concept. Idea: Store timestamps in a queue Remove all calls older than t - 3000 Remaining size = answer Key learnings: • Sliding window using queue • Maintaining only relevant data • Efficient real-time processing • Clean O(n) approach ✅ All test cases passed ⚡ O(1) amortized per operation Sometimes clean logic is all you need 💡 #LeetCode #DSA #Queue #SlidingWindow #Java #CodingJourney #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 14/50 💡 Approach: Sort + Two Pointers Brute force checks every triplet — that's O(n³)! Instead, I sorted the array first, then fixed one element and used Two Pointers to find the remaining pair in O(n). Result? O(n²) overall! 🔍 Key Insight: → Sort the array first to enable Two Pointer technique → Fix element at index i, use left & right pointers for the rest → sum < 0 → move left pointer right (need bigger value) → sum > 0 → move right pointer left (need smaller value) → sum = 0 → found a triplet! Skip duplicates carefully 📈 Complexity: ❌ Brute Force → O(n³) Time ✅ Sort + Two Pointer → O(n²) Time, O(1) Space The hardest part wasn't the logic — it was handling duplicates correctly. Details make the difference between a good solution and a great one! 🎯 #LeetCode #DSA #TwoPointers #Java #ADA #PBL2 #LeetCodeChallenge #Day14of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #3Sum
To view or add a comment, sign in
-
-
🚀 Solved an interesting problem today: “Minimum Stickers to Spell Word” At first, I tried a greedy approach… failed ❌ Then I realized this is actually a DP + memoization problem. 💡 Key Insight: Instead of trying all combinations blindly, we reduce the target string step by step. 🧠 Approach: - Convert each sticker into frequency map - Recursively try reducing target - Use memoization to avoid recomputation ⏱️ Time Complexity: Optimized significantly with caching 🔥 This problem improved my thinking about state reduction. #DSA #CodingInterview #Java #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 71/100 – LeetCode Challenge Solved: Remove Duplicates from Sorted List II (Medium) Today’s problem was a great test of Linked List manipulation and handling edge cases efficiently. 🔍 Key Insight: Since the list is sorted, duplicates appear consecutively. Instead of keeping one copy, the challenge is to remove all nodes with duplicate values, leaving only distinct elements. 💡 Approach: Used a dummy node to handle edge cases Applied two-pointer technique (prev & current) Skipped entire duplicate sequences in one pass ⚡ Result: Runtime: 0 ms (Beats 100%) Space Complexity: O(1) 🎯 Key Learning: Handling duplicates in linked lists requires careful pointer updates — especially when the head itself is part of duplicates. Consistency is key 🔥 #Day71 #LeetCode #100DaysOfCode #Java #DataStructures #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 114 - LeetCode Journey Solved LeetCode 572 – Subtree of Another Tree ✅ This problem focuses on determining whether one binary tree is a subtree of another. A subtree must match both in structure and node values, which makes it more than just a simple value comparison problem. Approach: I used a recursive strategy combining two key steps: Traverse each node of the main tree At every node, check if the subtree starting from that node is identical to the given subRoot For checking identical trees, I implemented a helper function that compares: • Node values • Left subtree • Right subtree If all match, we confirm the subtree exists. Otherwise, we continue searching in the left and right branches of the main tree. Complexity Analysis: • Time Complexity: O(n × m) in the worst case, where n is nodes in root and m is nodes in subRoot • Space Complexity: O(h), due to recursion stack Key Takeaways: • Tree problems often require combining traversal + comparison logic • Breaking problems into helper functions simplifies implementation • Understanding recursion flow is crucial for tree-based questions 🌳 All test cases passed successfully 🎯 #LeetCode #DSA #BinaryTree #Recursion #Java #CodingJourney #ProblemSolving
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
-
-
LeetCode — Problem 189 | Day 3 💡 Problem: Rotate Array Given an array, rotate it to the right by k steps. 🧠 My Approach: - Used reverse technique for in-place rotation - First reversed the entire array - Then reversed first k elements - Finally reversed remaining elements - Handled k using k = k % n This problem gave a good understanding of: ✔️ Array manipulation ✔️ In-place optimization (O(1) space) ✔️ Reverse logic #LeetCode #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
Day 86 – Sorted List to Height-Balanced BST Today’s problem was about converting a sorted linked list into a height-balanced Binary Search Tree (BST). 💡 Key Idea: Use the slow & fast pointer technique to find the middle element of the linked list. The middle element becomes the root Left half → left subtree Right half → right subtree 🔁 Apply this recursively to build a balanced BST. 🧠 What I learned: How to simulate array-like access in a linked list Importance of finding the middle efficiently Recursion for tree construction 💻 Time Complexity: O(n log n) 💾 Space Complexity: O(log n) (recursive stack) #Day86 #DSA #Java #CodingJourney #LeetCode #BinaryTree #LinkedList
To view or add a comment, sign in
-
-
Day 56 : Crushing Binary Trees on LeetCode 💡 Today’s live practical session in Alpha Plus 7.0 We focused on some of the most challenging Binary Tree questions on LeetCode, breaking down the logic behind them. What I practiced today: ✅ Tree Diameter: understand the logic to calculate the absolute longest path between any two nodes in the entire tree. ✅ Maximum Path Sum: Tackled a famous "Hard" level problem! Figured out how to find the path with the highest possible sum, even if it doesn't pass through the root. ✅ Target Deletion: Wrote the recursive code to systematically find and delete leaf nodes that match a specific target value. #BinaryTree #LeetCode #ProblemSolving #DSA #Java #SoftwareEngineering #100DaysOfCode #ApnaCollege
To view or add a comment, sign in
-
-
Today I solved LeetCode 110 – Balanced Binary Tree. 🧩 Problem Summary: Given the root of a binary tree, determine if it is height-balanced. A binary tree is balanced if: The height difference between the left and right subtree of every node is not more than 1. 💡 Key Concepts Used: Binary Trees Recursion Depth First Search (DFS) Height calculation 🧠 Approach: Use DFS to calculate the height of each subtree. For every node: Get height of left subtree Get height of right subtree Check if the absolute difference is greater than 1: If yes → tree is not balanced Optimize by returning -1 early when imbalance is found to avoid unnecessary calculations. ⏱ Time Complexity: O(N) — Each node is visited once. 📚 What I Learned: Combining height calculation with validation in one traversal. Optimizing recursive solutions with early stopping. Understanding balanced vs unbalanced trees. Strengthening DFS and recursion skills. Improving step by step with tree problems Consistency is building confidence every day #LeetCode #DSA #BinaryTree #BalancedTree #DFS #Recursion #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
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