New answers tagged

1

Yeah, you are recreating tmp every iteration of your loop. This makes your solution O(n^2). You could easily make your solution O(n) by setting tmp before your loop and then updating it along with newlist. The reason your current solution is O(n^2) is that building the tmp set with all the items in newlist would take as long as new list. For example, if ...


2

As already stated, not sure why you're returning vectors; the linked question asks for a number. And with that, you can use big-integers with simple calculations; some already do num-combin and num-perm efficiently behind the scenes. Ignoring the algorithm though (since that seems to be your intent), you're passing ownership of values that you're not ...


Top 50 recent answers are included