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.
This was a pain in Haskell due to timeouts, but I can testify that there is a solution.
The issue is that the test cases are very long. Thus performing each test in O(n) is not going to cut it.
It is worth spending a little time prepping the data, which can be done in O(n log n) and then run each test using binary search with O(log n). Then you can pass all the tests cases
This problem is definitely worth more than 30 points. The intuitive approach of sorting and then adding until you reach the number does not cut it.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subset Sum
You are viewing a single comment's thread. Return to all comments →
This was a pain in Haskell due to timeouts, but I can testify that there is a solution.
The issue is that the test cases are very long. Thus performing each test in O(n) is not going to cut it.
It is worth spending a little time prepping the data, which can be done in O(n log n) and then run each test using binary search with O(log n). Then you can pass all the tests cases
This problem is definitely worth more than 30 points. The intuitive approach of sorting and then adding until you reach the number does not cut it.