Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Almost did the same thing...but I changed the trait bounds on
array_diff
to also require thatT
implement theCopy
trait.Then I used
iter
andcopied
instead of just usinginto_iter
like I should have...because I initially misspelledinto_iter
while trying this exact thing :Pbest practice 🙏
I don't think that it's one of the best solutions: here filter is called two times, so it's likely that you iterate two time on input, which is unnecessay. This can be solve with a vanilla for loop & one if.
Rust is a pass by value language so really this is only mutating the function local value.
As long as the input variable is not a reference there's no risk of mutating the passed in value from the perspective of the caller.
This comment is hidden because it contains spoiler information about the solution
Do you know you can fork the solution and see what happens if you remove this part? Just click on
fork
below the code. Rust compiler explains things very well :)This comment is hidden because it contains spoiler information about the solution
Yes, but array sizes are quite small in test cases, so creating additional structures can be less productive in this specific case.
This code has O(n*m) runtime as for each element we have to re-scan in b from scratch.
This comment is hidden because it contains spoiler information about the solution
Great solution 👏👏
nvm it was just a typo.
This compiles and runs perfectly. Could you copy your code here?
i tried this and kept getting an error when
a[]
was emptyWell, this is kinda a duh moment for me... I did an iteration version which is wildly unnecessary, if you see this one. If anyone is still wondering how it works, it uses integer division to round down to the nearest whole number before multiplying by the divisor to get the complement.
Loading more items...