# [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)], 12 bytes A [k (oK)] port of Arnauld's 05AB1E solution (and tsh's JavaScript solution): {+/0|-':0,x} [Try it online!][TIO-jrqdbb0d] [K (oK)]: https://github.com/JohnEarnest/ok [TIO-jrqdbb0d]: https://tio.run/##y9bNz/7/P82qWlvfoEZX3cpAp6L2f5qCoYKxghGQBGFTINtYwUTBiOs/AA "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"