The focus on time complexity is unfortunate

For example, this was my JS solution to the Two Sum problem:

const twoSum = (nums, target) => nums
// Map to counterparts
.map(x => target - x)
// Map to indices of counterparts in input list, excluding self
.map((x, i) => nums.findIndex((y, j) => i !== j && x === y))
// Filter matches
.filter(x => x > -1)

It works, but trades speed for clarity, so it exceeds the time limit in the final test and fails; I feel that it should be still accepted, since it's not excessively slow, and because clarity and maintainability are often more important than just performance.

Comments (0)