Skip to content

Instantly share code, notes, and snippets.

@russellkerns
russellkerns / subset-sum.md
Created November 26, 2019 21:14 — forked from garrett-green/subset-sum.md
Subset Sum

Prompt

Given a target sum and an array of positive integers, return true if any combination of numbers in the array can add to the target. Each number in the array may only be used once. Return false if the numbers cannot be used to add to the target sum.

Examples

subsetSum(2, [1, 10, 5, 3]); // false
subsetSum(10, [1, 10, 5, 3]); // true (10 === 10)
subsetSum(9, [1, 10, 5, 3]); // true (1+3+5 === 9)
@russellkerns
russellkerns / graphPathChecker.md
Created November 14, 2019 20:25
interviewer && interviewee gist

Graph Path Checker

Prompt

Write a function that determines if a path exists between two vertices of a directed graph.

Recall that a graph is a collection of connections, or 'edges', linking together nodes or verticies. In a directed graph, each edge is like an arrow or a one-way street-- an edge linking A to B indicates that A connects to B, but not that B connects to A.

The graph passed to the function will be represented as an object with a structure sometimes called an 'adjacency list' or 'adjacency map', in which each key represents a node in the graph, and each value will consist in an array of nodes which can be reached from the key. For example, the following object:

Substring Search

Prompt

Write a function, indexOf, which takes in two strings--the needle and the haystack--and returns the index of the first appearance of the needle in the haystack. If the needle does not appear in the haystack, return -1. Don't use indexOf(), includes() or substring(),

indexOf('or', 'hello world'); // should return 7
indexOf('hello world', 'or'); // should return -1
indexOf('howdy', 'hello world'); // should return -1