If you know if advance you need distinct elements,...
# announcements
k
If you know if advance you need distinct elements, use a set instead of
list.distinct()
.
w
Gotcha! Could that be causing the issues of memory?
a
@warriorprincess what do you call large inputs?
w
@Andreas Sinz this: https://codeshare.io/5ov7EX
it works okay on my pc
but the cloud portal says
out of memory
a
how many integers are inside
nums
?
k
Could be the "cause" depending on how many duplicates there are.
w
theyre all zeros...
k
They a set will use
O(1)
memory while the list would use
O(n)
memory and have way worse performance.
w
@Andreas Sinz a lot of them...100ish
1000*
@karelpeeters makes sense
k
That's a relatively small amount 😉
w
i guess my code sucked and was giving duplicate
thats why i had to use distinct
which messed up the perf...
i tried to reduce the duplicates and reduced them to one