Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit tree 1e5197aeb730da5a09dc09fa753c4b6ca071dd61 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
function hasTargetSum(array, target) {
// Write your algorithm here
const passedNumbers = new Set(); // initialize empty array
for (const number of array) {
const complement = target - number;

// returns true if the Set includes the complement
if (passedNumbers.has(complement)) return true;

// adds the number to the Set
passedNumbers.add(number);
}
return false;
}

/*
Write the Big O time complexity of your function here

Big O time complexity: O(n) - Linear time complexity - the number of elements in the array is the number of operations performed on each element

*/

/*
Add your pseudocode here
1. Initialize an empty Set
2. Loop through the array
3. Get the complement of the current number
4. Check if the Set includes the complement
5. If it does, return true
6. If it doesn't, add the number to the Set
7. Return false
*/

/*
Add written explanation of your solution here
The solution is to loop through the array and check if the complement of the current number is in the Set. If it is, return true. If it isn't, add the number to the Set.




*/

// You can run `node index.js` to view these console logs
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.