Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access