Path Crossing Problem
Description
LeetCode Problem 1496.
Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.
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. Return false otherwise.
Example 1:

Input: path = "NES"
Output: false
Explanation: Notice that the path doesn't cross any point more than once.
Example 2:

Input: path = "NESWW"
Output: true
Explanation: Notice that the path visits the origin twice.
Constraints:
1 <= path.length <= 10^4path[i]is either'N','S','E', or'W'.
Solution
Approach: Hash Set of Visited Points
Walk the path one step at a time and keep every point we have stood on in a hash set, starting with the origin (0, 0). After each move, if the new point is already in the set, the path crosses itself; otherwise add it and go on. If the walk ends without a repeat, return false.
Remember to put the origin in the set before the first step: in "NESW" the only repeated point is the start, and it must count.
To use a plain integer set, a point can be packed into one key such as x * 100000 + y. This is unique because the path has at most 104 steps, so |x| and |y| never exceed 104.
Complexity: O(n) time and O(n) space for the visited points, where n is the length of path.
class Solution:
def isPathCrossing(self, path: str) -> bool:
step = {"N": (0, 1), "S": (0, -1), "E": (1, 0), "W": (-1, 0)}
x = y = 0
visited = {(0, 0)}
for c in path:
dx, dy = step[c]
x += dx
y += dy
if (x, y) in visited:
return True
visited.add((x, y))
return False