#Japt, 16 15 bytes
Japt, 16 15 bytes
[UUy]®=ðd)ÎaZÌÄ
##Explanation [ ] :Create an array containing U : The input and Uy : The input transposed ® :Map each Z ð : Indices of elements where d : Any element is truthy (not 0) = ) : Reassign to Z Î : First element a : Absolute difference with ZÌ : Last element Ä : Plus 1
Explanation
[ ] :Create an array containing
U : The input and
Uy : The input transposed
® :Map each Z
ð : Indices of elements where
d : Any element is truthy (not 0)
= ) : Reassign to Z
Î : First element
a : Absolute difference with
ZÌ : Last element
Ä : Plus 1