Interview Bootcamp
Ask Author
Back to course home

0% completed

Vote For New Content
Nitpick: sorting the array takes O(N*logN) time - can't we keep a hash of previo...

hj3yoo

Mar 3, 2022

Nitpick: sorting the array takes O(N*logN) time - can't we keep a hash of previously visited elements instead?

It matters less for this problem as the overall complexity is O(N2^N) which is significantly higher than O(NlogN), but just a food for thought.

1

0

Comments
Comments
P
Pete Stenger3 years ago

I would think this would add a lot of additional complexity because now you have to keep track of # of unique solutions added.

S
Splumpy Chumbo3 years ago

using a hash or a set to store seen elements only adds a couple lines of code compared to the solution to the previous problem. I think the real tradeoff is between time and space complexity. Sorting adds O(n*logn) time, while using a set/hash adds O(n) space in the wor...