Day 61/100 of #100DaysOfCode Today I worked on a basic string problem and also explored a higher-level problem related to optimization. First, I solved a string problem: removing spaces from a given string. Initially, it felt simple, but while coding I understood the importance of clear thinking. Key learning: Focus on characters we want to keep Traverse the string using a loop Build a new result string without spaces Example: Input: "geeks for geeks" Output: "geeksforgeeks" This strengthened my understanding of how to convert logic into code step-by-step. Along with this, I also looked at a more advanced problem involving robots and factories. Even though I didn’t fully implement it, I understood the core idea: Robots are placed on a line and need to reach factories Each factory has a limit on how many robots it can repair The goal is to assign robots to factories such that the total distance traveled is minimum The approach involves: Thinking in terms of assigning closest possible robots Considering constraints like factory limits Understanding that sometimes simple greedy logic is not enough Learning that advanced techniques like sorting and dynamic programming are used to find the optimal solution This made me realize how problems can evolve from simple logic to complex optimization, and how important it is to build a strong foundation before jumping into advanced topics. Still learning, still improving — one concept at a time. #coding #dsa #learning #100daysofcode
Surinder Kumar’s Post
More Relevant Posts
-
🔥 LeetCode Hard Problem Breakdown — Maximum Walls Destroyed by Robots Recently, I worked on a really challenging problem that completely changed how I think about greedy vs dynamic programming. 🧩 Problem Summary (Simple Words) You are given: 🤖 Robots placed on a number line 🧱 Walls placed on the same line Each robot has a shooting distance Each robot can: Shoot LEFT ⬅️ or RIGHT ➡️ (only once) Destroy all walls in that range BUT ❌ bullet stops if another robot comes in between 👉 Goal: Destroy maximum UNIQUE walls 🚨 Initial Thought (Where Most Go Wrong) At first, it feels like: “For each robot, choose the direction that destroys more walls.” ❌ This greedy approach fails Because: Robots can destroy overlapping walls Decisions of one robot affect others 💡 Key Insight This is NOT an independent decision problem. 👉 It’s a global optimization problem 👉 Requires Dynamic Programming (DP) 🧠 Approach Breakdown Step 1: Preprocessing Sort robots and walls Maintain mapping of robot → distance Step 2: For each robot, calculate: left[i] → walls destroyed if robot shoots LEFT right[i] → walls destroyed if robot shoots RIGHT num[i] → walls between robot[i-1] and robot[i] (overlap region) Step 3: DP State We maintain: subLeft → max walls till i if current robot shoots LEFT subRight → max walls till i if current robot shoots RIGHT Step 4: Transition currentLeft = max( subLeft + left[i], subRight - right[i-1] + min(left[i] + right[i-1], num[i]) ); currentRight = max( subLeft + right[i], subRight + right[i] ); 👉 The tricky part is handling overlap correctly 🎯 Key Learning 👉 If decisions: overlap affect each other Then: Greedy ❌ DP ✅ 🚀 Final Thoughts: This problem taught me. Don’t trust the greedy blindly. Always think about overlapping effects. DP often hides behind “simple-looking” problems.. 💬 Would love to hear: Have you faced similar problems where greedy failed? #DSA #LeetCode #DynamicProgramming #Java #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 95 Today’s problem: Robot Return to Origin (Easy) A simple yet insightful problem focused on movement tracking and coordinate logic. The idea is straightforward — simulate the robot’s moves and check whether it ends up back at the origin (0,0). 💡 Key Takeaways: Maintain two variables (x, y) to track position Each move updates coordinates accordingly Final check: if (x == 0 && y == 0), the robot returns to origin ✅ Clean logic > overthinking ⚡ Result: Accepted ✅ ⏱ Runtime: 0 ms (100% 💯) 📊 Memory: Room for improvement Even the “easy” problems reinforce fundamentals — and strong fundamentals win interviews. Consistency is the real game. On to Day 96 💪 #LeetCode #Programming #DSA #CodingJourney #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🧠 Problem: Leetcode 2463: Minimum Total Distance Traveled Today I solved a challenging Dynamic Programming + Greedy Sorting problem that focuses on optimizing distance between robots and factories. 💡 Problem Understanding We are given: A list of robots' positions A list of factories, where each factory has: Position Capacity (how many robots it can repair) 🎯 Goal: Assign robots to factories such that the total travel distance is minimized ⚙️ Approach Used 🔹 Step 1: Sorting Sort robots → ensures we process in order Sort factories by position → helps assign nearest robots 🔹 Step 2: DP Definition We use a 2D DP array: dp[i][j] = minimum distance to fix first i robots using first j factories 🔹 Step 3: Base Case dp[0][j] = 0 → No robots = No distance Initialize rest with large value (∞) 🔹 Step 4: Transition Logic For each factory: Either: 👉 Skip the factory 👉 Use it to repair k robots (within its limit) We calculate distance incrementally: Assign closest robots to current factory Keep updating minimum cost 🔁 Core Idea Instead of trying all combinations blindly, we efficiently group robots to nearest factories using DP 🧮 Time Complexity Roughly: O(R × F × Limit) Where: R = robots F = factories 🔥 Key Learning Sorting + DP = Powerful combo Breaking problem into subproblems (i, j) makes it manageable Always think: "Take or Skip" in DP #DP #Leetcode #DSA #Java #Programming
To view or add a comment, sign in
-
-
🚀 Day 214 of #300DaysOfCoding Today I solved a Hard-level problem on LeetCode: 👉 Minimum Total Distance Traveled This problem really tested my understanding of Dynamic Programming + Greedy Thinking. 💡 Key Learnings: Sorting plays a crucial role in optimizing 1D distance problems Converting real-world constraints into DP states makes complex problems manageable Handling capacity constraints (factories limit) using iterative assignment 🧠 Approach: Sorted robots and factories based on position Used DP + Memoization to assign robots to factories efficiently Tried multiple assignments per factory within capacity limits ⚡ Why this problem is interesting? It combines: Greedy intuition (nearest assignment) Dynamic Programming (optimal substructure) Real-world modeling (capacity constraints) 📊 Complexity: Time: O(n × m × limit) Space: O(n × m) 🔥 Problems like this improve problem-solving depth and prepare you for top product-based companies. #LeetCode #DSA #DynamicProgramming #CodingJourney #ProblemSolving #SoftwareEngineering #MCA #GATEPreparation
To view or add a comment, sign in
-
-
#100DaysOfLeetcode journey 🚀 Day 65/100 — Extending the Streak with Advanced DP! Today’s Problem: 2463. Minimum Total Distance Traveled (Hard) 🔹 The Goal: We have robots and factories at various positions on a 1D axis. Each factory has a specific capacity limit. We need to set directions for the robots to minimize the total distance traveled until all robots are repaired. 🔹 The Insight: This problem is a masterclass in Contiguous Assignment. By sorting both the robots and the factories, we unlock a critical property: in an optimal solution, if robot A is to the left of robot B, robot A will be repaired by a factory that is at or to the left of the factory repairing robot B. This transformation allows us to use Dynamic Programming. 🔹 The Logic: State Definition: I used a 2D DP table where dp[i][j] represents the minimum cost to repair the first j robots using the first i factories. Transition: For each factory, we "try" repairing anywhere from 0 up to its maximum capacity. We calculate the cost for that specific cluster of robots and add it to the best result from the previous factories. Complexity: By processing the factory-robot pairs in sorted order, we achieve an $O(M \cdot N \cdot \text{Limit})$ solution that handles large-scale coordinate systems effectively. ✨ Achievement: Day 65! Even after crossing the two-thirds mark, the curiosity to solve high-complexity "Hard" problems continues. Moving from simple simulations into optimization problems that require proving mathematical invariants is what keeps the journey exciting. 🔍 Steps followed: ✔ Dual Sorting: Normalized positions for both agents to enable segment-based DP. ✔ Clustering Logic: Implemented a nested loop to evaluate every possible capacity usage per factory. ✔ Overflow Prevention: Managed large distance sums using long primitives and a safe infinity bound. 🔧 Complexity Analysis: Time Complexity: $O(M \times N \times \text{Limit})$ Space Complexity: $O(M \times N)$ 65 days down! Let’s see how much further we can push the logic as we enter the final third of the challenge! 🛠️ #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #SoftwareEngineer #InternshipBound #Programming #DynamicProgramming #Optimization #Algorithms #Day65
To view or add a comment, sign in
-
-
Today, I tackled a challenging DSA problem titled “Maximum Walls Destroyed by Robots.” This problem involved several key concepts: - Sorting - Binary Search (lower_bound / upper_bound) - Greedy + Dynamic Programming The core idea revolves around each robot having a specific range, with the objective of maximizing the number of walls covered while avoiding overlap conflicts between adjacent robots. Here’s what I implemented: - Utilized unordered_map to map each robot to its distance. - Applied binary search to efficiently determine reachable walls. - Maintained prefix decisions using Dynamic Programming: - subLeft: best result when the current robot contributes from the left - subRight: best result when the current robot contributes from the right A key learning from this experience was that optimizing overlapping ranges with constraints requires a combination of: - Local decisions for each robot's coverage - Global optimization through DP transitions This problem truly tested my ability to think in intervals, handle edge cases between adjacent elements, and optimize using the Standard Template Library effectively. Consistency and problem-solving lead to growth. #DSA #Coding #Cpp #LeetCode #ProblemSolving #SoftwareEngineering #FAANGPrep #POTD
To view or add a comment, sign in
-
-
🚀 Day 12 of Learning DSA Today was all about mastering 2D Arrays (Matrix Problems) — and honestly, this felt like leveling up 🔥 Instead of just coding, I focused on understanding patterns, logic, and edge cases behind these problems 👇 🌀 1. Spiral Traversal of Matrix Learned how to print elements in a spiral order using boundary shrinking technique 💡 Key Concepts: Using 4 pointers: top, bottom, left, right Traversal order: ➡️ ⬇️ ⬅️ ⬆️ Importance of conditions to avoid duplicate traversal 👉 Biggest takeaway: Matrix problems are more about visual thinking than coding 🔄 2. Rotate Matrix by 90° (In-place) Understood how to rotate a matrix without using extra space 💡 Key Concepts: Transpose (swap rows & columns) Then reverse rows (clockwise) OR reverse columns (anti-clockwise) Why this works mathematically 👉 Biggest takeaway: Complex problems often reduce to simple transformations 🔁 3. Transpose of Matrix The foundation behind rotation and many matrix problems 💡 Key Concepts: Swapping matrix[i][j] with matrix[j][i] Avoiding double swaps using j = i Importance of index control 👉 Biggest takeaway: Small mistakes in indexing can completely break logic 🧠 What I Really Learned Today Most matrix problems = pattern recognition + boundary control Writing code is easy, avoiding edge-case bugs is hard Dry run + visualization = game changer 💪 Moving Forward #DSA #LearningInPublic #180DaysOfCode #CodingJourney #DataStructures #ProblemSolving #MatadeenYadav #matadeenyadav
To view or add a comment, sign in
-
-
🔥 Day 551 of #750DaysOfCode 🔥 🚧 LeetCode 3661: Maximum Walls Destroyed by Robots (Hard) Today’s problem was a great mix of greedy thinking + binary search + DP optimization 🤯 🧠 Problem Insight We are given: Robots with positions & shooting distances Walls on a number line Each robot can shoot left or right, but: 👉 Bullets stop if they hit another robot 👉 Goal is to maximize unique walls destroyed 💡 Key Challenges Choosing left vs right direction optimally Avoiding overlapping counts of walls Handling blocking by neighboring robots Ensuring maximum unique destruction ⚙️ Approach Breakdown ✅ Step 1: Sort robots & walls 👉 Makes range queries possible ✅ Step 2: Use Binary Search (lowerBound / upperBound) 👉 Efficiently count walls in range ✅ Step 3: Precompute: left[i] → walls destroyed if robot shoots left right[i] → walls destroyed if robot shoots right num[i] → overlapping walls between robots ✅ Step 4: Apply Dynamic Programming Maintain: subLeft → max walls if current robot shoots left subRight → max walls if current robot shoots right 👉 Transition carefully avoids double counting ⏱ Complexity Sorting: O(n log n) Binary Search per robot: O(log n) DP traversal: O(n) 👉 Overall: O(n log n) 🧠 What I Learned How to combine Binary Search + DP Handling interval overlaps smartly Thinking in terms of choices per index (left/right) Writing clean helper functions (lowerBound, upperBound) 📌 Takeaway Hard problems are not about complex code, they’re about breaking constraints into structured decisions. #LeetCode #DataStructures #Algorithms #CodingChallenge #Java #ProblemSolving #100DaysOfCode #SoftwareEngineering #DSA #750DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 554 of #750DaysofCode 🔥 🚀 Problem Solved: Walking Robot Simulation Today’s problem tested my simulation + hashing skills in a really interesting way! 🤖 What I implemented: I simulated the robot’s movement step-by-step on an infinite grid while handling obstacles efficiently. 💡 Instead of using complex structures, I used: 👉 HashSet to store blocked positions 👉 Direction array to manage movement (N, E, S, W) 🧠 Core Idea: Maintain current direction using an index Rotate: Right → (dir + 1) % 4 Left → (dir + 3) % 4 Move one step at a time (very important 🚨) Before every step: Check if next position is blocked If yes → stop moving for that command ⚡ Key Insight: 👉 You cannot jump directly k steps 👉 You MUST move step-by-step to correctly detect obstacles 💻 My Approach: ✔️ Stored obstacles as "x,y" in HashSet ✔️ Used direction vector: North → (0,1) East → (1,0) South → (0,-1) West → (-1,0) ✔️ Tracked max distance using: 👉 x² + y² 📈 Complexity: Time: O(N + total steps) Space: O(M) for obstacles 🎯 What I learned: Simulation problems require careful step execution Hashing makes obstacle lookup super fast Small implementation details can make or break the solution 💬 Honestly, this problem looks easy at first, but handling directions + obstacles correctly makes it a great practice problem! #Day554 #750DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #Developers #Tech
To view or add a comment, sign in
-
-
Hi Everyone, Installing ROS + Blender just to validate a URDF? That’s hours of setup… for a basic check. So I built a simpler way 👇 ⚡ Validate robot models instantly ⚡ No heavy dependencies ⚡ Works in CI/CD pipelines Less setup. More building. Free, no sign in, Try it now: https://lnkd.in/gmvRQmZE What’s one thing you’d improve in robotics workflows? #Robotics #ROS #RobotOperatingSystem #RoboticsEngineering #Automation #AI #Developers #Software Engineering #Cloud Computing #APIS #DevTools #Startup #Open Source #GitHub #Python #DevOps #CICD #Simulation #3DModeling #Engineering Tools #Deep Tech #RoboticsStartup #TechInnovation #BuildIn Public #IndieHacker #SaaS
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