Robot Returns to Origin LeetCode Challenge

✅ Day 93 of 100 Days LeetCode Challenge Problem: 🔹 #657 – Robot Return to Origin 🔗 https://lnkd.in/gfZBi3XR Learning Journey: 🔹 Today’s problem involved tracking movements of a robot on a 2D plane. 🔹 I used a dictionary to map each move to its coordinate change: • 'U' → +1 (y-axis) • 'D' → -1 (y-axis) • 'R' → +1 (x-axis) • 'L' → -1 (x-axis) 🔹 Maintained a coordinate array ans = [0, 0] representing (x, y). 🔹 Iterated through each move and updated the respective axis. 🔹 Finally checked whether the robot returned to the origin [0, 0]. Concepts Used: 🔹 Coordinate Simulation 🔹 HashMap / Dictionary 🔹 String Traversal Key Insight: 🔹 The robot returns to origin only if horizontal and vertical movements cancel out. 🔹 Net displacement in both x and y directions must be zero. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories