Skip to main content
2 of 2
added 3 characters in body
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 41 37 bytes

62lYLt1=i:"YYw(t5Mf'<@{}'ot_h+)X<y=])

Input is 0-based.

Try it online!

Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372