Question: Goldman Sachs, Recent Online Assessment Questions (21st August 2023) | Better Compression | Encircular
2
Entering edit mode

ADD COMMENTlink 15 months ago Delta 2.9k
0
Entering edit mode

Any idea on how to solve Q2 ????
Here is my idea , but not an absolute answer 

 

Make a int state for direction , directions are u r d l , 0 1 2 3 , then turning right is (dir++)%4 and turning left is (dir--)%4 . make 2 integers x and y and 2 vectors to store the path traversed . do the traversal over the string again and again until we reach the starting point again . then do traversal again and store in another set of vectors . then compare the 2 vectors . If they are equal then the robot does move in a circle .

However this solution will get stuck when the robot dosent move in a circle

Maybe count the number of r and l in the string , if either is 0 then … no even this is not an absolute solution

Maybe execute few cycles of it and keep counting the number of movements to left right up or down

ADD COMMENTlink 15 months ago Ayush Agarwal • 20

Login before adding your answer.

Similar Posts
Loading Similar Posts