Stores visited segments
HashSet < string > s = new HashSet < string > ( ) ; for ( int i = 0 ; i < path . Length ; i ++ ) { int p = x ; int q = y ; if ( path [ i ] == ' N ' ) y ++ ; else if ( path [ i ] == ' S ' ) y -- ; else if ( path [ i ] == ' E ' ) x ++ ; else if ( path [ i ] == ' W ' ) x -- ;