Day 46 - LeetCode Journey Solved LeetCode 412: Fizz Buzz in Java ✅ A classic problem, but a great reminder that even simple logic needs clarity and clean implementation. The task was to print numbers from 1 to n, but with a twist based on divisibility rules. If a number is divisible by both 3 and 5, we print "FizzBuzz". If only divisible by 3, print "Fizz". If only divisible by 5, print "Buzz". Otherwise, print the number itself. The key here was handling conditions in the correct order. Checking for 15 first avoids missing the "FizzBuzz" case. Key takeaways: • Importance of condition ordering • Writing clean and readable logic • Handling edge cases properly • Strong basics matter in interviews ✅ All test cases passed ✅ Clean and efficient implementation Simple problems like this help build a strong base. Mastering basics is what makes complex problems easier later 💪 #LeetCode #DSA #Java #ProgrammingBasics #Algorithms #ProblemSolving #CodingJourney #InterviewPreparation #Consistency
LeetCode 412: Fizz Buzz in Java - Condition Ordering and Clean Logic
More Relevant Posts
-
Day 48 - LeetCode Journey Solved LeetCode 1108: Defanging an IP Address in Java ✅ A super clean and beginner-friendly string problem that focuses on simple transformation. Problem idea: Replace every "." in the IP address with "[.]" to create a defanged version. Approach: Used built-in replace() method to directly modify the string. No loops, no extra logic — just one line solution. Key takeaways: • Understanding string manipulation basics • Knowing when to use built-in functions for efficiency • Writing clean and concise code • Avoiding overcomplication Time Complexity: O(n) Space Complexity: O(n) ✅ All test cases passed ✅ Optimal and readable solution Sometimes the simplest problems teach the most — clarity in coding matters 🚀 #LeetCode #DSA #Java #Strings #ProblemSolving #CodingJourney #Programming #InterviewPrep #Consistency
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🧩 Problem: 1784 – Check if Binary String Has at Most One Segment of Ones Today’s problem looked confusing at first. Honestly, the problem description wasn’t very intuitive, and I had to read it a couple of times to understand what it was actually asking. 💡 What the question really means: We’re given a binary string without leading zeros, and we need to check if all the 1s appear in only one continuous block. Valid examples: 111 110 1000 Invalid example: 1001 → because the 1s appear in two separate segments So the key idea is simple: If the string ever contains the pattern "01", it means we finished a block of 1s and then encountered another 1 later — which creates multiple segments. ⚡ Approach Just check if "01" exists in the string. If it does → return false Otherwise → return true 🧠 Takeaway Sometimes the hardest part of a problem isn’t the coding — it’s understanding the problem statement clearly. Once the logic clicked, the solution became very straightforward. Consistency with daily problem solving continues. 🔁 #LeetCode #DailyChallenge #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 7 / 100 – LeetCode Challenge Today I solved Length of Last Word (LeetCode #58) using Java. 🔹 Problem: Given a string "s" containing words and spaces, return the length of the last word in the string. 📌 Approach: - Traverse the string from the end. - Ignore trailing spaces. - Start counting characters of the last word. - Stop when a space appears after counting begins. 💡 Key Concepts Practiced: - String traversal - "charAt()" usage - Reverse iteration - Conditional logic ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) ✅ Key Takeaway: Sometimes solving a problem becomes easier when we traverse the data from the end instead of the beginning. #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 9 📌 Problem: 3 Sum 💻 Language: Java 🧠 Concept Used: Sorting + Two Pointer Technique 🔍 Platform: LeetCode Today’s challenge was to find all unique triplets in an array whose sum equals zero — without duplicate combinations. Approach: ✔ Sort the array ✔ Fix one element ✔ Use two pointers to find the other two numbers ✔ Skip duplicates carefully to maintain unique triplets This problem really improved my understanding of pointer movement and edge-case handling. 🔗 Problem Link: https://lnkd.in/gRABQpTt 🔗 Code: https://lnkd.in/ge4qhGAT #100DaysOfCode #Day9 #Java #DSA #LeetCode #TwoPointers #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 47 - LeetCode Journey Solved LeetCode 520: Detect Capital in Java ✅ A simple yet interesting string problem that checks whether capital letters in a word are used correctly. Valid cases: • All letters are uppercase → "USA" • All letters are lowercase → "leetcode" • Only first letter is uppercase → "Google" Approach was straightforward: Count uppercase letters and validate based on the three conditions. Clean logic makes this problem easy and readable. Key takeaways: • Strong understanding of string traversal • Using built-in functions like Character.isUpperCase() • Writing clear conditional logic • Handling edge cases properly ✅ All test cases passed ✅ Clean and efficient solution Small problems like this strengthen fundamentals, and strong fundamentals are the backbone of DSA 🚀 #LeetCode #DSA #Java #Strings #ProblemSolving #CodingJourney #Programming #InterviewPrep #Consistency
To view or add a comment, sign in
-
-
🚀 Day 5 – LeetCode Practice Today, I solved the Swap Nodes in Pairs problem on LeetCode: 🎯 Difficulty: Medium 💻 Language Used: Java 💡 Approach: • Given a linked list, the task was to swap every two adjacent nodes and return the modified list. • I used pointer manipulation to iterate through the list. • Maintained a dummy node to handle swaps at the head cleanly. • For each pair, I adjusted the next pointers to reverse the pair and linked them smoothly to the rest of the list. • Continued this process until the end of the list. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 📚 Key Takeaway: This problem reinforced careful linked list traversal and pointer re-wiring for in-place node rearrangement. It’s a great exercise in understanding how to restructure linked lists efficiently. Consistent problem-solving practice continues to sharpen my data structure implementation skills. 💪 #LeetCode #Java #DSA #LinkedList #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 4 – LeetCode Practice Today, I solved the Valid Parentheses problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given a string containing just the characters ()[]{}, the task was to check whether the input string is valid — meaning every opening bracket has a matching closing bracket in the correct order. • I used a stack to match brackets: – When encountering an opening bracket, push it onto the stack. – When encountering a closing bracket, check whether the top of the stack matches the corresponding opening type. – At the end, if the stack is empty, all brackets matched correctly. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(n) 📚 Key Takeaway: This problem helped reinforce stack usage and careful handling of matching pairs — a foundational technique for many parsing and syntax-checking problems. Consistent problem-solving practice continues to build my confidence and coding fundamentals. 💪 #LeetCode #Java #DSA #Stack #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 5 – LeetCode Practice Today, I solved the Reverse Nodes in k-Group problem on LeetCode: 🎯 Difficulty: Hard 💻 Language Used: Java 💡 Approach: • Given a linked list and an integer k, the task was to reverse every group of k nodes. • I used pointer manipulation and a dummy node to handle group reversals cleanly. • Moved through the list in blocks of k, reversing each sub-group by re-wiring next pointers. • Ensured that if the final group had fewer than k nodes, it was kept as-is. • This approach ensured in-place reversal without extra space. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 📚 Key Takeaway: This problem deepened my understanding of in-place linked list manipulation, group operations, and edge-case handling when list length isn’t a multiple of k. Solving pattern-rich, hard problems like this consistently improves my algorithmic thinking and implementation precision. 💪 #LeetCode #Java #DSA #LinkedList #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 8 – LeetCode Practice Today, I solved the Count and Say problem on LeetCode: 🎯 Difficulty: Easy / Medium 💻 Language Used: Java 💡 Approach: • The “count and say” sequence is built by reading off digits of the previous term — counting repeated digits then describing them. • I started from the base term "1" and iteratively built the next term by scanning the current string and describing consecutive runs of the same character. • This continues until the nth term is generated. ⏱ Complexity: • Time Complexity: O(n × k) (n = sequence length, k = average term length) • Space Complexity: O(k) 📚 Key Takeaway: This problem improved my understanding of string manipulation and iterative pattern construction. Carefully building and transforming sequences is a useful technique in many real-world problems. Consistent problem-solving practice continues to strengthen my logic and coding confidence 💪 #LeetCode #Java #DSA #Strings #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
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