🚀 Day 553 of #750DaysOfCode 🚀 🤖 LeetCode 657: Robot Return to Origin Today’s problem was simple yet a great reminder of how powerful basic logic can be. 📌 Problem Summary: A robot starts at (0,0) and follows a sequence of moves: 'U' → Up 'D' → Down 'L' → Left 'R' → Right 👉 Goal: Check whether the robot returns back to the origin after all moves. 💡 Approach: Instead of overthinking, I focused on tracking movement on axes: Vertical → U cancels D Horizontal → L cancels R If both balances are zero → back to origin ✅ 🧠 Key Insight: This problem is not about simulation, but about balance. ⚡ Complexity: Time → O(n) Space → O(1) 🎯 Takeaway: Even easy problems strengthen your fundamentals. Consistency > Complexity 💯 🔥 553 days down, 197 to go! Let’s keep building 🚀 #LeetCode #Java #DSA #CodingJourney #Consistency #ProblemSolving #Developers #100DaysOfCode #Tech
Robot Returns to Origin: LeetCode 657
More Relevant Posts
-
🚀 Day 555 of #750DaysOfCode 🚀 🧠 Today’s Problem: Walking Robot Simulation II (LeetCode - Medium) This problem was all about simulation + optimization. At first glance, it looks like a simple movement problem, but the tricky part is handling direction changes at boundaries efficiently. 💡 Key Insights: The robot moves along the perimeter of the grid. Instead of simulating every step (which could be up to 10⁵), we optimize using: 👉 perimeter = 2*(width - 1) + 2*(height - 1) We reduce steps using modulo: 👉 num %= perimeter Then simulate movement in chunks based on current direction. ⚙️ What I implemented: Maintained (x, y) position and current direction Handled boundary collisions → turn 90° counterclockwise Efficient movement without iterating step-by-step 🔥 Learning Takeaways: Simulation problems often hide optimization opportunities Always look for patterns (like cycles/perimeters) Clean direction handling makes logic much easier 💻 Tech Used: Java, OOP, Simulation Logic Consistency > Motivation. Showing up every day 💪 #LeetCode #Java #ProblemSolving #DataStructures #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
💡Day 46 of LeetCode Problem Solved! 🔧 🌟657. Robot Return to Origin🌟 🔗 Solution Code: https://lnkd.in/gffUSuzJ Task : • There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. • You are given a string moves that represents the move sequence of the robot where moves[i] represents its ith move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down). • Return true if the robot returns to the origin after it finishes all of its moves, or false otherwise. • Note: The way that the robot is "facing" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move. Example 1: Input: moves = "UD" Output: true Explanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true. Example 2: Input: moves = "LL" Output: false Explanation: The robot moves left twice. It ends up two "moves" to the left of the origin. We return false because it is not at the origin at the end of its moves. #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
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
-
-
#Day359 of #1001DaysOfCode 📘 LeetCode Daily Challenge Problem: Walking Robot Simulation (LeetCode 874) 💡 Approach: Simulated the robot’s movement step-by-step while tracking direction changes. Used a HashSet to store obstacle positions for O(1) lookup, ensuring the robot stops correctly when encountering obstacles. Updated the maximum distance from origin after each move. ⏱ Time Complexity: O(n + k) 🧠 Space Complexity: O(m) Staying consistent and improving problem-solving skills every day 🚀 #DSA #Java #LeetCode #ProblemSolving #Coding
To view or add a comment, sign in
-
-
🚀 Day 550 of #750DaysOfCode 🚀 💡 Problem Solved: Maximum Amount of Money Robot Can Earn Today’s problem was a great example of how Dynamic Programming + smart decision-making can turn a complex problem into a structured solution. 🧠 Problem Insight: A robot moves from the top-left to the bottom-right of a grid, collecting coins along the way. Positive values → gain coins 💰 Negative values → lose coins due to robbers 🥷 But here’s the twist: 👉 The robot can neutralize robbers up to 2 times ⚙️ Approach I Used: Instead of just tracking position, I added an extra dimension: Number of neutralizations used (0, 1, or 2) So for every cell, I tracked the maximum coins possible under each scenario. At each step, I had two choices: Take the value (gain or loss) If it’s negative → optionally neutralize (if power remains) This turns the problem into a state-based DP, where each decision impacts future outcomes. 🔥 What Made This Interesting: It’s not just about maximizing sum It’s about when to use limited resources Greedy won’t work — you must think ahead 👉 Sometimes taking a small loss now helps you avoid a bigger loss later. 📈 Complexity: Time: O(n × m) Space: O(n × m × 3) 💬 Key Takeaway: This problem reinforced an important lesson: When constraints are limited (like 2 neutralizations), always consider adding them as a DP state. ✅ Day 550 done — staying consistent and leveling up every day 🚀 #DSA #DynamicProgramming #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #Tech #SoftwareEngineering #750DaysOfCode
To view or add a comment, sign in
-
-
Solved a basic but interesting problem: Robot Return to Origin 🤖 In this problem, a robot moves based on given directions (Up, Down, Left, Right). The goal is to check whether the robot comes back to the starting point (0,0) after completing all moves. 👉 Approach: I tracked the movement using x and y coordinates. Left/Right affects x Up/Down affects y If both x and y become 0 at the end, it means the robot returned to origin. Simple logic, but a good reminder that strong basics are very important 💡 #LeetCode #DSA #ProblemSolving #CodingJourney #Java #Stack #Algorithms #Consistency #Learning #Tech
To view or add a comment, sign in
-
-
#Day358 of #1001DaysOfCode 📘 LeetCode Daily Challenge Problem: Robot Return to Origin (LeetCode 657) 💡 Approach: Simulated the robot’s movement on a 2D plane by tracking vertical and horizontal positions. Each move updates the position, and if the robot returns to (0,0), it means all movements are balanced. ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(1) Consistency is key — one problem every day 🚀 #DSA #Java #LeetCode #ProblemSolving #Coding
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode – Day 10 Consistency is kicking in. Small wins adding up 🔥 ✅ What I accomplished today: 🧠 LeetCode Problem – Robot Collisions 📌 Problem Overview: Given robots with positions, health, and directions (L or R), simulate collisions: Robots moving toward each other collide The robot with lower health gets destroyed If equal → both destroyed Survivors continue moving 💡 My Approach (Sorting + Stack Simulation): 🔹 Sorted robots based on positions to process collisions in order 🔹 Used a stack to track right-moving robots 🔹 When a left-moving robot appears → simulate collisions with stack top 🔹 Carefully handled 3 cases: ✔ Smaller health → robot destroyed ✔ Greater health → reduce health & continue ✔ Equal health → both destroyed 🔹 Stored original indices to return result in correct order ⚡ Time Complexity: O(n log n) (sorting + single pass) ⚡ Space Complexity: O(n) 🧩 Key Insight: This problem helped me understand: ✔ How to convert simulation problems into stack-based solutions ✔ Importance of sorting before processing interactions ✔ Handling multiple collision scenarios cleanly ✔ Writing state-driven logic without brute force 🔗 LeetCode Submission Link: https://lnkd.in/gKGk8GFM ☕ Spring Boot Learning – Revision + Concepts 🔹 Revised all previously learned concepts to strengthen fundamentals 🔹 Learned the difference between: 📌 PUT vs PATCH ✔ PUT → Updates the entire resource (full replacement) ✔ PATCH → Updates only specific fields (partial update) 📌 H2 Database (In-Memory DB): ✔ Runs in memory → data is lost after application restart ✔ Useful for testing & development ✔ Not suitable for persistent production data 📌 Key Takeaways: ✔ Use PUT when updating full objects ✔ Use PATCH for partial updates (better performance) ✔ H2 is great for testing, but not for long-term storage ✔ Revision is as important as learning new things 📝 Spring Boot Notes: https://lnkd.in/gNZWz96m 🔥 Learning Streak: Day 10/100 Double digits now. Staying consistent 💪 #100DaysOfCode #Java #SpringBoot #BackendDevelopment #LeetCode #DSA #CodingJourney #ProblemSolving #SoftwareDevelopment #LearningInPublic #Developers #Consistency #BuildInPublic
To view or add a comment, sign in
-
-
This weekend, I used Claude in VS Code to refactor 4,000 lines of C code into separate files. It took 5 minutes, but also snuck in 6 subtle bugs that took a full day to track down. Without AI: probably a week of work, probably more bugs. With AI: 5 minutes of coding, one day of debugging. But here's the new reality: we can now crank out more code than we can possibly review and debug. That's a new kind of risk that our engineering processes weren't designed for. Speed is no longer the constraint. Comprehension is. #AI #SoftwareEngineering #CTO #DeveloperTools
To view or add a comment, sign in
-
🚀 Day 32 of #LeetCode Journey ✅ Problem: Robot Return to Origin (LeetCode 657) Today’s problem was simple yet a great way to strengthen basic logic and coordinate tracking skills. 🔍 Problem Statement: Given a string of moves (U, D, L, R), determine if the robot returns to the origin after completing all moves. 💡 Approach: * Start from position (0,0) * Track horizontal (x) and vertical (y) movements * Update position based on each move * Finally, check if we are back at (0,0) 🧠 Key Insight: Equal number of opposite moves cancel each other out: * U cancels D * L cancels R ⏱️ Complexity: Time: O(n) Space: O(1) 📌 Takeaway: Even simple problems help build strong fundamentals in problem-solving and coding logic. #Java #LeetCode #CodingJourney #100DaysOfCode #Programming #Developer
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