👇 🚀 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
Dinesh Kolhe’s Post
More Relevant Posts
-
Day 18 – LeetCode 7 | Reverse Integer | Handling Overflow Like a Pro Solved LeetCode 7 – Reverse Integer today. At first glance, it looks like a basic number problem. It’s not. The real challenge is overflow handling, not reversing digits. Most beginners: → reverse digits correctly → fail when the number exceeds 32-bit integer range → get wrong answers If you ignore overflow, your solution is broken. Period. Core idea Extract last digit using % 10 Append using rev = rev * 10 + digit BEFORE multiplying → check overflow Complexity Time → O(log10 n) Space → O(1) What I improved today Edge case thinking Overflow detection Defensive coding mindset Simple problems hide important fundamentals. Master these → interviews become easy. #LeetCode #Day18 #Java #DSA #ProblemSolving #CodingInterview #100DaysOfCode #SoftwareEngineer #Algorithms #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 57 of #100DaysOfCode Today’s problem was a clean and classic two-pointer exercise — 🔁 LeetCode 344: Reverse String Simple on the surface, but a great reminder of in-place algorithms and pointer manipulation. 📌 Problem Summary You’re given a character array s. Your task is to reverse the array in-place, using O(1) extra space. 🧠 Approach Used: Two Pointers ✔️ Initialize: left = 0 right = s.length - 1 ✔️ Swap characters while left < right, then move pointers inward. This ensures: No extra memory Linear traversal Clean and readable logic ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (in-place) ✔️ 477 / 477 test cases passed 🚀 Runtime: 0 ms (Beats 100%) 🔥 Key Learning Even the simplest problems reinforce core fundamentals: Two-pointer technique In-place operations Space optimization Mastering basics = dominating harder problems later 💪 Onward to Day 58 🚀 #100DaysOfCode #LeetCode #ReverseString #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 36/100 of My LeetCode Challenge: Mastering Greedy & Dynamic Programming! Just solved LeetCode 3507: Minimum Pair Removal to Sort Array I – an interesting problem that beautifully blends greedy operations with dynamic programming thinking! 🧠 🔍 The Challenge: Given an array, repeatedly replace the adjacent pair with the minimum sum until the array becomes non-decreasing. Return the minimum number of such operations required. 💡 Key Insights: This isn't just about blindly following the operation description (selecting minimum sum pairs) The optimal solution requires recognizing this as a dynamic programming problem We need to find the minimum operations to partition the array into segments that can be merged while maintaining the non-decreasing property Each merge operation happens only when the left segment's sum exceeds the right segment's sum 🛠️ My Approach: Implemented a memoized DP solution that explores all possible partition points For each possible split position, recursively solve left and right subarrays Add a merge cost when the left segment's sum is greater than the right segment's sum Use memoization to avoid redundant computations for O(n²) time complexity 📊 Performance: Runtime: 66.06% Memory: 44.62 MB Beats: 32.51% of Java submissions 🎯 Why This Matters: This problem is a great example of how: Problem understanding matters more than just following instructions Dynamic programming can elegantly solve what seems like a greedy problem Memoization dramatically improves performance for recursive solutions Real-world scenarios often require transforming problem statements into solvable patterns ✨ The Journey Continues: Every day of this 100-day challenge brings new learning opportunities. Today reinforced that sometimes the direct approach isn't optimal, and we need to think one level deeper about the underlying structure of the problem. #LeetCode #CodingChallenge #100DaysOfCode #ProblemSolving #DynamicProgramming #GreedyAlgorithms #Java #SoftwareEngineering #TechCareer #DeveloperJourney #Algorithm #DataStructures #CodingInterview #Programming
To view or add a comment, sign in
-
-
Day 18 of #100DaysOfCode 🚀 📌 Problem: Isomorphic Strings (LeetCode) 💡 Key Learning: ▪️Two strings are isomorphic if there’s a one-to-one character mapping that stays consistent throughout. 🔍 What I focused on today: ▪️Using HashMap to store character mappings ▪️Ensuring no two characters map to the same value ▪️Understanding the importance of correct if–else structure ▪️Why checking string length first matters ▪️How small logical mistakes can break the entire solution 🧠 Biggest takeaway: Correct logic flow matters more than just writing code that compiles. Consistent practice, clearer logic, and better problem-solving—one day at a time 💪 #Day18 #LeetCode #DSA #Java #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 19 of my DSA consistency challenge — solved LeetCode 14: Longest Common Prefix 🚀 Today’s problem looked easy at first, but it teaches an important lesson about string comparison and edge cases. Problem: Given an array of strings, find the longest common prefix among them. If no common prefix exists, return an empty string. Key idea: Start with the first word as the prefix and shrink it step by step until every string starts with it. If at any point it becomes empty, stop — there is no common prefix. What I improved today: • String manipulation skills • Edge case handling (empty array, single word, no prefix) • Clean iterative thinking instead of overcomplicating Time Complexity: O(n × m) n = number of strings, m = length of shortest string Consistency > Motivation. 19 days straight. No skipping. #Day19 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #SoftwareEngineer #InterviewPreparation #100DaysOfCode #Developers #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 24 – LeetCode 1358 | Mastering Sliding Window for Substring Counting Solved LeetCode 1358: Number of Substrings Containing All Three Characters today. At first glance, this problem looks like a brute-force substring question. But checking every substring leads to O(n²) or O(n³) time, which is unacceptable for interviews. The correct approach is using the Sliding Window (Two Pointers) technique. Instead of generating all substrings: Expand the window Track counts of a, b, and c Once all three are present, count all valid substrings at once Shrink the window and repeat This reduces the complexity to O(n). Today’s focus: • Efficient substring counting • Two-pointer logic • Thinking in patterns instead of brute force Improving problem-solving skills one day at a time. #LeetCode #DSA #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingInterview #SoftwareDeveloper #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
One of the best habits I’m currently building is writing pseudocode before writing real code. It forces me to slow down, think clearly, and design the logic first instead of jumping straight into syntax and getting stuck. If you’re new to programming, pseudocode is one of the simplest tools to reduce overwhelm and build real problem-solving skills. Clear thinking first. Clean code later. #OctoPrep #PythonDeveloper #DataScience #DataAnalysis
To view or add a comment, sign in
-
LeetCode Daily Challenge Solved Problem: Divide an Array Into Subarrays With Minimum Cost Today’s problem was a great reminder that understanding the definition of cost can completely change the approach. We are given an array and must divide it into 3 contiguous subarrays. The cost of each subarray = its first element. Our goal is to minimize the total cost. If we choose split points i and j, the total cost becomes: nums[0] + nums[i] + nums[j] So instead of thinking about all elements, we only care about the starting elements of each subarray. Optimized Greedy Insight (O(n)) The first subarray must start at index 0 We just need to find the two smallest elements from the rest of the array Add them with nums[0] to get the minimum cost This turns what looks like a partition problem into a simple minimum selection problem. Key Takeaways Always re-check how the “cost” is defined Brute force thinking often leads to greedy optimization Consistent daily practice is helping me sharpen my problem-solving and interview skills #LeetCode #DSA #Java #ProblemSolving #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 35 of 50 Days of Code on LeetCode 🚀 Today I worked on a problem that highlighted the importance of ordering data correctly to uncover optimal solutions—finding all pairs with the minimum absolute difference in an array of distinct integers. 🔍 Approach: • Sorted the array to ensure proper ordering • Compared adjacent elements to identify the minimum absolute difference • Collected all pairs matching this minimum difference • Returned the pairs in ascending order automatically 💡 Key Learnings: • The closest values in a dataset often appear after sorting • Minimum absolute differences are found between adjacent elements • Preprocessing steps like sorting are crucial for correctness • Clean logic improves both efficiency and readability ⚙️ Complexity: Time: O(n log n) Space: O(1) (excluding output) This problem reinforced how a simple preprocessing step can transform a problem into an elegant and interview-ready solution. Continuing to build strong DSA fundamentals in Java 🚀 #Day35 #50DaysOfCode #LeetCode #Java #DSA #ProblemSolving #Algorithms #CodingJourney #PlacementPreparation #LearningByDoing
To view or add a comment, sign in
-
-
Day 4 | LeetCode Daily Solved LeetCode Problem #152 – Maximum Product Subarray Concept: • Dynamic Programming • Tracking max & min due to negative values Key Learnings: • Negative numbers can flip the result, so tracking min is as important as max • Simple-looking problems can hide tricky edge cases One problem a day — building consistency and stronger fundamentals. #LeetCode #DSA #DynamicProgramming #Java #ProblemSolving
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