🚀 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
Java DSA FizzBuzz LeetCode Solution and Interview Insight
More Relevant Posts
-
🔥 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
To view or add a comment, sign in
-
-
🚀 Day 53: The Hybrid Challenge – Mastering Java’s Most Complex Inheritance Today was the final piece of the inheritance puzzle: Hybrid Inheritance. ☕ Hybrid inheritance is exactly what it sounds like—a "mix and match" of two or more inheritance types (like Single + Multiple or Hierarchical + Multilevel) within a single program. The Catch? Because Java doesn't support Multiple Inheritance with classes to avoid the Diamond Problem, achieving a hybrid structure requires a bit of strategic engineering. My Key Takeaways from Day 53: 🧱 1. The Strategy: Classes + Interfaces Since we can't extend multiple classes, we use Interfaces. ▫️ The Blueprint: A class can extend one parent class while simultaneously implementing multiple interfaces. ▫️ The Result: You get the shared logic of a class hierarchy PLUS the flexible behaviors of interfaces. 🌍 2. Real-World Example ▫️ Think of a "Smart Car": It Inherits from a Vehicle class (Single Inheritance for basic engine/wheels). It Implements a GPS interface and an Electric interface (Multiple Inheritance for specific features). Together, this creates a Hybrid structure that is modular and clean. ⚖️ 3. Why This Matters ▫️ Reusability: You don't have to rewrite the Vehicle logic for every new car type. ▫️ Flexibility: You can add or remove "behaviors" (interfaces) without breaking the core class hierarchy. ▫️ Safety: By using interfaces, we avoid the ambiguity and "fragile base class" issues found in languages like C++. Question for the Developers: In your current projects, do you lean more towards Deep Inheritance (many layers) or Flat Composition (using more interfaces)? I've heard there's a big shift toward the latter! 👇 #Java #OOP #Inheritance #100DaysOfCode #BackendDevelopment #SoftwareArchitecture #CleanCode #LearningInPublic 10000 Coders Meghana M
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
-
🚀 Mastering Java Through LeetCode 🧠 Day 22 of My DSA Journey Today I solved an interesting matrix-based problem that improved my understanding of arrays and comparison logic. 📌 LeetCode Problem Solved Today: 2352 – Equal Row and Column Pairs Problem Statement: Given an n x n matrix, find how many pairs (row, column) are exactly the same. A pair is valid only if both contain the same elements in the same order. 🧠 Key Idea: Compare each row with every column Check element-by-element equality Count all matching pairs 🔍 Example: Input: [[3,2,1], [1,7,6], [2,7,7]] Output: 1 Matching Pair: Row 2 = Column 1 → [2,7,7] ⚙️ Approach: Traverse all rows Build each column dynamically Compare row[i][k] with column[k][j] If all elements match → increment count ⏱️ Time Complexity: O(n³) (Optimized solution using HashMap possible in O(n²)) What I Learned: Matrix traversal techniques Row vs Column comparison logic Importance of nested loops in grid problems 🔥 Consistency is the key! Every day one problem closer to my goal of becoming a Software Engineer #LeetCode #DSA #Java #CodingJourney #100DaysOfCode #SoftwareEngineer #ProblemSolving #Learning #Tech
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode's Palindrome Number problem in Java — and all 11,511 test cases passed! ✅ Here's what I learned building a clean, string-based solution: 💡 The Approach: → Convert the integer to a string → Reverse it character by character → Compare the original vs reversed string Simple? Yes. But the real win is in the edge case — returning false immediately for negative numbers. That's clean defensive programming. 🧵 Key Takeaway: You don't always need complex math. Sometimes the most readable solution is the best solution — and readability is what makes code maintainable in production. ⚡ Runtime: 16ms | Memory: 46.62MB Not the fastest (beats 5.61%), but it's clear, correct, and gets the job done. I'm challenging myself to solve problems daily and document my thinking. Consistency > perfection. If you're on a similar DSA journey, let's connect! Drop your approach in the comments — I'd love to see how others tackled this. 👇 #LeetCode #Java #DSA #DataStructures #CodingChallenge #ProblemSolving #SoftwareDevelopment #100DaysOfCode #TechIndia
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
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 25 Today I solved another interesting problem that involves Stack + String manipulation, which is very important for interviews. 📌 LeetCode Problem Solved Today: Q.394 – Decode String 💡 Problem Statement: Given an encoded string, decode it using the rule: k[encoded_string] → repeat the string k times Example: "3[a2[c]]" → "accaccacc" Approach: I used a Stack-based approach to handle nested patterns efficiently: Use one stack for numbers (repeat count) Use another stack for strings Traverse the string character by character Key Logic: Handle multi-digit numbers using: k = k * 10 + digit Store previous state using stacks Build final string using StringBuilder Supports nested decoding like "3[a2[c]]" Time Complexity: O(n) Space Complexity: O(n) What I Learned: How to use stacks for nested structures Importance of handling multi-digit numbers Clean string building using StringBuilder #Java #DSA #LeetCode #CodingInterview #SoftwareEngineer #Stack #DataStructures #ProblemSolving #100DaysOfCode #Programming #Developers #TechCareers #CodingJourney #LearnToCode #JavaDeveloper #InterviewPreparation
To view or add a comment, sign in
-
-
🚀 Day 11 of Java with DSA Journey — This one blew my mind 🤯 📌 Problem: Power of Three (LeetCode 326) Yesterday, I used bit manipulation for Power of Two. Today? 👉 That approach completely fails. So I had to think differently… 💡 Breakthrough Idea Instead of loops or recursion… I used math + number theory to solve it in O(1) time. 👉 1162261467 % n == 0 Yes, one line. 🧠 Key Learnings 🔹 Bitwise isn’t universal Works great for base-2, but not for base-3 🔹 Prime Numbers Matter Since 3 is prime, its powers divide each other perfectly 🔹 Max Value Trick Largest power of 3 in 32-bit int = 3^19 = 1162261467 ⚡ Complexity ⏱ Time: O(1) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Know Your Data Type Limits Many O(1) tricks depend on constraints like 32-bit integer limits 💡 Tip 2: Prime Numbers Unlock Shortcuts If a number is prime, its powers have clean divisibility properties 💡 Tip 3: Always Question the Default Approach Most people write: while (n % 3 == 0) n /= 3; 💡 Tip 4: This is a Pattern Power of 2 → bitwise Power of 3 → math Power of 4 → hybrid 💡 Tip 5: Edge Cases First Always check n <= 0 🔥 Real Insight This problem forced me to shift my thinking: ❌ Rely on one technique ✅ Adapt based on the problem Consistency compounds 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #NumberTheory #InterviewPrep #Day11 #BitManipulation #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 52 of My DSA Journey Today, I solved Reverse Words in a String (LeetCode 151) 💻 This problem tested my understanding of string manipulation, trimming, and efficient traversal. 🔹 Problem Statement: Given a string s, reverse the order of words while removing extra spaces. 🔹 Key Learnings: ✅ Handling leading, trailing, and multiple spaces ✅ Using split() with regex (\\s+) ✅ Efficient use of StringBuilder for better performance ✅ Traversing array in reverse order 🔹 Approach: Trim the string to remove extra spaces Split words using regex Traverse from end to start Append words with single space 🔹 Example: Input: " hello world " Output: "world hello" Another Example: Input: "the sky is blue" Output: "blue is sky the" 🔹 Code Insight (Java): Used StringBuilder to efficiently build the reversed string without extra space issues. Consistency is the key 🔑 — showing up every day and improving step by step. #Day52 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Programming #PlacementPreparation 🚀 If you want, I can also create a more viral version (with hooks + storytelling) to get more reach 🔥Here’s a clean and engaging LinkedIn post for your Day 52 of DSA Journey with an example: 🚀 Day 52 of My DSA Journey Today, I solved Reverse Words in a String (LeetCode 151) 💻 This problem tested my understanding of string manipulation, trimming, and efficient traversal. 🔹 Problem Statement: Given a string s, reverse the order of words while removing extra spaces. 🔹 Key Learnings: ✅ Handling leading, trailing, and multiple spaces ✅ Using split() with regex (\\s+) ✅ Efficient use of StringBuilder for better performance ✅ Traversing array in reverse order 🔹 Approach: Trim the string to remove extra spaces Split words using regex Traverse from end to start Append words with single space 🔹 Example: Input: " hello world " Output: "world hello" Another Example: Input: "the sky is blue" Output: "blue is sky the" 🔹 Code Insight (Java): Used StringBuilder to efficiently build the reversed string without extra space issues. Consistency is the key 🔑 — showing up every day and improving step by step. #Day52 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Programming #PlacementPreparation 🚀
To view or add a comment, sign in
-
-
A student asked me today: If Java already has the Collection Framework, why do we need to implement a stack using ArrayList or LinkedList? And honestly, that’s where real learning begins. Yes, Java provides ready-made classes for stack-like behavior. But when we build a stack from scratch using ArrayList or LinkedList, we’re not just coding—we’re understanding *how things work under the hood*: * How memory is managed * Why operations like push/pop have certain time complexities * The trade-offs between different data structures Frameworks make us productive. Fundamentals make us powerful. Sometimes the goal isn’t to replace the Collection Framework—it’s to *understand it deeply enough that you could build it yourself if needed.* That curiosity is what separates someone who uses code from someone who truly understands it. #Java #DataStructures #Learning #Programming #ComputerScience #TeachingMoments #Continuouslearning
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