Here's a solution using q wrapper prior - https://code.kx.com/q/ref/prior/ along with scan iterator.
prior
scan iterator
q)pt:{{(+)prior x,0}\[x;1]} q)pt[4] 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1