in reply to Re^7: LeetCode Problem #1 - Two Sum - Improve and/or discuss.
in thread LeetCode Problem #1 - Two Sum - Improve and/or discuss.

Consider if a new element is added to @tests:

[[1,2,3,6], 5, [2,1]]

So, 3+2=5 and the solution is found. In my code, with a sorted $test->[EXPECTED], the test passes; in yours, with an unsorted $test->[EXPECTED], the test fails.

"FWIW: one actually needs more tests if the input isn't unique, since those cases are different but legit solutions. ... another case for multiple solutions would be ..."

That's incorrect. The spec has, in emboldened text (under Contraints): Only one valid answer exists.

— Ken