You are viewing a single comment's thread. Return to all comments →
If at least the costs were given in order, it could make sense...
agreed. my binary search attempts were timing out.
it was only when i ignored it mentioning binary search and just thought about best way to solve the problem, could I solve it without timeouts
I had the same problem. The problem as such is good but it's poorly categorized.
If the costs were given in order, a linear search for the sum starting from both ends does the job instead of doing a binary search in every step.
At least in C++, you can sort the data and then perform linear search (converging from both ends) without timing out.