Self Crossing

Hard

Topics
ArrayMathGeometry

You start at the origin and move counter-clockwise: nums[0] north, nums[1] west, nums[2] south, nums[3] east, and so on. Given the distance array nums, return true if the path crosses itself, otherwise false.

Example 1

Input:  nums = [2,1,1,2]
Output: true

Example 2

Input:  nums = [1,2,3,4]
Output: false

Example 3

Input:  nums = [1,1,1,1]
Output: true

Constraints

  • 1 <= nums.length <= 8
  • 1 <= nums[i] <= 8
Run ⌘' · Submit ⌘⏎