🔥 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
Solving Walking Robot Simulation with Hashing and Direction Management
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 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
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
-
-
#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 36 of 100 Days LeetCode Challenge Problem: Robot Return to Origin Day 36 is a simple but important simulation + counting problem 🔥 💡 Key Insight: To return to origin (0,0): Total moves Right = Left Total moves Up = Down 👉 If both conditions satisfy → ✅ robot returns to origin 🔍 Core Approach: 1️⃣ Initialize Counters x = 0, y = 0 2️⃣ Process Each Move 'R' → x++ 'L' → x-- 'U' → y++ 'D' → y-- 3️⃣ Final Check If (x == 0 && y == 0) → true Else → false 💡 Alternative Approach: Count occurrences: count('R') == count('L') count('U') == count('D') 🔥 What I Learned Today: Simple problems test basic logic clarity Simulation problems are about correct tracking Don’t overcomplicate—keep it clean 📈 Challenge Progress: Day 36/100 ✅ Consistency still going strong! LeetCode, Simulation, Strings, Counting, Coordinates, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Simulation #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 22 of 100 Days LeetCode Challenge Problem: Determine Whether Matrix Can Be Obtained By Rotation Day 22 is a classic matrix rotation + simulation problem 🔥 💡 Key Insight: We can rotate the matrix in 90° steps (up to 4 times): 90° 180° 270° 360° (back to original) 👉 If at any step mat == target → ✅ True 🔍 Core Approach: 1️⃣ Rotate Matrix (90° Clockwise) Transpose the matrix Reverse each row 👉 This gives one 90° rotation 2️⃣ Repeat Rotation 4 Times After each rotation: Compare with target 👉 If match found → return true 👉 Else after 4 rotations → false 💡 Optimization: Early exit when match is found Avoid unnecessary rotations 🔥 What I Learned Today: Matrix rotation is a standard pattern Simulation problems require step-by-step accuracy Reusing logic reduces complexity 📈 Challenge Progress: Day 22/100 ✅ Staying consistent & sharp! LeetCode, Matrix, Rotation, Simulation, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #Rotation #Simulation #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
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
-
-
𝐃𝐚𝐲 𝟕𝟕/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐑𝐨𝐛𝐨𝐭 𝐑𝐞𝐭𝐮𝐫𝐧 𝐭𝐨 𝐎𝐫𝐢𝐠𝐢𝐧 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Simulate the robot’s movement using coordinates (x, y): R → x++, L → x-- U → y++, D → y-- Finally, check if the robot returns to (0, 0). 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Simulation using coordinate tracking. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝟏) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Simple simulation problems strengthen fundamentals and improve clarity in handling movement-based logic. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #Simulation #Strings #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
Day 93: Optimization > Completion 📉 Problem 3661: Maximum Walls Destroyed by Robots Today was a massive lesson in efficiency. I initially cleared all test cases with a Memoization + Binary Search approach, but at O(N²), I knew it wasn't the most optimal way to handle the constraints. I decided to dig deeper and refactor the entire logic into a cleaner Dynamic Programming solution. The Strategy Shift: • The O(N²) Trap: My first pass worked, but nested recursion with memoization can get heavy. I wanted to see if I could solve it in a single linear pass. • State Transition: I moved to a DP approach using subLeft and subRight to track the maximum walls destroyed up to each robot. • Precision Boundary Logic: By pre-calculating the left and right firing ranges for each robot using Binary Search (lowerBound/upperBound), I could transition states in O(N) time. I’m honestly not proud of my initial approach today. It felt a bit like forcing a solution rather than finding the most elegant one. Pushing myself to find the O(N) path when I already had a working "Pass" was the real challenge, but it’s where the growth happens. We go again tomorrow. 🚀 #LeetCode #Java #DynamicProgramming #BinarySearch #Algorithms #DailyCode
To view or add a comment, sign in
-
𝐃𝐚𝐲 𝟕𝟖/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐖𝐚𝐥𝐤𝐢𝐧𝐠 𝐑𝐨𝐛𝐨𝐭 𝐒𝐢𝐦𝐮𝐥𝐚𝐭𝐢𝐨𝐧 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Track robot movement using (x, y) coordinates. Maintain direction using an index (North, East, South, West). Store obstacles in a HashSet for fast lookup. Move step-by-step and stop if an obstacle is encountered. Track maximum Euclidean distance squared from origin. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Simulation + HashSet for obstacle detection. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧 × 𝐦) (worst case step simulation) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐤) (for storing obstacles) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Using HashSet for obstacle detection converts costly lookups into O(1), making simulation efficient. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #Simulation #Hashing #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
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