Robot Return to Origin

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
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 i<sup>th</sup> 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.
LeetCode Problem - 657
class Solution {
public boolean judgeCircle(String moves) {
// Initialize variables to track the robot's position on a 2D grid
int x = 0, y = 0;
// Iterate through each move in the string
for (char c : moves.toCharArray()) {
// If the move is 'R' (right), increment the x-coordinate
if (c == 'R') x++;
// If the move is 'L' (left), decrement the x-coordinate
else if (c == 'L') x--;
// If the move is 'U' (up), increment the y-coordinate
if (c == 'U') y++;
// If the move is 'D' (down), decrement the y-coordinate
else if (c == 'D') y--;
}
// After processing all moves, check if the robot is back at the origin (0,0)
if (x == 0 && y == 0) return true; // Robot returned to the starting point
return false; // Robot did not return to the starting point
}
}




