Tap here to switch tabs
Problem
Submissions

Problem: Path Crossing

med
30 min
Try to solve the Path Crossing problem.

Statement

Given a string path, where each character represents a movement on a 22D plane:

  • 'N' moves 11 unit north to (x,y+1)(x, y + 1)

  • 'S' moves 11 unit south to (x,y−1)(x, y - 1)

  • 'E' moves 11 unit east to (x+1,y)(x + 1, y)

  • 'W' moves 11 unit west to (x−1,y)(x - 1, y)

You start at the origin (0,0)(0, 0) on a 22D plane and traverse the path specified by path.

Return true if the path crosses itself at any point (visiting any coordinate that has already been visited), and false otherwise.

Constraints:

  • 1≤1 \leq path.length ≤104\leq 10^4

  • path[i] is either 'N', 'S', 'E', or 'W'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Path Crossing

med
30 min
Try to solve the Path Crossing problem.

Statement

Given a string path, where each character represents a movement on a 22D plane:

  • 'N' moves 11 unit north to (x,y+1)(x, y + 1)

  • 'S' moves 11 unit south to (x,y−1)(x, y - 1)

  • 'E' moves 11 unit east to (x+1,y)(x + 1, y)

  • 'W' moves 11 unit west to (x−1,y)(x - 1, y)

You start at the origin (0,0)(0, 0) on a 22D plane and traverse the path specified by path.

Return true if the path crosses itself at any point (visiting any coordinate that has already been visited), and false otherwise.

Constraints:

  • 1≤1 \leq path.length ≤104\leq 10^4

  • path[i] is either 'N', 'S', 'E', or 'W'.