# [J], 15 bytes A J port of Arnauld's 05AB1E solution (and tsh's JavaScript solution): 1#.0>./2-~/\0,] [Try it online!][TIO-jrqbpjvg] [J]: http://jsoftware.com/ [TIO-jrqbpjvg]: https://tio.run/##RYvBCoMwEETv@YqHLYiQrpuooIJ@SXsqDaWXHjzrr8e0YGTY4c3uzieGZRKUEY3uIjpL7W9bfVf7iJUphDJMUmJZR8JizOv5/hJwNPjkv@kSN7T449jRn39/HVGvmpGMNjd9WufglIGewcQd "J – Try It Online" # [K (oK)], <s>12</s> 7 bytes -5 bytes thanks to ngn! A [k (oK)] port of Arnauld's 05AB1E solution (and tsh's JavaScript solution): +/0|-': [Try it online!][TIO-jrqhgupq] [K (oK)]: https://github.com/JohnEarnest/ok [TIO-jrqhgupq]: https://tio.run/##y9bNz/7/P81KW9@gRlfd6n@agqGCsYIRkARhUyDbWMFEwYjrPwA "K (oK) – Try It Online" My naive solution: - # [J], 27 bytes 1#.2(1 0-:])\0,@|:@,~1$~"0] [Try it online!][TIO-jrqa7sle] [J]: http://jsoftware.com/ [TIO-jrqa7sle]: https://tio.run/##RYvBCsIwEETv@YpHLdRCDLuphTZQ6IfYkxjEi4detb8eo9DIsMOb3Z1HiuvkEAKS9OD8UZFTWNqL2PkVZrtpvVWypNZUjiZOrsHyDsTVmNv1/iSidPjs3@kzd5zx@7Fn@P/9tEeppSAFbWn6vC5BhZGB0aQP "J – Try It Online"