Skip to content

Instantly share code, notes, and snippets.

Intersection


Prompt

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.

@a-Daley
a-Daley / Solving Graphs.md
Last active September 10, 2019 04:52
Solving Graphs

Solving Graphs


Interviewer Prompt

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.

@a-Daley
a-Daley / BreathFirst.md
Created June 18, 2019 20:45
Breath-First Tree Traversal

Tree Traversal


Interviewer Prompt

Today you will write a series of iterator functions for trees.

  • breadthFirst

String Search

(ie indexOf)


Prompt

You are attempting to find the index of the first appearance of one string (the needle) inside of another (the haystack).

//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 {