Does robot moves circular
Easy Accuracy: 45.01% Submissions: 1582 Points: 2

Given a sequence of moves for a robot. Check if the sequence is circular or not.

A sequence of moves is circular if the first and last positions of the robot are the same. A move can be one of the following :
    G - Go one unit
    L - Turn left
    R - Turn right

Example 1:

Input: path = "GLGLGLG"
Output: "Circular"
Explanation: If we start form 
(0,0) in a plane then we will 
back to (0,0) by the end of the 

​Example 2:

Input: path = "GGGGL"
Output: "Not Circular"
Explanation: We can't return to 
same place at the end of the path.

Your Task:  
You don't need to read input or print anything. Your task is to complete the function isCircular() which takes the string path as input and returns "Circular" if the path is circular else returns "Not Circular".

Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(1)

1 ≤ |S| ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Does robot moves circular

Output Window