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.
I did not know about the removeIf method until seeing your solution, very useful!
Pretty sure my brain was fried when I did this one; that or I solved it way too fast without even thinking.
Please. Just "return n * -1;" or "return -n;" will do just fine.
My attempted refactor (using TreeSet and LinkedHashSet) was only attempting to see if switching data structures alone would speed up the process (It didn't; usually I ended up just slowing things down actually). I didn't really think about the Set methods and using them to my advantage. After submitting, I saw the TreeSet based solutions from others and, wow. Pretty elegant! Especially when you don't just use the characteristics of the data structure (e.g. no duplicates) but also their methods to your advantage!
My solution obviously relies on holding onto and running through each and every element in the List, as well as inserting every element in sorted order, making it rather slow for any n > ~10,000.
Finally, a note about the line "while (index < ((n / 2) + (n / 6)))": through lots of testing, I found that I could get the correct n values looping only about 2/3 of n times (rather than say, "while (index < n)"). The solution relies on having all nums in the sequence filled in between 0 and n, so the sequence must be complete up till index n to retrieve the correct answer.
After doing this and looking at other's solutions, this was definitely silly.