🚀 LeetCode Problem Solved: Valid Parentheses ✅ I recently tackled the Valid Parentheses problem on LeetCode, which challenges you to check if a string containing (, ), {, }, [ and ] is valid. Key takeaways from this challenge: Using a stack-like approach to track opening brackets. Making sure every closing bracket matches the most recent unmatched opening bracket. Handling edge cases like unmatched or mis ordered brackets efficiently. The approach is simple yet effective: push opening brackets, and for every closing bracket, check against the last unmatched one. If it doesn’t match, the string is invalid. At the end, the string is valid only if all brackets are matched. A great way to sharpen problem-solving and logical thinking skills. 10000 Coders Usha Sri #LeetCode #CodingChallenge #Java #ProblemSolving #Stack
Solved LeetCode's Valid Parentheses problem using a stack
More Relevant Posts
-
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
-
-
🚀 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
-
-
Matrix Rotation (Inspired by LeetCode Problem 48 - Rotate Image) Recently, I worked on a mini project based on the LeetCode problem “Rotate Image”, which involves rotating a matrix representation of an image. Through this project, I explored how pixels and matrices interact while implementing the logic behind image rotation. I developed the project using Java Swing for the user interface, which helped me visualize the matrix rotation process and make the learning more interactive. Even though it’s a core array concept, this experience gave me a clear understanding of how DSA principles can be applied efficiently in real-world software projects — especially in optimizing logic and performance. I’m still learning and experimenting with more DSA concepts, building mini projects to practically apply them and understand how they fit into the software development life cycle (SDLC). #DSA #Java #JavaSwing #LeetCode #LearningJourney #ProblemSolving #SoftwareDevelopment #MatrixRotation
To view or add a comment, sign in
-
🚀 Day 59 – LeetCode Challenge Problem: Third Maximum Number (#414) Today’s problem was about finding the third distinct maximum number in an array. It looked simple at first, but the challenge was to handle duplicates carefully while ensuring an efficient solution. 💡 Approach Used: 🔹 Step 1: Sort the array in ascending order. 🔹 Step 2: Start from the end (largest number) and keep track of distinct elements. 🔹 Step 3: Use a counter to count how many unique numbers have been found. 🔹 Step 4: Once the third distinct number is reached, return it. 🔹 Step 5: If the array has fewer than 3 distinct numbers, return the largest one instead. ⏱ Time Complexity: O(n log n) 💾 Space Complexity: O(1) 🧠 Key Takeaway This problem reinforced how careful handling of duplicates can make or break a solution. Even simple array tasks can teach valuable lessons about edge cases and clean logic. #LeetCode #Day59 #Java #DSA #100DaysOfCode #CodingChallenge #ProblemSolving #LearningEveryday #CodeNewbie #Array
To view or add a comment, sign in
-
-
✨ Day 5 of my LeetCode streak! Today I solved another interesting problem that taught me a cool bit manipulation trick 😎 💡 Problem: Smallest Number With All Set Bits Greater Than or Equal to N 📘 Statement: You are given a positive number n. Return the smallest number x greater than or equal to n, such that the binary representation of x contains only set bits (all 1s). Example: Input: n = 5 Output: 7 Explanation: Binary of 7 → 111 🧠 My Thought Process: At first, I noticed that numbers like 1 (1), 3 (11), 7 (111), 15 (1111) all have binary 1s only. So, the idea was simple 👇 Keep generating numbers like these (111...) until it becomes greater than or equal to n. To do that efficiently, I used bit manipulation: Start from mask = 1 Keep doing mask = (mask << 1) | 1 Stop when mask >= n The trick (mask << 1) | 1 means: Shift bits left (multiply by 2) Add one 1 at the end of the binary number 💻 Code (Java): class Solution { public int smallestNumber(int n) { int mask = 1; while (mask < n) { mask = (mask << 1) | 1; // shift left, add 1 at the end } return mask; } } 🧩 Example Dry Run: For n = 10: mask = 1 → 3 → 7 → 15 As soon as mask becomes 15 (>=10), that’s our answer ✅ Binary of 15 → 1111 🔍 Key Takeaways: Learnt how bit manipulation can make problems simpler and faster ⚡ Understood how left shift (<<) and bitwise OR (|) can be combined to create binary patterns Another cool use of binary logic to solve what looks like a simple math problem! 🗓️ LeetCode Streak: Day 5 / Consistency > Perfection 🔥 Every day I’m learning something new — one problem at a time. #LeetCode #100DaysOfCode #Java #BitManipulation #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 40 of My #LeetCode Challenge 🚀 📘 Problem: Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold (LeetCode #1343) 💡 Approach: Implemented the Sliding Window technique to efficiently calculate the sum of each subarray of size k. First, compute the sum of the initial k elements. Then, slide the window forward — subtract the element leaving and add the new one entering. Check if the average of the current window meets or exceeds the given threshold. This method optimizes the time complexity to O(n) by avoiding repetitive summation. ⏱️ Concepts Used: Sliding Window | Arrays | Optimization | Time Complexity 🔥 Consistency and logic go hand in hand — every day adds a new layer to my problem-solving skills! #Day40 #LeetCode #100DaysOfCode #CodingChallenge #Java #DSA #ProblemSolving #CodingJourney #TechLearning #CodeEveryday #SoftwareEngineering #ProgrammerLife #CodingCommunity #Developer #JavaProgramming #LearnToCode #TechGoals #CodeNewbie #Algorithm #DataStructures #CodingPractice
To view or add a comment, sign in
-
-
🌳 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 7 of My Coding Practice Journey 🚀 Today I solved a problem to find the second largest element in an array using Java. This helped me strengthen my logic-building and understand how to efficiently handle array comparisons without sorting. Here’s my code snippet: 👇 class Solution { static public int getSecondLargest(int[] arr) { int l = -1, s = -1; for (int k : arr) { if (k > l) { s = l; l = k; } else if (s < k && k != l) { s = k; } } return s; } public static void main(String[] args) { getSecondLargest(new int[]{1, 3, 4, 2, 7, 5}); } }
To view or add a comment, sign in
-
🚀 Day 68 of #100DaysOfChallenge Today's problem: 3461. Check If Digits Are Equal in String After Operations I (LeetCode - Easy) This problem was a fun blend of pattern observation and modular arithmetic — a great reminder that even simple-looking questions can strengthen your logical flow and coding discipline on LeetCode. 🧩 Problem Overview: We’re given a string of digits, and in each step, we repeatedly calculate the sum of every pair of consecutive digits modulo 10, until only two digits remain. Finally, we check whether those two digits are equal. 💡 My Approach: Used a straightforward simulation approach — repeatedly computing new strings of digits using modular arithmetic until only two digits were left. It’s simple, direct, and performs efficiently for short strings. ⚙️ Language: Java ⚡ Runtime: 8 ms (Beats 72.03%) 💾 Memory: 44.67 MB (Beats 69.77%) ✅ Result: Accepted — 706 / 706 test cases passed Every daily problem adds another layer of precision and confidence. Consistency isn’t just about coding every day — it’s about learning something new with every attempt. 🌱 On to the next challenge 💪 #100DaysOfCode #LeetCode #ProblemSolving #Java #CodingChallenge #Programming #DeveloperJourney #LearningEveryday #TechMindset #Consistency
To view or add a comment, sign in
-
-
🚀 Day 47 of My LeetCode Journey 🚀 Problem: Sum of Square Numbers Topic: Math / Two Pointers 🧠 Approach: To check if a number c can be expressed as the sum of squares of two integers (a² + b² = c), we use the two-pointer technique: Start a = 0 and b = √c Calculate sum = a² + b² If sum == c → ✅ return true If sum < c → increase a If sum > c → decrease b Repeat until a <= b. ⏱️ Complexity: Time: O(√c) Space: O(1) This problem beautifully combines mathematical logic with an efficient two-pointer approach — clean and elegant! 💡 #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #DSA
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