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.

&nbsp;
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.

&nbsp;
Constraints:


	1 &lt;= path.length &lt;= 104
	path[i] is either 'N', 'S', 'E', or 'W'.


class Solution:
    def isPathCrossing(self, path: str) -> bool:
        c = set()
        x,y = 0,0
        c.add((x,y))
        for i in path:
            if i == 'N':
                y+=1
            elif i == 'E':
                x+=1
            elif i == 'W':
                x-=1
            else:
                y-=1
            if (x,y) in c:
                return True
            else:
                c.add((x,y))
        return False
// Path crossing
// Leetcode

class Solution {
    public boolean isPathCrossing(String path) {
        Set<String> visited = new HashSet<>();
        int x = 0, y = 0;
        visited.add(x + "," + y);
        for (char c : path.toCharArray()) {
            if (c == 'N') y++;
            else if (c == 'S') y--;
            else if (c == 'E') x++;
            else x--;
            if (visited.contains(x + "," + y)) return true;
            visited.add(x + "," + y);
        }
        return false;       
    }
}
class Solution {
public:
    bool isPathCrossing(string path) {

        set<pair<int, int>>st;

        int x=0,y=0;

        st.insert({0, 0});

        for(int i=0;i<path.length();i++){

            if(path[i]=='N'){
                x++;
            }

            else if(path[i]=='S'){
                x--;
            }

            else if(path[i]=='E'){
                y++;
            }

            else{
                y--;
            }

            //if pair find at any point, return true
            if(st.find({x,y}) != st.end()){
                return 1;
            }
            //insert the pair
            st.insert({x, y});
        }
        return 0;
    }
};
var isPathCrossing = function(path) {
    let set = new Set();
    let curr = [0, 0]
    
    let start = `${curr[0]}, ${curr[1]}`
    set.add(start)
    
    for (let el of path) {
        if (el === 'N') curr[1]++;
        else if (el === 'S') curr[1]--;
        else if (el === 'E') curr[0]++;
        else curr[0]--;
        
        let key = `${curr[0]}, ${curr[1]}`
        if (set.has(key)) return true;
        set.add(key)
    }
    
    return false;
};
Path Crossing