Say I have a 2D array in which each row is zero-padded to the maximum length:

[[1, 2, 0],
[3, 0, 0],
[4, 5, 6]]

And I also have the length of the rows before they were padded:

[2, 1, 3]

I want to return the last non-zero element of each row, i.e.,

[2, 3, 6]

Is there an elegant(no loops) to achieve this?