4 ms·
Here's a much more efficient algorithm that runs in O(n*√2^n) time and space: 1. Spilt the toys in two sets (A and B) of similar size. 2. Generate a list L of
by nroets 5y ago
Here's a much more efficient algorithm that runs in O(n*√2^n) time and space:
1. Spilt the toys in two sets (A and B) of similar size.
2. Generate a list L of all the possible sums that can be made with the toys in set A.
3. Sort the list.
4. Generate all the possible sums that can be reached with the toys in B and binary search L for a sum that will solve the problem.