Path Crossing Problem
Path Crossing Problem — ExecCode Easy DSA Practice
Solve the Path Crossing problem on ExecCode. Free online easy DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. Your task is to compute the required answer and return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path. Return false otherwise.
Examples
Input {"path": "NES"}; Output False. Input {"path": "NESWW"}; Output True
Constraints
1 <= path.length <= 10^4 path[i] is either 'N', 'S', 'E', or 'W'.
Practice Path Crossing free on ExecCode. Browse DSA problems, topic map, and placement guides.