Dinesh Kolhe’s Post

👇 🚀 Day 52 of #100DaysOfCode 💻 Consistency check: still going strong 💪 Today’s problem was a clean and practical string manipulation question — 📝 Length of Last Word (LeetCode) 📌 Problem Summary Given a string consisting of words and spaces, find the length of the last word in the string. Example: "Hello World" → 5 Sounds simple, but edge cases matter: Trailing spaces Multiple spaces between words 🧠 My Approach Instead of splitting the string (which uses extra space), I traversed the string from the end: 1️⃣ Skip all trailing spaces 2️⃣ Count characters until a space is found This keeps the solution efficient and clean. ⚙️ Complexity Analysis ⏱ Time: O(n) 💾 Space: O(1) Optimized and interview-friendly 🚀 🔥 Key Learning Not every problem needs complex logic Backward traversal is a powerful trick for string problems Handling edge cases is what makes solutions robust ✅ Accepted with 0 ms runtime Another step forward in my coding journey ✔️ On to Day 53! 🚀💻 #100DaysOfCode #LeetCode #Java #Strings #ProblemSolving #DSA #CodingJourney #Consistency

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories