2 of 5 added 7 characters in body

J, 29 23 bytes

1{(,~#|1+}.i.{.)@]^:[&0

Try it online!