Day 47 of #100DaysOfLeetCode Today's problem: Reverse Words in a String Language used: Java What I did today: I implemented a solution to reverse the order of words in a given string while handling extra spaces efficiently. Used split("\\s+") to handle multiple spaces. Reconstructed the reversed string using StringBuilder. Applied trim() to clean up leading and trailing spaces. Key Takeaways: split("\\s+") is great for ignoring multiple spaces. Always use trim() to ensure a neat final output. StringBuilder makes string manipulation much faster than direct concatenation. #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #Programming #DeveloperJourney #LearnToCode
Reversed Words in a String with Java
More Relevant Posts
-
"Exploring the Magic of Loops in Java! 💻✨ From simple triangles to complex symmetric designs, star patterns are more than just beginner exercises — they’re a creative way to master logic, loops, and nested conditions! Here’s my deep dive into different star pattern programs in Java — each one crafted to teach how iterations and conditions interact to create stunning console outputs. Programming isn’t just about solving problems; it’s about creating beauty through logic. 🌟 #JavaProgramming #CodingJourney #PatternLogic #ProgrammersLife #CodeArt #TechLearning #StarPattern #LogicBuilding"
To view or add a comment, sign in
-
Day 43 of #50DaysOfLeetCodeChallenge Problem: Valid Parentheses Approach: Used a stack to keep track of opening brackets. For each closing bracket, checked if it matches the top of the stack. Returned false if there was a mismatch or stack was empty. This ensures all brackets are properly nested and closed. Key Takeaways: Stacks are perfect for problems involving nested structures. Simple traversal with O(n) time complexity and O(n) space. Feeling more confident handling pointers and references in Java! Performance: Using a stack this way really helped me understand how to manage nested elements efficiently. #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #Stack #Programming
To view or add a comment, sign in
-
-
🚀 Day 140 of #150DaysOfCode on LeetCode Solved: 1526. Minimum Number of Increments on Subarrays to Form a Target Array Language: Java The task was to determine the minimum number of subarray increment operations needed to build the target array from all zeros. 🔹 Intuition: Every time the current element is greater than the previous one, it means we need that many new operations to reach the next level. Decreases don’t add extra work since earlier increments already cover them. 🔹 Approach: Start with the first element’s value as the initial count. For each subsequent element, if it’s larger than the previous one, add the difference. The sum of all such differences gives the minimum number of operations required. 🔹 Complexity: Time: O(n) Space: O(1) #LeetCode #150DaysOfCode #Java #CodingChallenge #ProblemSolving #Greedy #Arrays #DSA #TechLearning #Programmer #WomenInTech #CodeJourney #DynamicProgramming
To view or add a comment, sign in
-
-
Ever debugged for hours only to realize you were comparing Strings with == instead of .equals()? You're not alone. 🤦♂️ The culprit? Java's String Pool - a memory optimization that trips up even experienced developers. I just wrote a deep dive into: ✅ How String Pool actually works behind the scenes ✅ Why comparing the same content with == sometimes returns true, sometimes false ✅ The intern() method and when to use it ✅ Real performance benchmarks ✅ Common pitfalls that waste memory Practical code examples included. 5-minute read. Read here: https://lnkd.in/g4emECJM #Java #Coding #Programming #SoftwareDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 94 of #100DaysOfCode 🧠 Solved "Reverse String II" in Java using a clear two-pointer approach with modular design. 🔹 Problem: • Given a string s and an integer k, reverse the first k characters for every block of 2k characters from the start. • If fewer than k characters remain, reverse all of them. • If between k and 2k remain, reverse only the first k. 🔹 Approach: • Convert the string into a char[] for in-place editing. • Iterate in steps of 2k. • For each block, find left and right boundaries (right = min(left + k - 1, n - 1)). • Reverse the section using a helper method with two pointers. • Return the new string after all blocks are processed. 🔹 Key Learning: • Renaming pointers to left and right improves readability for two-pointer logic. • Modularizing reversal logic into a helper method makes the code cleaner and reusable. • Handling partial segments (less than k left) becomes easy with boundary checks. 🔹 Thanks to: • Dr Bharathi Raja N — Director of Training & Placement, Dhanalakshmi College of Engineering • Sreesairam V Sir — Aptitude Guru Hem #DhanalakshmiCollegeOfEngineering #LeetCode #Java #100DaysOfCode #Day94 #TwoPointers #StringManipulation #CodingJourney
To view or add a comment, sign in
-
-
Day 21 of #50DaysOfCode – Java Today’s challenge was Printing All Prime Numbers Between 1 and N. This task helped me understand how to identify prime numbers and how nested loops work in Java. Key learnings from today: 🔹 A prime number is divisible only by 1 and itself 🔹 We can check primality by testing divisibility 🔹 Using logical conditions and loops together improves problem-solving Slowly building confidence with new concepts every day! 💪✨ #Java #CodingJourney #50DaysOfCode #PrimeNumbers #LogicBuilding #ProgrammingBasics #LearningEveryday
To view or add a comment, sign in
-
💡 𝗝𝗮𝘃𝗮/𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝗧𝗶𝗽 - 𝗦𝘁𝗿𝗶𝗻𝗴 𝐔𝐬𝐚𝐠𝐞 🔥 💎 𝗧𝗵𝗿𝗲𝗲 𝗪𝗮𝘆𝘀 𝘁𝗼 𝗖𝗵𝗲𝗰𝗸 𝗦𝘁𝗿𝗶𝗻𝗴 𝗣𝗿𝗲𝗳𝗶𝘅/𝗦𝘂𝗳𝗳𝗶𝘅 👍 𝗨𝘀𝗶𝗻𝗴 𝘀𝘁𝗮𝗿𝘁𝘀𝗪𝗶𝘁𝗵 𝗮𝗻𝗱 𝗲𝗻𝗱𝘀𝗪𝗶𝘁𝗵 𝗺𝗲𝘁𝗵𝗼𝗱𝘀 The most readable and straightforward approach provided by the String class. These methods clearly express your intent and are optimized for prefix and suffix validation in production code. 💡 𝗨𝘀𝗶𝗻𝗴 𝗰𝗵𝗮𝗿𝗔𝘁 𝘄𝗶𝘁𝗵 𝗹𝗲𝗻𝗴𝘁𝗵 𝗰𝗵𝗲𝗰𝗸 Direct character access using the charAt() method combined with length() for index calculation. This approach offers fine-grained control when checking specific character positions at string boundaries. 🔥 𝗨𝘀𝗶𝗻𝗴 𝗿𝗲𝗴𝗲𝘅 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 𝗺𝗮𝘁𝗰𝗵𝗶𝗻𝗴 The powerful Pattern and Matcher API from java.util.regex package. Perfect for complex validation scenarios where you need flexible pattern matching beyond simple prefix/suffix checks. 🤔 Which one do you prefer? #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
📅 Days 57–64 of My Coding Journey — Diving Deep into Java Exception Handling, Threads & Real-World Projects 💻 Over the past week, I explored some of the most practical and powerful concepts in Java that take coding from theory to real-world application. 💡 Topics I covered: ✅ Exception Handling – mastering try-catch-finally blocks, and creating Custom Exceptions for cleaner error control. ✅ Multithreading – understanding how threads work, how to start and manage them efficiently. ✅ StringBuilder & StringBuffer – learning the difference between mutable classes and thread safety in string manipulation. ✅ Explored important String methods to handle text effectively. ✅ Built a Patient Management System 🏥 — implementing OOP principles, exceptions, and thread usage in one project. #Day57 #Day58 #Day59 #Day60 #Day61 #Day62 #Day63 #Day64 #Java #ExceptionHandling #Threads #StringBuilder #StringBuffer #OOPS #CodingJourney #SoftwareEngineering #100DaysOfCode #LearningInPublic #KunalKushwaha #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 129/160 – Total Decoding Messages | Dynamic Programming Today’s challenge was about decoding numeric messages into alphabets (like 1→A, 2→B...26→Z). Used a DP approach to count all valid decoding ways efficiently. 🧠 Key takeaway: Dynamic Programming shines when a problem’s state depends on previous results — here, each position depends on the previous one and the one before it. #100DaysOfCode #GeeksforGeeks #160DaysOfDSA #DynamicProgramming #ProblemSolving #Java #CodingJourney #LearnByDoing
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