🚀 Mastering Java Through LeetCode 🧠 Day 6 Continuing my journey of solving problems from the LeetCode 75 list to strengthen my Data Structures and Algorithms (DSA) skills using Java. Daily coding practice is helping me improve logical thinking, problem-solving ability, and writing cleaner code for real-world applications. 📌 LeetCode Problem Solved Today: Q. 151 – Reverse Words in a String – from LeetCode 🔍 What I Learned: Handling strings with leading, trailing, and multiple spaces Using trim() and split() with regex (\\s+) Reversing words efficiently using StringBuilder Improving string manipulation with O(n) time complexity 💡 Problem Summary: We are given a string s that may contain extra spaces between words or at the beginning/end. The goal is to reverse the order of the words while ensuring: Only one space between words No leading or trailing spaces in the final result. Example: Input: "the sky is blue" Output: "blue is sky the" Another Example: Input: " hello world " Output: "world hello" In this problem, the key challenge is cleaning the spaces first and then reversing the order of the words correctly. ✅ The approach I used: Remove extra spaces using trim(). Split the string using split("\\s+"). Traverse the words array in reverse order. Build the final string using StringBuilder. This problem helped me better understand string processing and edge case handling in Java. #LeetCode #DSA #Java #CodingPractice #ProblemSolving #SoftwareDevelopment #LearningInPublic #LeetCode75
Mastering Java with LeetCode: Reversing Strings
More Relevant Posts
-
Coding agents are innovating fast, but they're also getting bloated. To actually understand what they’re doing, you have to go back to the basics. A good way to learn is to get into it. Adding LSP support to the 260 line nanocode agent in #Java https://lnkd.in/ec5j8QpJ
To view or add a comment, sign in
-
Day 83 - LeetCode Journey Solved LeetCode 237: Delete Node in a Linked List in Java ✅ This problem was a bit different from usual linked list questions. Instead of deleting a node in the traditional way, we weren’t given access to the head of the list. That’s what made it interesting. The trick was to think differently. Instead of removing the node directly, copy the value of the next node into the current node and skip the next node. Simple idea, but not obvious at first. This problem really tests your understanding of how linked lists work internally. Key takeaways: • Thinking beyond standard approaches • Understanding pointer manipulation deeply • Writing minimal and efficient code • Strengthening core linked list concepts ✅ All test cases passed ✅ Clean and optimal solution Problems like these remind me that DSA is not just about coding, but about thinking differently 💡 #LeetCode #DSA #Java #LinkedList #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
Day 26 of Learning Java : Strings Level: Advanced ⚡🧠 Today was all about mastering something I use every day… 👉 Strings but this time, deeply. 🔥 String Methods = Real Power From basics to advanced: length(), isEmpty(), charAt() equals(), compareTo(), contains() substring(), indexOf() Now I can actually control strings, not just use them. ⚡ String Manipulation Transforming data like a pro: toUpperCase(), trim(), replace(), split(), join(), repeat() Feels like playing with text… but with logic. 💡 String Interning intern() stores strings in the String Pool → saves memory → avoids duplicates Java really cares about optimization. 🚀 StringBuilder vs StringBuffer Both are mutable… but different vibes: StringBuilder → Fast ⚡ (used mostly) StringBuffer → Safe 🔒 (thread-safe but slower) Big realization today? Strings are not just text… they’re one of the most powerful and optimized parts of Java. Day 26 and now even string handling feels like a skill 🔥🚀 Special thanks to Aditya Tandon Sir, Rohit Negi Sir and CoderArmy 🙌 #Java #CoreJava #Programming #LearningJourney #Developers #BuildInPublic
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 7 Continuing my journey of solving problems from the LeetCode 75 list to strengthen my Data Structures and Algorithms (DSA) skills using Java. Consistent practice is helping me improve problem-solving ability and preparing for real-world software development and placements. 📌 LeetCode Problem Solved Today: Q. 238 – Product of Array Except Self Given an integer array nums, we need to return an array where each element is the product of all elements of the array except itself. Example: Input: nums = [1,2,3,4] Output: [24,12,8,6] This problem was interesting because: We must solve it in O(n) time complexity We cannot use the division operator It requires understanding of prefix and suffix product technique 💡 Key Learning from Today Optimizing brute force solutions Understanding prefix and suffix multiplication Writing efficient algorithms with O(n) complexity Strengthening array manipulation skills in Java 🧑💻 Approach Used Instead of calculating the product repeatedly, I used: Left product pass Right product pass This helped reduce the time complexity from O(n²) → O(n). 📈 Every day I’m getting better at: Problem solving Writing optimized code Preparing for technical interviews #LeetCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 73 of #90DaysDSAChallenge Solved LeetCode 451: Sort Characters By Frequency Learned an important Java design concept today. Problem Overview: The task was to sort characters in a string based on descending frequency. What confused me initially: Why create a separate Freq class instead of just using HashMap and PriorityQueue directly? Key Learning: PriorityQueue stores one complete object at a time. For this problem, each item needs two pieces of data together: Character Frequency Example: Instead of storing: e and 2 separately We package them as: Freq('e', 2) That custom class acts like a container holding both values in one object, so PriorityQueue can compare and sort them correctly. Why this matters: This taught me that custom classes in Java are often not about complexity, they simply bundle related data into one manageable unit. Alternative approach: We can also use Map.Entry<Character, Integer> instead of creating a custom class, but building Freq makes the logic easier to understand while learning. Today’s takeaway: Not every class is for business logic — sometimes it exists just to package data cleanly. #Java #90DaysDSAChallenge #LeetCode #PriorityQueue #HashMap #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DAY 76/150 — CHECKING SUBTREES WITH RECURSION! 🌳 Day 76 of my 150 Days DSA Challenge in Java and today I solved a problem that strengthens my understanding of tree comparison and recursion 💻🧠 📌 Problem Solved: Subtree of Another Tree 📌 LeetCode: #572 📌 Difficulty: Easy–Medium The task is to determine whether one binary tree is a subtree of another binary tree. A subtree must match both structure and node values exactly. 🔹 Approach Used I used a recursive DFS approach: • Traverse each node of the main tree • For every node: Check if the subtree starting at that node is identical to the given tree • Use a helper function to compare two trees: If both nodes are null → true If values differ → false Recursively compare left and right subtrees ⏱ Complexity Time Complexity: O(n × m) (n = nodes in main tree, m = nodes in subtree) Space Complexity: O(h) (recursion stack) 🧠 What I Learned • Tree problems often require combining traversal + comparison • Recursion is powerful for handling hierarchical structures like trees • Breaking the problem into smaller checks simplifies the solution 💡 Key Takeaway This problem taught me how to: Compare two trees efficiently Apply recursion for structural matching Think in terms of subproblems within trees 🌱 Learning Insight As I continue my Binary Tree journey, I’m understanding that: Most tree problems are based on DFS, BFS, or recursion patterns Mastering these basics makes complex tree problems easier ✅ Day 76 completed 🚀 74 days to go 🔗 Java Solution on GitHub: 👉 https://lnkd.in/gZNXaW-C 💡 In trees, solving smaller parts correctly leads to the full solution. #DSAChallenge #Java #LeetCode #BinaryTree #Recursion #DFS #150DaysOfCode #ProblemSolving #CodingJourney #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 55 of #100DaysOfCode — Getting Started with Multithreading in Java Over the past 2 days, I explored one of the most important concepts in Java: Multithreading 🔥 💡 What I Learned 🧵 What is Multithreading? Multithreading allows a program to execute multiple tasks simultaneously, improving performance and efficiency ⚡ 👉 Instead of running tasks one after another, we can run them in parallel. ⚙️ Creating Threads in Java 1️⃣ Using Thread Class Extend the Thread class Override the run() method Start using start() 2️⃣ Using Runnable Interface (Best Practice ✅) Implement Runnable Pass it to a Thread object Start execution using start() 🧠 Key Takeaways ✔ Runnable is preferred over Thread (better design & flexibility) ✔ Supports multiple inheritance ✔ Separates task from execution ✔ Helps in building scalable backend systems ⚠️ Important Concept 👉 Difference between: run() ❌ (normal method call) start() ✅ (creates new thread) 🔥 Real-World Use Cases Backend APIs Payment systems Real-time applications Inventory & billing systems (like the one I'm building 🏪) 🚀 What’s Next? ➡️ Synchronization ➡️ Race Conditions ➡️ ExecutorService (Thread Pool) Learning multithreading feels like unlocking a new level in Java 💪 Huge thanks to my mentor Suresh Bishnoi for simplifying complex concepts like multithreading and pushing me to keep learning consistently. #Java #Multithreading #100DaysOfCode #BackendDevelopment #LearningJourney
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 89 ✅ Today, I solved the Minimum Distance to the Target Element problem on LeetCode 💻 🔍 Problem Insight: Given an array, a target element, and a starting index — we need to find the minimum distance between the start index and any occurrence of the target. 🧠 Approach I Used: Traversed the array using a loop Checked where the element equals the target Calculated distance using Math.abs(i - start) Updated the minimum distance using Math.min() ⚡ Key Learning: Sometimes the simplest linear traversal (O(n)) gives the most optimal solution. No need to overcomplicate! 💡 Code Concept: Use a variable to track minimum distance Update it whenever a closer target is found 💬 What I Learned Today: Consistency is more important than complexity. Even simple problems strengthen your fundamentals! 🔥 Day 89 Progress: Strengthened problem-solving skills Improved understanding of distance-based logic Practiced writing clean and optimized Java code 📈 Still learning, still growing… one problem at a time! #LeetCode #DSAinJava #ProblemSolving #Java #CodingJourney #Consistency #SoftwareDeveloper 🚀
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
-
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