Skip to main content
1 of 5
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 27 bytes

n:"GaZyGTYa4&1ZI@=&fwxmA]va

(3 bytes were needed because of an Octave bug in bwlabeln function)

Try it online! Or verify all test cases.

Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372