🔥 Day 3 of my 50 Days Wild Coding Kickoff! 🔥 💡 Problem 3: Valid Parentheses (Easy) Given a string containing just '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if: ✔ Open brackets are closed by the same type ✔ Open brackets are closed in the correct order Example 1: Input: s = "[]" Output: true Example 3: Input: s = "[(])" Output: false 🚀 Approach (Optimized without Stack class): Instead of using Java’s built-in Stack, I used a char array to simulate a stack for better performance. Created a char[] as stack Used top pointer to track elements Push opening brackets On closing bracket → pop and compare If mismatch or stack empty → invalid #100DaysOfCode #50DaysOfCode #CodingChallenge #JavaDeveloper #DataStructures #Stack #Algorithms #DSA #CodingJourney #InterviewPrep #LeetCode #ProblemSolving #DeveloperLife #CodingDaily #CodePractice
Valid Parentheses Problem Solution in Java
More Relevant Posts
-
🚀 Day 8 of Java with DSA Journey 🚀 📌 Topic: FizzBuzz (LeetCode 412) 💬 "Clean code is not written by following rules, but by following logic." ✨ What I learned today: 🔹 Condition Priority Matters Checking FizzBuzz (divisible by both 3 & 5) first is crucial. Order defines correctness. 🔹 String Handling Used Integer.toString(i) for clean output formatting. 🔹 Code Readability Even simple problems test how clearly you structure your logic. 🔹 Complexity Awareness ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) 🧠 Problem Solved: ✔️ FizzBuzz 🎨 Visualizing the Logic (Decision Tree) Each number flows through conditions like a filter. It stops at the first true condition, which makes ordering critical. 💡 Key Insight: FizzBuzz may look simple, but it teaches precise logical structuring and modular arithmetic (%). 👉 The “15 Test”: If we check i % 3 == 0 first, 15 becomes "Fizz" and skips "Buzz". By checking (i % 3 == 0 && i % 5 == 0) first, we correctly get "FizzBuzz". ⚡ Interview Insight (Scalability Twist): What if we add a new condition like 7 → "Bazz"? Instead of messy if-else, use string concatenation: String currentStr = ""; if (i % 3 == 0) currentStr += "Fizz"; if (i % 5 == 0) currentStr += "Buzz"; if (currentStr.isEmpty()) currentStr += i; answer.add(currentStr); ✅ Easier to extend ✅ Cleaner logic ✅ More maintainable 🔑 Takeaway: Consistency beats complexity. Showing up daily builds real problem-solving skills. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Day8 #CleanCode #SoftwareEngineering #FizzBuzz #Array #InterviewPrep #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 3 of My Coding Challenge Improving my problem-solving skills step by step! Today I solved a number-based problem on reversing an integer. 🔹 Platforms: LeetCode & GeeksforGeeks 🔹 Problem: LeetCode #7 – Reverse Integer 🔹 Problem Statement: Given a signed 32-bit integer, reverse its digits. If the reversed integer overflows, return 0. 🔹 Approach: 1️⃣ Extract last digit using modulo (%) 2️⃣ Build reversed number step by step 3️⃣ Check for overflow before updating result 🔹 Example: Input: 123 → Output: 321 Input: -123 → Output: -321 Input: 120 → Output: 21 🔹 What I learned: ✔ Handling integer overflow conditions ✔ Working with digits using modulo & division ✔ Writing safe and optimized code 💻 Code: import java.util.*; public class ReverseIntegerLeetCode7 { ``` public static int reverse(int x) { int rev = 0; while (x != 0) { int rem = x % 10; x = x / 10; // Check overflow if (rev > Integer.MAX_VALUE / 10 || (rev == Integer.MAX_VALUE / 10 && rem > 7)) { return 0; } if (rev < Integer.MIN_VALUE / 10 || (rev == Integer.MIN_VALUE / 10 && rem < -8)) { return 0; } rev = (rev * 10) + rem; } return rev; } public static void main(String[] args) { int x = 123; System.out.println(reverse(x)); x = -123; System.out.println(reverse(x)); x = 120; System.out.println(reverse(x)); } ``` } 🔗 GitHub: https://lnkd.in/g-wNSrPq #Java #DSA #LeetCode #CodingChallenge #50DaysChallenge #Consistency #GrowthMindset #LearningJourney
To view or add a comment, sign in
-
🚀 Just solved LeetCode Problem #7 – Reverse Integer At first, it looked like a simple problem: reverse the digits of a number. But while solving it, I realized it’s not about reversing… it’s about thinking deeper. Here’s what I actually learned 👇 🔹 1. Think before things break Instead of checking overflow after it happens, I learned to prevent it before it happens using conditions like: → checking limits before multiplying by 10 🔹 2. Edge cases are everything The logic was easy. Handling edge cases like: very large numbers negative values integer limits …was the real challenge. 🔹 3. Don’t trust the compiler blindly Languages like Java won’t throw an error on overflow — they silently give wrong values. That was a big realization. 🔹 4. Patterns matter The simple step: → ans = ans * 10 + digit is a powerful pattern used in many problems. 🔹 5. Clean logic > shortcuts Using long was easy, but solving it properly with constraints made me understand the problem deeply. 💡 Biggest takeaway: Writing code that works is good. Writing code that is safe and correct in all cases is what really matters. On to the next problem 💪 #LeetCode #DSA #DataStructures #Algorithms #CodingJourney #LearnToCode #Programming #Java #SoftwareEngineering #ProblemSolving #CodingPractice #TechSkills #Developers #100DaysOfCode #CodeNewbie #InterviewPrep #CodingLife #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Day 2 of My Coding Challenge Improving my problem-solving skills step by step! Today I solved an important array problem from LeetCode. 🔹 Platforms: LeetCode & GeeksforGeeks 🔹 Problem: LeetCode #189 – Rotate Array 🔹 Problem Statement: Rotate the array to the right by k steps. 🔹 Approach: I used the Reversal Algorithm for an optimized solution: 1️⃣ Reverse the entire array 2️⃣ Reverse first k elements 3️⃣ Reverse remaining elements 🔹 Example: Input: [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] 🔹 What I learned: ✔ Optimized approach from brute force to O(n) ✔ Importance of array manipulation techniques ✔ Handling edge cases like k > n 💻 Code: import java.util.Arrays; public class RotateArrayLeetCode189 { ``` public static void reverse(int[] arr, int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } public static void rotate(int[] arr, int k) { int n = arr.length; k = k % n; if (k < 0) { k = k + n; } // Step 1: Reverse entire array reverse(arr, 0, n - 1); // Step 2: Reverse first k elements reverse(arr, 0, k - 1); // Step 3: Reverse remaining elements reverse(arr, k, n - 1); } public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5, 6, 7}; int k = 3; rotate(arr, k); System.out.println(Arrays.toString(arr)); } ``` } 🔗 GitHub: https://lnkd.in/g-wNSrPq #Java #DSA #LeetCode #CodingChallenge #50DaysOfCode #LearningJourney #PlacementPreparation
To view or add a comment, sign in
-
what happens if both try and finally have a return statement?” Sounds simple, right? But this is where many developers get confused. When I first learned this, I thought — 👉 whichever return comes first will be executed. But Java doesn’t work that way. In Java, the finally block always executes, even if a return statement has already been encountered in the try block. And here’s the twist — if finally also contains a return statement, 👉 it completely overrides the return from try. So you might expect the output to be 10… but the actual result will be 20. A small concept, but a big difference in understanding. Also, an important lesson: ❌ Never use return statements inside a finally block It makes your code confusing, hard to debug, and leads to unexpected behavior. The purpose of finally is cleanup — not control flow. Because in programming, it’s not just about writing code… it’s about understanding how it actually works. 🚀 #Java #Programming #SoftwareDevelopment #CodingInterview #Developers #Tech #Learning #CleanCode #JavaConcepts
To view or add a comment, sign in
-
Most developers are not slowed down by bad code. They are slowed down by bad thinking. Not syntax. Not framework choice. Not whether the project uses Java, Go, or Python. The real damage usually comes earlier: - no clear boundaries - too many dependencies in one request path - retries added without thinking - APIs designed around convenience instead of failure - teams optimizing for feature speed over system clarity That’s why some codebases feel heavy even before they get big. The problem is not always technical debt. Sometimes it’s decision debt. And that is much harder to fix. Debate: What does more long-term damage to software teams? A) bad code B) bad architecture C) bad product decisions D) bad debugging habits My vote: B first, C second. What’s yours? #Java #SoftwareArchitecture #Microservices #DistributedSystems #BackendEngineering
To view or add a comment, sign in
-
Most people think coding is about writing logic. But it's something deeper… It’s about thinking clearly when things don’t work. I spent hours debugging a small issue, not because it was hard, but because my thinking was messy. The moment I slowed down, broke the problem and questioned every assumption… The solution appeared in minutes💡 Good developers don’t just code fast. They think better. And that’s what I’m working on every single day. #SoftwareDevelopment #CodingJourney #ProblemSolving #Java #Learning
To view or add a comment, sign in
-
Day 14 of my coding journey — Extracting Unique Words using Java Streams Today I explored a clean and efficient way to extract unique words from a string using Java Streams. Instead of writing multiple loops and conditional checks, I leveraged the power of functional programming: Grouped words using a frequency map Filtered out words that appear more than once Collected only truly unique words in a concise pipeline What I really liked about this approach is how readable and expressive the code becomes. It clearly shows what we want to achieve rather than how step-by-step. Key takeaway: Writing optimized code is not just about performance — it’s also about clarity, maintainability, and using the right abstractions. Every day I’m getting more comfortable thinking in terms of streams, transformations, and data flow. If you have alternative approaches or optimizations, I’d love to hear them. #Day14 #Java #CodingJourney #JavaStreams #BackendDevelopment #ProblemSolving #CleanCode
To view or add a comment, sign in
-
-
Topic: Importance of Naming in Code Good naming is one of the simplest ways to improve code quality. Poor naming leads to: • Confusion • Misunderstanding of logic • Slower development • Harder maintenance Good naming should be: • Clear and descriptive • Consistent across the codebase • Reflective of intent Examples: Bad: data, temp, x Good: userAccountBalance, paymentStatus, orderList Naming is not just a small detail. It directly impacts how easily others understand your code. Because code is read more often than it is written. What naming conventions do you follow in your projects? #CleanCode #SoftwareEngineering #Java #BackendDevelopment #Coding
To view or add a comment, sign in
-
🚀 Solved LeetCode Problem #58 – Length of Last Word Today I worked on a simple yet insightful string manipulation problem that emphasizes attention to edge cases. 🔍 Problem Insight: Given a string containing words and spaces, the goal is to find the length of the last word, ignoring any trailing spaces. 💡 Approach Used: Instead of using built-in methods like split(), I implemented an optimized approach by: Traversing the string from the end Skipping trailing spaces Counting characters until the next space is encountered This approach avoids extra space usage and improves efficiency. 🧠 Key Learning: Importance of handling edge cases like trailing spaces How reverse traversal can simplify string problems Writing memory-efficient solutions 📈 Complexity: Time: O(n) Space: O(1) ✨ Problems like this help strengthen: String manipulation skills Logical thinking Writing clean and optimized code Consistency is key—one step closer to mastering DSA! 💪 #LeetCode #DSA #StringManipulation #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
Explore related topics
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