🚀 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
Solved LeetCode problem: Valid Parentheses with Stack
More Relevant Posts
-
🌳 Day 62 of 100 Days of LeetCode 🌳 Today’s challenge: LeetCode 226 – Invert Binary Tree 🔄 🧩 Problem Summary: Given the root of a binary tree, invert it — meaning swap the left and right children of every node. Essentially, you’re mirroring the entire tree! 🌲✨ 💡 Key Takeaways: 🔹 Strengthened understanding of tree traversal using recursion. 🔹 Learned how a simple DFS (Depth-First Search) can elegantly solve structural transformations. 🔹 Practiced reasoning about symmetry and recursion base cases. 🧠 Approach: 1️⃣ If the tree is empty, return null. 2️⃣ Recursively invert the left and right subtrees. 3️⃣ Swap the left and right children of the current node. 4️⃣ Return the root once the tree is fully inverted. 🚀 A great example of how recursion simplifies complex problems into smaller, intuitive steps! #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #CodingJourney #Recursion #ProblemSolving
To view or add a comment, sign in
-
-
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
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
-
-
💡 LeetCode #58 — Length of Last Word Today I solved LeetCode Problem 58: Length of Last Word 🧠 Problem Summary: Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a sequence of non-space characters. Key Idea: We can traverse the string from end to start — Skip trailing spaces. Count the number of characters until the next space (which marks the last word). This avoids unnecessary splitting and saves extra space. #LeetCode #Java #DSA #Strings #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🌟 Problem 21 – Merge Two Sorted Lists I solved this problem today on LeetCode 💪. It helped me understand how to work with linked lists and how to merge them efficiently. 🧩 Description: Given two sorted linked lists, merge them into one sorted list and return its head. 👉 Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] ✅ Approach: * Compare nodes from both lists one by one. * Add the smaller value to the new list. * Continue until all elements are merged. 📈 Time Complexity: O(n + m) 📦 Space Complexity: O(1) #LeetCode #TopInterview150 #Java #DSA #Coding #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
🧩 Day 78 of #100DaysOfCode Challenge 🧩 📘 LeetCode 56 — Merge Intervals Topic: Arrays & Sorting Today’s problem was about merging overlapping intervals — a real test of logical thinking and array manipulation skills! 💡 Problem Summary: Given multiple intervals, the goal is to merge all overlapping ones and return a list of non-overlapping intervals that cover all ranges in the input. ⚙️ Approach (Brute + Optimized): 1️⃣ Sort all intervals based on their start value. 2️⃣ Compare the current interval with the previous one: If they overlap, merge them by updating the end time. If not, add the previous interval to the result. 3️⃣ Continue until all intervals are processed. 🧠 Key Learning: Sorting simplifies overlapping detection. Interval-based problems help strengthen array and logic handling. Real-world application: scheduling problems and timeline merging! ✨ Each problem is another step toward mastering patterns in DSA. #Day78 #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #WomenInTech #CodingJourney #Arrays #Sorting
To view or add a comment, sign in
-
-
Day-90 of #100DaysOfCodeChallenge 🚀 ✨ Daily LeetCode Challenge – Problem 2536: Increment Submatrices by One Today’s problem was a great exercise in optimizing 2D range updates using a difference matrix + prefix sums approach. Instead of updating each cell inside every query (which is too slow for large constraints), I used an efficient technique that reduces the complexity from O(q·n²) to O(n² + q) — and it worked! 🚀 Happy to see the solution get accepted with solid performance. 💡 🧩 Key Takeaway: Mastering prefix-sum tricks (1D & 2D) can massively improve performance on problems involving repeated range updates on LeetCode. 📈 Results: ✔ Accepted ✔ 9ms runtime ✔ Optimized solution ✔ Beats ~90% submissions On to the next challenge! 💪 #LeetCode #DailyChallenge #Java #ProblemSolving #DSA #CodingJourney #WomenInTech #LearningEveryday
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 3: Remove Duplicates from Sorted Array Day 3 of my #LeetCode50DaysChallenge ✅ Today’s problem was about array manipulation — Remove Duplicates from Sorted Array ✨ 🧩 Problem: Given an integer array nums sorted in non-decreasing order, remove duplicates in-place such that each unique element appears only once. The relative order of the elements should remain the same. 💡 Approach: This problem is a classic two-pointer approach! One pointer i keeps track of the last unique element’s position. The other pointer j iterates through the array. Whenever a new element is found (nums[i] != nums[j]), we move it forward by incrementing i and assigning nums[i] = nums[j]. In the end, i + 1 gives the count of unique elements. A simple yet elegant technique to modify arrays in-place! ⏱️ Time Complexity: O(n) 📊 Example: Input: [0,0,1,1,1,2,2,3,3,4] Output: [0,1,2,3,4] Consistency is the secret ingredient to progress! 🌱 Each problem solved adds another brick to the wall of mastery 💪 #LeetCode #CodingChallenge #Day3 #ProblemSolving #Java #SoftwareDevelopment #Consistency #100DaysOfCode
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
-
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