DEV Community

Discussion on: Two Sum Solution in JavaScript

lukaszahradnik profile image
Lukáš Zahradník
  1. It's happening in two loops - one in your function and the second one in the indexOf. It is still O(n^2).
  2. Try out twoSum([2,4,6,5,6], 8) for both of your solution and you will see the inconsistency of outputs.