constsolve=arr=>{constvals=newMap()// tfw no Map::with_capacityfor(leti=0;i<arr.length;i++)vals.set(arr[i],i)constout=newArray(arr.length)for(const[v,i]ofvals)out[i]=vreturnout.filter(x=>typeofx!=="undefined")}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Javascript in O(n) (more specifically
3n
, looping three times on the length of the input, two identicalreduce
es and onefilter
):Epic, but also this relies on the
array
being sparse in the first reduce (so, a map really), sincenew Array(Number.MAX_SAFE_INTEGER)
is an error.I'd express that as
which is just a funny version of