There is a more efficient solution to findSum in javaScript

Hi just saw the findSum question in java script. Which sounds like a twoSum issue. I was wondering why you didn’t show the solution which can be done in O(n) which is to build a dictionary.

The key of this dictionary would be the complement value that is needed for a specific number to add up to the target and the value would be the number.

as we iterate through the array we fill up the dictionary checking whether the value in the array exists as the key in the dictionary,

If there is a match we have a key and value that add up to be the target value

Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers


You are thinking in the right direction toward an efficient solution, but we still need to cover the concept of dictionaries in the course. In the meantime, we will cover other approaches to solving the problem that does not require dictionaries. However, we appreciate your out-of-the-box thinking and encourage it.

Happy learning at Educative.