Can anyone of you take a look at my code and help me fix it? I saw other codes, the logic was similar. But I failed somewhere in implementation. This problem got me like “WHY ARE YOU NOT SOLVING WTFFF” quite badly, so I will appreciate if you guys can help me fix my code.(Meaning, I don’t want to know the answer, I want to see where I failed in my approach and how could I fix it to be correct.)
Thanks in advance
My logic involved on checking at every step what the command is, modifying the change in vertical and/or horizontal direction accordingly. In case the ABSOLUTE change in vertical/horizontal direction proved greater than the limits n and m, the loop stops and prints “unsafe”.
A corner case was seen that-
Let n=2 and m=3. Let command be LLRRR. The “change” in horizontal is reported to be 1, and it will print safe. However, it is not the case.
Hence another 2 counters were set to record contiguous command changes. If a command in same direction occurred more times than the dimensions could accommodate, it would break out of loop and print “unsafe”