Skip to main content
1 of 5
user
  • 387
  • 2
  • 21
  • 68

APL (Dyalog Unicode), 22 bytes

∊({⍵+⍳≢⍵}¨⊢⊆⍨⊢+1+∘|⌊/)

Try it online!

I was hoping for an extremely short answer using , but it doesn't allow negative numbers (on the left). Explanation coming.

user
  • 387
  • 2
  • 21
  • 68