🚀 Day 59 of #100DaysOfCode Today’s problem was Jump Game II, and it turned out to be a great learning experience in understanding how to move from a brute-force mindset to an optimized greedy solution. 🔹 Problem Statement: You are given an array where each element represents the maximum jump length from that position. Starting from index 0, the goal is to reach the last index using the minimum number of jumps. 🔹 Initial Thought (Brute Force): My first instinct was to try all possible jumps from each index using recursion. This approach explores every path to the end and then picks the minimum jumps required. However, this method has a major drawback: * It leads to exponential time complexity * Results in Time Limit Exceeded (TLE) for larger inputs This made it clear that a better, optimized approach was needed. 🔹 Optimized Approach (Greedy): Instead of exploring all possibilities, I learned how to make the best decision at each step using a greedy strategy. The idea is: * Keep track of the farthest index we can reach while traversing * Maintain a current boundary (range) of indices we can explore with the current number of jumps * When we reach the end of this boundary, we increase the jump count and update the boundary to the farthest reachable index This ensures: ✔ Minimum number of jumps ✔ Efficient traversal in a single pass 🔹 Key Variables Used: * farthest→ tracks the maximum reachable index * currEnd→ marks the end of the current jump range * jumps → counts the number of jumps taken 🔹 Time & Space Complexity: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔹 Key Learnings from Today: ✨ Greedy algorithms can outperform brute force when decisions can be made locally ✨ Tracking ranges instead of individual paths simplifies the problem ✨ Many array problems are actually about intervals and coverage ✨ Optimization is not always about complex logic—sometimes it’s about observing patterns 🔹 Personal Reflection: Today’s problem reminded me that getting stuck on brute force is okay, but the real growth happens when you step back, rethink, and optimize Each day of this challenge is helping me improve not just my coding skills, but also my problem-solving mindset and ability to think efficiently under constraints. 💯 Consistency > Perfection One step closer to becoming a better developer every single day. #Day59 #100DaysOfCode #DSA #GreedyAlgorithm #LeetCode #CodingJourney #ProblemSolving #Placements #SoftwareDevelopment
Optimizing Jump Game II with Greedy Algorithm
More Relevant Posts
-
#100DaysOfLeetcode journey 🚀 🚀 Day 74/100 — Wildcard Directions & Greedy Optimization! Today’s Problem: 2833. Furthest Point From Origin 🔹 The Goal: Given a string representing moves on a number line ('L' for left, 'R' for right, and '_' as a wildcard), find the maximum absolute distance from the origin you can reach after performing all moves. 🔹 The Insight: This problem boils down to a simple Greedy Strategy. To get as far away from zero as possible, you want to pick a "dominant" direction. The underscores are your flexible assets—they should always be used to reinforce whichever direction ('L' or 'R') you are already moving in more. 🔹 The Logic: Component Counting: I simply counted the occurrences of 'L', 'R', and the wildcards ('_'). Net Displacement: The core distance is the absolute difference between the fixed moves: $|R - L|$. Wildcard Bonus: To maximize the distance, every single underscore should be converted into the direction that increases that absolute difference. The Result: Total Distance = $|R - L| + \text{Underscores}$. ✨ Achievement: Day 74! Approaching the three-quarter mark of the challenge. Today was a great reminder that not every "optimization" problem requires complex Dynamic Programming. Sometimes, the most efficient solution ($O(N)$ time, $O(1)$ space) comes from identifying the greedy choice that yields the maximum variance. 🔍 Steps followed: ✔ Linear Scan: One pass to aggregate the move types. ✔ Directional Bias: Identified the majority direction. ✔ Greedy Allocation: Assigned all flexible moves to the majority direction to maximize the final offset. 🔧 The Stats: Time Complexity: $O(n)$ Space Complexity: $O(1)$ 74 days down! The streak is strong, and the logic is getting leaner. Let's keep moving! 🛠️ #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #SoftwareEngineer #InternshipBound #Programming #GreedyAlgorithms #Logic #Optimization #Day74
To view or add a comment, sign in
-
-
🚀 Day 56 of #100DaysOfCode Today’s problem was “Count and Say” from LeetCode, and honestly, it turned out to be a great exercise in understanding patterns and strengthening my fundamentals in strings and iteration. At first glance, the problem looks a bit confusing because of its recursive definition. But once I broke it down, I realized that it’s all about reading the previous result and constructing the next one using run-length encoding (RLE). 🧠 My Approach: I started with the base case: 👉 Count and say(1) = "1" Then for every next step, I: * Traversed the current string * Counted consecutive repeating characters * Built a new string by appending: (count + character) For example: * "1" → "11" (one 1) * "11" → "21" (two 1s) * "21" → "1211" (one 2, one 1) This step-by-step transformation helped me clearly understand how the sequence evolves. 💡 Key Learnings from Today: * Breaking complex problems into smaller steps makes them manageable * String traversal and careful indexing are very important * While loops can be more useful than for loops in pattern-based problems * Edge cases (like last character handling) need extra attention * Writing clean and readable code helps avoid logical mistakes ⚙️ Challenges I Faced: Initially, I struggled with managing the pointer while counting characters and ensuring I don’t skip any element. But after dry-running the code and visualizing the process, everything started making sense. 🔥 What I Improved Today: * Better understanding of pattern-based problems * More confidence in handling strings * Improved logical thinking and debugging skills ✨ This journey is teaching me that consistency beats perfection. Even if the problem feels tricky at first, spending time understanding it deeply always pays off. 📌 Every day I’m getting a little closer to becoming a better problem solver. Let’s keep going 💪 #Day56 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving #Cpp #LearnToCode #Consistency #GrowthMindset #Developers #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode 70 days in… and one thing is clear — consistency truly beats everything. Not every day is productive, not every problem feels easy, but showing up daily is what’s making the real difference. Today, I worked on the Word Search problem on LeetCode — a classic that revolves around DFS (Depth First Search) and Backtracking. At first glance, it looks simple, but once you start implementing it, you realize how important it is to think carefully about recursion and state management. 💡 Here’s what I focused on today: * Understanding how to traverse a 2D grid using DFS * Exploring all 4 directions (up, down, left, right) * Learning how to avoid revisiting the same cell * Applying the concept of backtracking (mark → explore → unmark) * Improving recursive thinking and debugging skills One key challenge was ensuring that once a cell is used in a path, it is temporarily marked and then restored correctly. This small detail makes a huge difference — and missing it can break the entire logic. 📌 Key Learnings: * Backtracking is not just about recursion, it’s about decision + undoing the decision * Breaking the problem into smaller steps makes complex problems manageable * Patience is as important as logic in DSA * Every mistake is actually helping me understand deeper Honestly, problems like these remind me that growth in coding is a gradual process. Some days feel smooth, others feel frustrating — but both are equally important. 🔥 What keeps me going? The idea that even if progress is slow, I am still moving forward. And that’s something to be proud of. 🎯 Next Goal: Strengthen more patterns like backtracking, recursion, and graph traversal — because these are game changers for interviews. Let’s keep building, learning, and improving — one day at a time 💪 #Day70 #100DaysOfCode #DSA #CodingJourney #LeetCode #Backtracking #DFS #Recursion #Programming #SoftwareEngineering #TechJourney #Consistency #GrowthMindset #KeepLearning
To view or add a comment, sign in
-
-
This might be the most underrated tool in the developer community right now. 🔥 You grind LeetCode daily. You push commits on GitHub. You solve problems on Codeforces. But nobody sees the FULL picture. Not even you. That changes with ScoreBook. 🎯 ScoreBook is a Developer Intelligence Platform that gives you ONE unified score across 9 major coding platforms — weighted by difficulty, prestige, and community quality. 📊 Platforms covered: Codeforces · LeetCode · GitHub · CodeChef · AtCoder · HackerRank · TopCoder · HackerEarth · GeeksForGeeks Here's what blew my mind: → Your score is calculated fairly — not just raw numbers, but weighted percentile ranking → You can see EXACTLY where you stand among every developer on the platform → Full breakdown per platform — no guesswork → Updates every 24 hours so your score stays fresh This is the kind of tool that top developers have been waiting for. If you're serious about your coding journey, stop flying blind. 🔗 www.scorebuk.com — connect your profiles, get ranked, own your score. built by Danish Belal Drop a comment if you check it out. Curious where everyone lands. 👇 #Developer #Coding #LeetCode #Codeforces #GitHub #CareerGrowth #SoftwareEngineering #Tech #BuildInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
Hey friends! Today on #TheAdventuresOfBlink, we have a working breakout game... but it's kinda boring. The ball bounces, the paddle moves, eh-- whatever. I think we need a little *excitement*... in the form of special bricks! Let's learn how to make our game have its first Power-Up! ...while you're reading this post... can you do me a favor and leave a 👍🏻 on the video for me? We gradually add new adventurers, but the algorithm needs a little prod to show the channel to more folks. Remember, this isn't just brain-candy. Learning to do these things by hand is even more important in the era of the #aipocalypse! Learn to do something yourself and experience the reward of learning a skill (instead of just telling Claude "you are an expert software engineer, now do my bidding"!) As per usual: 🔗 in 💬. Come and build with me! And if this type of thing is your jam, join up with the DevOps Society and be part of a community of builders who like the things you like, too! #python #buildinpublic #learning #programming #retro #zeroTokenArchitecture (s/o Kelsey Hightower, I love this phrase!)
To view or add a comment, sign in
-
400 down, many more to go. 📈 Reaching 400 problems on LeetCode has taught me that software engineering isn't just about writing code—it’s about how you approach a problem when you don't initially know the answer. The stats: ✅ 400 Total Solved ✅ 60.2% Acceptance Rate ✅ Beating 98.5% in consistency/speed The biggest takeaway? Discipline beats motivation every single time. #SoftwareDeveloper #TechMilestones #LeetCode #CodingCommunity #GrowthMindset
To view or add a comment, sign in
-
-
Most people see "500 LeetCode solved" and see a number. I see 500 times I choose not to give up. For a long time, I viewed coding challenges as a "test" I had to pass. If I couldn't solve a problem, I felt like a failure. But somewhere around the 200-question mark, something shifted. I stopped trying to be "smart" and started being "disciplined." This journey taught me three lessons that have nothing to do with syntax: 1. The Beauty of Being Wrong: Every "Wrong Answer" was just data. It wasn't a critique of my intelligence; it was a roadmap to a better solution. 2. The Power of Compounding: You don't become an engineer by solving one hard problem. You become one by solving "easy" problems until they become second nature, then moving the goalpost. 3. Resilience is a Muscle: The frustration of a bug is temporary. The pride of solving it is permanent. Reaching this milestone was a solo climb, but having a guiding light made all the difference in navigating the most complex peaks of this journey.A special thank you to Pragati Gupta Mam, Harshit Jain Sir, and Neeraj Kumar Bharti Sir for the constant support and direction throughout this journey. Your insights helped me turn the "grind" into a path of growth. Whether you are at problem #1 or #1000, remember: The goal isn't to solve the problem. The goal is to become the person who can solve it. #Leetcode #ProblemSolving #Coding #GalgotiasUniversity
To view or add a comment, sign in
-
-
350 problems on LeetCode — and the hardest part wasn’t solving them I recently crossed 350 problems on LeetCode. At the start, it felt like a numbers game. Solve more, get better. But somewhere along the way, that idea changed. Because the real progress wasn’t in the count—it was in how I started thinking. Sitting with a problem that made no sense, and choosing not to move on Debugging the same logic again and again until it finally clicked Realizing that most mistakes come from unclear thinking, not lack of knowledge Learning to stay patient when nothing seems to work There were days when even simple problems felt difficult. Days where progress felt invisible. But that’s the part no one talks about. Improvement in problem solving is slow. It’s subtle. You don’t notice it day to day—but one day, things just feel easier. Patterns start repeating—DP, graphs, sliding window, and more. Your approach becomes more structured. And problems that once felt impossible start to feel manageable. The biggest shift wasn’t in skill. It was in mindset. You stop chasing quick answers. You start trusting the process. 350 is just a checkpoint. But it taught me something I’ll carry forward: Progress doesn’t come from motivation. It comes from showing up—even when it feels like you’re getting nowhere. On to the next milestone. #LeetCode #DSA #ProblemSolving #Consistency #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Day 42/60 — LeetCode Discipline Problem Solved: Climbing Stairs Difficulty: Easy Today’s problem looked simple, but it carried a deeper pattern. At each step, we can climb either 1 or 2 stairs. The question becomes: how many distinct ways can we reach the top? 💡 Key Insight: This is a Dynamic Programming problem — where each step depends on the previous two steps. 👉 f(n) = f(n-1) + f(n-2) Which is nothing but the famous Fibonacci sequence. 💡 Key Learnings: • Recognizing DP patterns • Converting recursion into iteration • Space optimization using two variables • Building solutions from smaller subproblems ⚡ Performance: Runtime: 0 ms Like climbing a staircase… you don’t jump to the top— You build your way up, step by step, pattern by pattern. Consistency creates mastery. #leetcode #coding #programming #developer #softwareengineer #codinglife #coders #code #python #java #cpp #javascript #webdevelopment #machinelearning #ai #artificialintelligence #datascience #100daysofcode #60daysofcode #dsa #datastructures #algorithms #dynamicprogramming #dp #fibonacci #codingchallenge #dailycoding #problemsolving #codingjourney #tech #technology #developerlife #programmerlife #learncoding #codingcommunity #codersofinstagram #instacoder #techlife #devcommunity #softwaredeveloper #engineerlife #codingmotivation #growthmindset #consistency #nevergiveup #studentlife #btech #computerscience #aiml #futureengineer #placements #internship #careergoals #studygram #learning #keepgoing #successmindset #hustle #grind #explorepage #trending #viral #reels #linkedinpost #github #opensource LeetCode Google DSA CodeWithHarry GeeksforGeeks Microsoft Apple Netflix Programming.com Love Babbar
To view or add a comment, sign in
-
-
🚀 Day 14 of 180 — Container With Most Water ✅ The first time i got TLE. Then i thought again to solve this. LeetCode 11 — Container With Most Water Given an array where each element is a vertical line's height. Find two lines that together with the x-axis forms a container that holds the most water. My thought process: First attempt — O(n²): I took two pointers i and j = i+1, calculated area for every possible pair and stored the maximum. Simple but slow — got TLE on large inputs. So I took a hint and thought about it differently. Better approach — Two Pointers O(n): Place one pointer at the very start and one at the very end: i = 0 (left) j = n-1 (right) Calculate area at each step: width = j - i height = min(height[i], height[j]) area = width * height Now the key question — which pointer to move? The amount of water stored depends on the smaller height. The larger one doesn't matter because water will spill from the smaller side anyway. So — always move the pointer with the smaller height inward. Why? Because maybe ahead there's a taller line that can store more water. Moving the larger one inward makes no sense — it can only make things worse. Keep doing this until i < j — meaning until only a single length container remains. Example: height = [1, 8, 6, 2, 5, 4, 8, 3, 7] i=0 (h=1), j=8 (h=7) area = min(1,7) * 8 = 8 move i (smaller) → i=1 (h=8), j=8 (h=7) area = min(8,7) * 7 = 49 move j (smaller) → ... keep going max area = 49 ✅ Day 14 done. 166 to go. 🔥 #180DaysDSA #Day14 #LeetCode #Java #DSA #TwoPointers #Arrays #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
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