[Community Puzzle] The two piles difference


Send your feedback or ask for help here!

Passed all test cases, except the last one! Any python expert who can guide me on the last test case (which is taking a lot of time)?

If you try all combinations of 20 elements among 40 with bruteforce it will timeout but you can take advantage of the fact that there are at most 12 different values.

First, build a counter of values.

Then, for each value v with a count of c, chose how many copies (between 0 and c) of v you want to put in A.

Edit: I hadn’t solved the puzzle when I answered you, I just did with the method I mentionned and it works fine, so go for it :slight_smile:
Also, I checked the author’s solution and apparently it was intended to be solved with a genetic algorithm, so you can also try it this way if you want.


Passed it with random shuffle of the list + two-opt of the resulting split :stuck_out_tongue: