Hello dudes and dudettes!! 🚀 Day 19/150 — Solved LeetCode 58: Length of Last Word Today’s problem looked super simple at first… but taught me a great lesson about handling edge cases carefully 😄 🧠 What’s the Problem About? You’re given a string that contains words separated by spaces. Your task is to find the length of the last word. Sounds easy, right? Well… not always 👇 💡 The Catch The string might contain: Extra spaces at the beginning Extra spaces at the end Multiple spaces between words So it’s not just about “finding the last word” — it’s about finding the last valid word. 🔥 Example Input: " hello world " At first glance, it looks messy 😵 But the actual last word is: 👉 "world" 👉 Length = 5 🧠 The Thought Process Instead of trying to split everything immediately, I started thinking: Why not scan from the end? Because: The last word is always near the end We can skip spaces quickly Then just count characters until we hit a space ⚙️ Approach That Worked Ignore trailing spaces Start from the end of the string Count characters until a space appears That count is your answer Simple, efficient, and clean. 😎 Why This Problem Is Interesting It’s not about complexity — it’s about precision It shows how small edge cases can break simple logic It encourages thinking in reverse (which is surprisingly powerful) 💡 What I Learned Always consider edge cases like extra spaces Sometimes scanning backward is smarter than forward Even easy problems can sharpen your attention to detail 🎯 Key Takeaway “Simple problems aren’t always trivial — they test how carefully you think.” 🔥 Another step forward — improving not just coding skills, but problem-solving mindset. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
LeetCode 58: Length of Last Word Solution
More Relevant Posts
-
Hello dudes and dudettes!! 🚀 Day 20/150 — Solved LeetCode 14: Longest Common Prefix Today’s problem looked simple on the surface… but turned out to be a great exercise in thinking systematically 😄 🧠 What’s the Problem About? You’re given a list of strings, and your task is to find the longest common prefix shared among all of them. In simple terms: 👉 “What is the longest starting part that every word has in common?” 💡 Example Input: ["flower", "flow", "flight"] All words start with: 👉 "fl" But after that: "flower" → o "flow" → o "flight" → i ❌ So we stop there. 🎯 Final answer: "fl" 🔥 The Catch At first, I thought: “Let me compare strings directly.” But the real trick is how you compare them. Instead of comparing whole words, I realized: 👉 Compare character by character (column-wise) 🧠 The Breakthrough Idea Think of the words like this: f l o w e r f l o w f l i g h t Now check: Column 1 → all f ✅ Column 2 → all l ✅ Column 3 → o, o, i ❌ 👉 Stop immediately. ⚙️ Approach That Worked Take the first word as a reference Loop through each character Compare that character with all other words If any mismatch → stop Otherwise → add it to the prefix 😎 Why This Problem Is Interesting It teaches you to break problems into smaller checks Shows how powerful a simple idea (column comparison) can be Reinforces the importance of stopping early when conditions fail 💡 What I Learned Don’t overcomplicate — start with the simplest structure Comparing step-by-step can be more effective than comparing everything at once Early exit conditions can save time and improve efficiency 🎯 Key Takeaway “You don’t need to compare everything — just stop at the first mismatch.” 🔥 Another step forward in the journey — learning to think clearly and solve efficiently. #LeetCode #Algorithms #Strings #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 21/150 — Solved LeetCode 151: Reverse Words in a String Today’s problem was a great reminder that even something as simple as a sentence can hide a few tricky details 😄 At first glance, reversing words sounds easy… But once spaces start behaving weirdly, things get interesting. 🧠 What’s the Problem About? You’re given a string that contains words separated by spaces. Your task is to: 👉 Reverse the order of words 👉 Not the characters inside them 💡 Example Input: "the sky is blue" Output: 👉 "blue is sky the" 🔥 The Twist It’s not just about reversing words… The string might contain: Extra spaces at the beginning Extra spaces at the end Multiple spaces between words Example: " hello world " Expected Output: 👉 "world hello" So we also need to clean up the spaces while solving it. 🧠 The Thought Process Instead of overcomplicating things, I broke it down: Extract the words (ignore spaces) Reverse their order Join them back with a single space That’s it. Simple steps → clean solution. ⚙️ Why This Approach Works Splitting automatically removes extra spaces Reversing handles the order Joining ensures proper formatting No unnecessary checks. No messy conditions. 😎 Why This Problem Is Interesting It looks easy but tests your handling of edge cases Shows how built-in operations can simplify problems Reinforces the idea that clarity beats complexity 💡 What I Learned Clean input → clean output Breaking a problem into steps makes it easier Sometimes the best solution is the simplest one 🎯 Key Takeaway “Don’t fight the problem — break it down and let simple steps solve it.” 🔥 Another step forward in the journey — writing cleaner, smarter solutions. #LeetCode #Algorithms #Strings #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 11/150 — Cracked LeetCode 274: H-Index Today’s problem was less about coding… and more about thinking smart 😄 At first glance, it looks like just another array problem. But once I dug in, I realized it’s actually about measuring impact — not just numbers. 🔍 What’s the Problem About? You’re given an array where each number represents how many times a research paper was cited. Now the twist: 👉 You need to find the H-Index Which basically means: A researcher has an H-Index of h if they have h papers with at least h citations each. 🧠 The “Aha!” Moment Initially, it feels confusing… like, “Where do I even start?” But everything clicks when you: 👉 Sort the array in descending order Suddenly, the problem becomes super clean. Now it’s just about checking: “Do I have 1 paper with ≥1 citation?” “Do I have 2 papers with ≥2 citations?” “Do I have 3 papers with ≥3 citations?” …and so on. The moment this condition fails — boom, you stop. That’s your answer. 📊 Quick Example Input: [3, 0, 6, 1, 5] After sorting: [6, 5, 3, 1, 0] Now checking step-by-step: 1 paper → valid ✅ 2 papers → valid ✅ 3 papers → valid ✅ 4 papers → not valid ❌ 🎯 Final Answer: 3 💡 What Made This Problem Interesting? It’s not about checking everything — it’s about knowing when to stop A simple sort can completely change how you see the problem It teaches you to think in terms of thresholds and consistency, not just values 😎 My Takeaway This problem is a perfect reminder that: “Sometimes the smartest solution isn’t more work… it’s better perspective.” 🔥 One more step forward in the journey. Let’s keep building. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 17/150 — Solved LeetCode 13: Roman to Integer Today’s problem was a fun twist — not your usual numbers, but ancient ones 😄🏛️ Converting Roman numerals into integers sounds simple… until the rules start playing tricks on you. 🧠 What’s the Problem About? You’re given a Roman numeral string like: 👉 “III”, “IV”, “IX”, “MCMIV” And your job is to convert it into a normal integer. 💡 Initial Thought At first, I assumed: “Just map each symbol and keep adding.” And that works… sometimes. But then comes the twist 👇 🔥 The Catch Roman numerals don’t always follow simple addition. 👉 If a smaller value comes before a bigger value, you subtract instead of adding. Examples: IV = 5 - 1 = 4 IX = 10 - 1 = 9 That’s where things get interesting. 💥 The Breakthrough Moment Instead of overthinking, I simplified the logic to one powerful idea: Look at the next character. If the next value is bigger → subtract current Otherwise → add current That’s it. Just one small check completely solves the problem. ⚙️ How It Works Traverse the string from left to right Compare each character with the next Decide whether to add or subtract Keep updating the total Simple logic. Clean execution. 📊 Why This Problem Is Cool It mixes logic with pattern recognition Shows how a tiny condition can change the whole approach Teaches you to look ahead before deciding 😎 What I Learned Don’t assume rules are always straightforward Edge cases often define the real solution Breaking the problem into small decisions makes everything easier 🎯 Key Takeaway “Sometimes the answer isn’t in the current step… it’s in what comes next.” 🔥 Another step forward — learning to think, not just code. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
My new ebook just dropped. 👇 I spent weeks documenting the exact Claude Code automations our team uses to save 20 hours every week. The result: "Automate Everything" — 10 copy-paste automations for dev teams who are tired of doing manually what AI can do in seconds. What's inside: → Auto-triage GitHub issues (saves ~3 hrs/wk) → PR code review bot (saves ~5 hrs/wk) → Unit test generator (saves ~4 hrs/wk) → + 7 more production-ready automations Every automation includes a workflow diagram + Python/Bash code you can drop into your repo today. No fluff. Instant download. 🔗 https://lnkd.in/dvCxkpDp #ClaudeCode #AIAutomation #DevTools #Productivity #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 1 — Building Problem Solving Skills I’m continuing my journey to improve problem-solving skills by staying consistent, disciplined, and accountable — one problem at a time. 🧩 Problem: • Two Sum (LeetCode #1) 📚 Topic: Arrays (Pair Traversal) 💡 Key Insight: Checking all possible pairs works, but it highlights the need for more efficient approaches as input size grows. ⚡ Approach: • Pick an element using index i • Traverse remaining elements using index j • Check if nums[i] + nums[j] == target • Return indices when condition is satisfied 🎯 Takeaway: Even simple problems help strengthen logic and introduce optimization thinking. ⏱ Complexity: Time → O(n²) Space → O(1) 💻 Sample Input: nums = [2, 7, 11, 15] target = 9 ✅ Output: [0, 1] Consistency > Perfection 💪 #DSA #LeetCode #ProblemSolving #Python #CodingJourney #LearningInPublic #Arrays #TechGrowth
To view or add a comment, sign in
-
-
🚀 Cracked the Spiral Matrix problem on LeetCode — and here’s the mindset behind it 👇 Most people jump straight into coding this problem. I didn’t. Instead, I approached it like a boundary management problem 🧠 🔍 My thought process: • Treat the matrix like a shrinking box • Maintain 4 pointers: top, bottom, left, right • Traverse layer by layer — not element by element • After each traversal, shrink the boundaries inward This helped me: ✅ Avoid unnecessary conditions ✅ Prevent duplicate traversals ✅ Keep the logic clean and scalable The real learning wasn’t just solving it — it was realizing how visualizing the structure simplifies the code. 💡 Sometimes the difference between confusion and clarity is just how you frame the problem. 🔥 Consistency + clarity > brute force coding #LeetCode #DSA #CodingJourney #ProblemSolving #Python #WomenInTech #TechLearning #SoftwareEngineering #100DaysOfCode #StudentDeveloper #CodingMindset #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 3 of #14DaysOfPython 🐍 Today’s focus: Loops (Iteration Mastery) — where automation really begins. 💡 Easy way to understand loops: 🔹 Why loops? 👉 When you need to repeat a task multiple times instead of writing code again and again 💡 Core Concepts (Logic First): 🔹 for loop vs while loop for → when you know how many times to run while → when condition decides 🔹 range() variations range(n) → 0 to n-1 range(start, end) range(start, end, step) 🔹 Loop control break → stop loop immediately continue → skip current step pass → do nothing (placeholder) 🔹 Infinite loop ⚠️ 👉 Happens when condition never becomes false 🔹 Iteration patterns 👉 Numbers, strings, lists — everything can be looped 🧠 Problems I practiced: Sum of digits Reverse a number Factorial Count occurrences ✨ Key takeaway: Loops are not about syntax — they are about thinking in repetition and patterns. Day 3 done ✅ Moving to Day 4 💪 #Python #HackerRank #CodingJourney #LearningInPublic #ProblemSolving #DeveloperJourney #100DaysOfCode#codegnan
To view or add a comment, sign in
-
-
Day 15/30 🔹 Problem: Check if a year is a leap year 🔹 What I focused on today: Understanding how multiple conditions work together 🔹 My Thinking Process: A year is divisible by 4 → leap year But if divisible by 100 → NOT a leap year Exception: if divisible by 400 → leap year 🔹 Inputs I used: Year 🔹 Code: year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap Year") else: print("Not a Leap Year") 🔹 Example: Year = 2024 → Leap Year Year = 1900 → Not a Leap Year Year = 2000 → Leap Year 🔹 Key Takeaway: Combining conditions correctly is important to avoid logical mistakes, even in simple problems #Day15 #Python #30DaysOfCode #LearningInPublic #DataAnalytics #ProblemSolving
To view or add a comment, sign in
-
🚀 From Confusion → Clarity: My Approach to “Sort the People” (LeetCode) Today I solved the Sort the People problem, and instead of jumping straight into sorting tricks, I focused on building clarity step by step 👇 🔍 My Thought Process: First, I paired each name with its corresponding height using a list (like a mini mapping). Then, I sorted this list based on height. Since the problem required descending order, I simply reversed the sorted list. Finally, I extracted only the names in the correct order. 💡 Key Learning: Sometimes, the simplest approach is the best one. Instead of overcomplicating with advanced data structures, breaking the problem into smaller transformations made it super manageable. 🧠 What this improved for me: Understanding how to use lambda for sorting Confidence in handling paired data (name + value problems) Thinking in steps rather than jumping to optimization ⚡ Code Strategy in One Line: Pair → Sort → Reverse → Extract Consistency > Speed. One problem at a time. 💪 📈 If you're also grinding DSA, keep going — progress compounds! #DSA #LeetCode #CodingJourney #Python #ProblemSolving #Consistency #TechGrowth #100DaysOfCode #WomenInTech #FutureEngineer
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