Day 48 of #50DaysOfLeetCodeChallenge Problem : Daily Temperatures 💡Approach: Used a monotonic stack to store indices of temperatures. For each day, I checked if the current temperature is higher than the one at the top of the stack. If yes, that means we’ve found a warmer day — so I popped the index and calculated the number of days waited. This gave an efficient O(n) solution instead of checking every pair. 🔥Key Takeaways: Learned how stacks can simplify problems involving “next greater element.” Improved understanding of monotonic structures and how they reduce unnecessary comparisons. Continuing my journey of learning, growing, and coding every day! #LeetCode #50DaysOfCode #Java #DataStructures #Stack #ProblemSolving #CodeToLearn #CharuCodes
Solved Daily Temperatures problem using monotonic stack in Java
More Relevant Posts
-
🚀 Day 54 of My #100DaysOfLeetCode Challenge 🚀 Today I worked on a problem related to making parentheses valid — a classic stack-based problem that tests your understanding of balanced brackets and edge cases. 💡 Problem: Given a string containing only '(' and ')', determine the minimum number of parentheses that must be added to make the string valid. 🧠 Concepts Used: Stack data structure String traversal Counting unmatched parentheses 🧩 Approach: Traverse through the string character by character. Use a stack to track unmatched '('. When encountering ')', pop from the stack if possible, else increment the counter. Finally, the total unmatched parentheses = stack size + counter. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #DSA #WomenInTech #TechLearning #CodeNewbie
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
✅Day 62 of #100DaysOfLeetCode 📌Problem: You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. 🟠 Difficulty: Medium 📍Topic: Array, Binary Search 🎯 Goal: Return the single element that appears only once in O(log n) time and O(1) space. 🧠key idea: Approach 1: The problem can be efficiently solved using a modified binary search. The core logic relies on the properties of the sorted array. If we are at an even index, its duplicate pair should be at the next (odd) index. If we are at an odd index, its pair should be at the previous (even) index. By examining the middle element and its neighbor, we can determine if the single, non-duplicated element lies in the left or right half of the array, allowing us to discard one half in each step and achieve a logarithmic time complexity. #100DaysOfCode #LeetCode #CodingChallenge #Java #DataStructures #Algorithms #BinarySearch #ProblemSolving #SoftwareDeveloper #TechJobs #DeveloperLife #CodeNewbie #Programming #LearnToCode #JobSeekers
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
🌳 Day 21 of #100DaysOfLeetCode – Unique Binary Search Trees 🌳 Today’s challenge was all about counting how many structurally unique BSTs can be formed using n distinct numbers. 🧮 This problem beautifully blends dynamic programming and combinatorial logic — where the number of unique trees for each n depends on the possible root positions and their left/right subtree combinations. ⚙️ 💡 Key takeaway: Dynamic programming helps in reusing subproblem results efficiently — making even complex recursive patterns simpler and faster! 🚀 #LeetCode #100DaysChallenge #BinarySearchTree #DynamicProgramming #ProblemSolving #CodingJourney #Java #DataStructures
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 5: Search Insert Position Day 5 of my #LeetCode50DaysChallenge ✅ Today’s problem was about finding the correct insertion index in a sorted array efficiently — Search Insert Position ✨ 🧩 Problem: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. The goal is to achieve a runtime complexity of O(log n). 💡 Approach: I implemented a binary search approach. The idea is to use two pointers (left and right) to narrow down the range. If the middle element is less than the target, move the left pointer up. Otherwise, move the right pointer down. Once the pointers converge, the left index represents the correct insertion position. This method ensures an efficient and clean solution, making use of binary search logic rather than linear iteration. ⏱️ Time Complexity: O(log n) 📊 Example: Input: nums = [1, 3, 5, 6], target = 2 Output: 1 “Small steps every day lead to big progress — keep showing up!” 💪 #LeetCode #CodingChallenge #Day5 #ProblemSolving #Java #SoftwareDevelopment #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 84 of #100DaysDSAChallenge 📌 Topic: Array — Squares of a Sorted Array ✅ Problem Solved on #LeetCode: 977. Squares of a Sorted Array (🟢 Easy) 💡 Key Learnings: • Strengthened understanding of the two-pointer technique for sorted array manipulation. • Learned to efficiently handle both negative and positive numbers when squaring values. • Optimized time complexity from O(n²) to O(n) by eliminating nested loops. • Enhanced focus on writing clean, readable, and efficient Java code. 🚀 Consistency Builds Clarity: Every problem you solve sharpens your logical thinking and builds confidence. Keep learning, improving, and moving forward — one problem at a time 💪 🏷️ #Day84 #100DaysChallenge #100DaysDSAChallenge #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #Arrays #Programming #LearningJourney #10kCoders #10000Coders #Consistency #LogicBuilding
To view or add a comment, sign in
-
-
Day 44 of #50DaysOfLeetCodeChallenge Problem: Add Two Numbers -Approach: Since the digits are stored in reverse, I started adding from the head nodes, just like manual addition from the least significant digit. Maintained a carry for sums ≥ 10. Traversed both lists simultaneously, creating new nodes for each sum digit. If a carry remained at the end, added it as a new node. -Key Takeaways: Linked lists can represent numbers in creative ways. Starting from the least significant digit simplifies addition. Carry handling is crucial for correctness. #LinkedInLearning #CodingJourney #Java #DataStructures #ProblemSolving #Algorithms #LeetCode #50Days
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