R, 3223 bytes
Edit: -9 bytes thanks to Command Master by switching to use a bitmask as input
function(h,n)rank(1:n%in%hh,,"f")
Input is simply a bitmask 1:n %in% h
returns a vector of mainly zeros, with ones whereno need to provide n
as this is implicitly the high-water marks should belength of the bitmask.
The "f"
(short for ties="first"
) argument to rank()
indicates that ties with the same rank should be broken using "increasing values at each index set of ties".
Old approach: R, 40 37 bytes
Edit: -2 bytes thanks to Command Master & Giuseppe
R, 32 bytes
function(h,n){x=1:n;x[h]=-x;rankrank(-x1:n%in%h,,"f")}
Same approach as above, except inputting h
as the indices of high-water marks, together with n
.
1:n %in% h
returns a vector of mainly zeros, with ones where the high-water marks should be (in other words, converting the indices to a bitmask).