We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It's both. The call to contains() on colors will be O(1) for a HashSet versus O(n) for a List, and you won't store duplicates. The listing above can be improved by using the output of remove instead of calling contains first. You can also add directly to the Set when reading from Stdin rather than storing values first and iterating through them.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
It's both. The call to contains() on colors will be O(1) for a HashSet versus O(n) for a List, and you won't store duplicates. The listing above can be improved by using the output of remove instead of calling contains first. You can also add directly to the Set when reading from Stdin rather than storing values first and iterating through them.