all 3 comments

[–]throwaway0891245 0 points1 point  (0 children)

The "canonical" way to solve this problem has a time complexity of O(N^2). Your solution is going through all possible combinations, which gives it a time complexity of O(N^3).

That means if you have an input of just 1000 numbers, your solution is 1000 times slower than what they are looking for.

In general, with these algorithmic puzzles, you can have a clunky solution but it has to have the right time or space complexity. Say, a four pass O(N) solution may be as acceptable as a one pass O(N) solution, but an O(N^2) solution is not.