Company: HSBC_5sep
Difficulty: medium
Robot Path Validity Problem Description A robot starts at the origin (0,0) on a 2D grid. It is given a string moves which describes a sequence of movements. Each character in moves represents a single step: '^' : moves one unit up ( (x, y) to (x, y+1) ) 'v' : moves one unit down ( (x, y) to (x, y-1) ) ' : moves one unit left ( (x, y) to (x-1, y) ) '>' : moves one unit right ( (x, y) to (x+1, y) ) The robot's path is considered "valid" if it never visits the same grid point twice, with one specific exception: the starting point (0,0) may be revisited, but only as the very last point of the path, thereby forming a simple closed loop. Your task is to implement a function solution(moves) that returns true if the path described by moves is valid according to these rules, and false otherwise. Examples Example 1: Input: moves = "^>>v Explanation: Starting from (0,0) , the path is: (0,0) -> (0,1) -> (1,1) -> (2,1) -> (2,0) -> (1,0) -> (1,1) . The point (1,1) is visited twice (after the second