J, 15 bytes
A J port of Arnauld's 05AB1E solution (and tsh's JavaScript solution):
1#.0>./2-~/\0,]
K (oK), 12 7 bytes
-5 bytes thanks to ngn!
A k (oK) port of Arnauld's 05AB1E solution (and tsh's JavaScript solution):
+/0|-':
J, 15 bytes
A J port of Arnauld's 05AB1E solution (and tsh's JavaScript solution):
1#.0>./2-~/\0,]
My naive solution:
J, 27 bytes
1#.2(1 0-:])\0,@|:@,~1$~"0]