Given two sorted arrays of numbers, return an array containing all values that appear in both arrays. The numbers in the resulting array (the "intersection") may be returned in any order, they needn't be sorted.
Write a function that determines if a path exists between two vertices of a directed graph.
The graph will be represented as an object, each of whose keys represents a vertex of the graph and whose value represents all vertices that can be reached from the aforementioned key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//O(n) time and O(n) space | |
const PairSum = (arr, target) => { | |
const nums = {} | |
for (let i = 0; i < arr.length; i++) { | |
let curNum = arr[i] | |
let potentialMatch = target - curNum | |
if (nums[potentialMatch]) { | |
return true | |
} else { |