Mark As Completed Discussion

This may be fine if our input is small, but this grows quite fast, as every additional element in the input will require a number of operations equivalent to the input length. The time complexity would be O(n^2). A better methodology is to use a data structure-- specifically, a hash map.

Using a hash map, we can set up a separate tracker, where the keys represent the difference between the goal and a number at an index.

Step Three

The above is a visual of a hash map data structure.

So if we had an array of numbers [1, 3, 5], and the target/goal was 4, here's the example hash map that we'd generate:

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment