A drawing app records a mouse drag as a string path of unit moves on a grid: N (y + 1), S (y - 1), E (x + 1), and W (x - 1). The drag starts at (0, 0).
Write pathCrosses(path) that returns true if the drag ever visits the same point twice (including the starting point), and false otherwise.
Input: path = "NESW" Output: true
The last move comes back to (0, 0).
Input: path = "NES" Output: false
The points (0, 1), (1, 1), and (1, 0) are all new.
0 <= path.length <= 10^5path has only N, S, E, W.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #26 Drag Path Crosses Itself. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.