Day 97/200 – LeetCode Challenge Solved “Largest Rectangle in Histogram” (Hard) today. This problem is a great example of how powerful the Monotonic Stack technique can be. Instead of brute force, we efficiently determine how far each bar can extend to compute the maximum rectangle area. Using a monotonic increasing stack to track indices. Identifying left and right boundaries for each bar. Every day is making data structures feel more intuitive! #Day96 #LeetCode #Java #CodingJourney #ProblemSolving
Solved Largest Rectangle in Histogram with Monotonic Stack
More Relevant Posts
-
I just solved LeetCode 662: Maximum Width of Binary Tree! Finding the width is different from a normal traversal because you have to account for the empty spaces between nodes. I used a simple indexing trick ($2i+1$ and $2i+2$) and an ArrayDeque to track positions. By using peekFirst() and peekLast(), I could instantly calculate the width of each level ($right - left + 1$). It’s a great example of how choosing the right data structure makes the logic much cleaner! #LeetCode #Java #BinaryTree #Coding
To view or add a comment, sign in
-
Day 103: Simple & Clean 🎯 Problem 1848: Minimum Distance to the Target Element After some complex DP challenges, today was a straightforward exercise in linear search and distance calculation. The Strategy: • Linear Traversal: I iterated through the array to find every occurrence of the target element. • Absolute Minimization: For each match, I calculated the absolute difference between the current index and the start index, keeping track of the minimum value found. Sometimes a simple, O(N) solution is all you need. Day 103 down—maintaining the streak with clarity and consistency. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
Day 35 of Consistency 💻🔥 Solved Longest Substring Without Repeating Characters — a classic sliding window problem that really tests optimization skills. ✨ Key Takeaways: Mastered the sliding window technique Used HashMap for efficient lookup Improved understanding of two-pointer approach ⚡ Performance: Runtime: 5 ms Beat: 87%+ submissions Every day is about getting sharper, not just solving problems. #LeetCode #DataStructures #Algorithms #CodingJourney #Consistency #Java #ProblemSolving
To view or add a comment, sign in
-
-
💡 Day 61 of LeetCode Problem Solved! 🔧 🌟 482. Find Maximum Consecutive Ones 🌟 🔗 Solution Code: https://lnkd.in/gf5DPq4E 🧠 Approach: • Traverse the binary array once using one pointer. • Keep counting consecutive 1s and update the maximum value at each step. • When a 0 appears, reset the count to 0. ⚡ Key Learning: • This is a simple sliding window idea. No need for nested loops or extra memory. Tracking current count and maximum value is a useful pattern for many array problems. ⏱️ Complexity: • Time: O(N) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Arrays
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
-
-
✨ Day 42 of 90 – Pattern Mastery Journey 🧠 Pattern : Alphabet Hash Pattern 💡 Approach: ✔ Created an n × n matrix using nested loops ✔ Printed alphabets only when row index equals column index (i == j) ✔ Filled all other positions with `#` ✔ Used ASCII logic `(char)('A' + i - 1)` to generate characters 🚀 This problem helped me understand how **diagonal conditions work in matrices** and how simple conditions can create clean structured patterns. #PatternMasteryJourney #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 20/100: The "Cheat Code" for String Rotations 🔄 I’m back on the grind! Today’s challenge was checking if one string is a rotation of another (e.g., "waterbottle" and "erbottlewat"). The Strategy: Instead of writing complex loops to shift characters, I used the Concatenation Trick: 1️⃣ Check if lengths are equal. 2️⃣ Create a new string by adding the first string to itself (s1 + s1). 3️⃣ Check if the second string exists inside that combined string. It’s a simple, elegant O(n) solution that shows how sometimes "working smarter" with data structures beats "working harder" with loops. 20% of the way there. Let's keep moving! 🚀 #100DaysOfCode #Java #DSA #Strings #ProblemSolving #Unit2 #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 75 of #100DaysOfCode Solved 103. Binary Tree Zigzag Level Order Traversal on LeetCode 🔗 🧠 Key Insight: This is a variation of level order traversal where: 👉 Levels alternate between left → right and right → left ⚙️ Approach (BFS + Direction Toggle): 1️⃣ Use a queue for level order traversal 2️⃣ Maintain a flag (leftToRight or sign) 🔹 true → left → right 🔹 false → right → left 3️⃣ For each level: 🔹 Create a list 🔹 Traverse all nodes in that level 4️⃣ Insert values based on direction: 🔹 If left → right → addLast(val) 🔹 Else → addFirst(val) 5️⃣ Add level list to result 6️⃣ Flip direction: 👉 sign *= -1 or toggle boolean ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #100DaysOfCode #LeetCode #DSA #BinaryTree #BFS #Queue #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 59/75 — Merge Sorted Array Today’s problem was about merging two sorted arrays into one sorted array in-place. Approach: • Start from the end to avoid overwriting elements • Use three pointers: i (nums1), j (nums2), k (merged position) • Place the larger element at the end and move backwards Key logic: while (i >= 0 && j >= 0) { if (nums1[i] > nums2[j]) { nums1[k--] = nums1[i--]; } else { nums1[k--] = nums2[j--]; } } while (j >= 0) { nums1[k--] = nums2[j--]; } Time Complexity: O(m + n) Space Complexity: O(1) A simple yet important problem that reinforces two-pointer technique. 59/75 🚀 #Day59 #DSA #TwoPointers #Arrays #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 72/100 Completed ✅ 🚀 Solved LeetCode – Matrix Diagonal Sum (Java) ⚡ Implemented an efficient approach to calculate the sum of both primary and secondary diagonals of a square matrix in a single traversal. Avoided double-counting the center element by handling the odd-sized matrix case separately. 🧠 Key Learnings: • Efficient diagonal traversal in a matrix • Handling overlapping elements (center in odd n) • Writing optimal O(n) solutions instead of nested loops • Clean and concise index-based logic 💯 This problem improved my understanding of matrix patterns and how to optimize traversal by reducing unnecessary iterations. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #arrays #problemSolving #100DaysOfCode 🚀
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