Self Crossing

You are given an array of integers distance.

You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.

Return true if your path crosses itself or false if it does not.

Example 1
Inputdistance = [2,1,1,2]
Outputtrue
The path crosses itself at the point (0, 1).
Example 2
Inputdistance = [1,2,3,4]
Outputfalse
The path does not cross itself at any point.

Constraints

  • 1 <= distance.length <= 10^5
  • 1 <= distance[i] <= 10^5

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate