Skip to content

Instantly share code, notes, and snippets.

View MMintzer's full-sized avatar

Matt Mintzer MMintzer

View GitHub Profile
@MMintzer
MMintzer / pairSum
Last active September 9, 2019 19:46
// Given an array of numbers sorted in ascending order (least to greatest), and a
// separate number (a "sum"), determine if any 2 numbers in the array add up to the sum.
// Return true if any 2 different numbers within the array add up to sum.
// Return false if no 2 numbers in the array add up to sum.
function pairSum(arr, target) {
}
#Binary Search
Write a function that implements binary search.
Problem
Given a sorted array of numbers, locate the index of a specified value according to the following algorithm.First identify the middle number in the array.Next determine if the value to be found is greater than, lower than, or equal to the middle number.If it is equal, you are finished, and output the index of the found value.If not, repeat the procedure for a smaller array, formed from by taking half of the given array that the specified number falls into.
THIS IS AN EXAMPLE FOR THE INTERVIEWER. HAVE YOUR CANDIDATE COME UP WITH THEIR OWN EXAMPLE!
Example
Consider the array[1, 3, 4, 7, 12, 17, 20].We want to locate the index of 17. First compare 17 to the middle of the array, which is 7. Because 17 > 7 we then repeat the comparison using the subarray[12, 17, 20].We find that 17 matches the middle of this array, and so we output the index from the original array, which is 5. Note that we do not output the index of 17 from the smaller suba
BALANCED BRACKETS
// Write a function that takes in a string made up of brackets
// ("(", "[", "{") and other optional characters. The function should
// return a boolean representing whether or not the string is balanced
// in regards to brackets. A string is said to be balanced if it has as many
// opening brackets of a given type as it has closing brackets of that type
// and if no bracket is unmatched. Note that a closing bracket cannot
// match a corresponding opening bracket that comes after it. Similarly,
// brackets cannot overlap each other as in '[(])'
// RIVER SIZES
// You are given a two-dimensiona array (matrix) of potentially unequal height and width containing only 0s and 1s.
// Each 0 represents land, and each 1 represents part of a river. A river consists of any number of adjacent 1s forming
// a river determine its size. Write a function that returns an array of the sizes of all rivers represented in the input
// matrix. Note that these sizes do not need to be in any particular order.
Sample input:
[
[1,0,0,1,0],
// RIVER SIZES
// You are given a two-dimensiona array (matrix) of potentially unequal height and width containing only 0s and 1s.
// Each 0 represents land, and each 1 represents part of a river. A river consists of any number of adjacent 1s forming
// a river determine its size. Write a function that returns an array of the sizes of all rivers represented in the input
// matrix. Note that these sizes do not need to be in any particular order.
Sample input:
[
[1,0,0,1,0],

class: center middle

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.

# Prompt
Implement a function that adds two numbers without using `+` or any other built-in arithmetic operators.
# Examples
```js
add(8, 0); // 8
add(1, 1); // 2
add(2, 2); // 4

Prompt

Implement a function that adds two numbers without using + or any other built-in arithmetic operators.

Examples

add(8, 0);     // 8
add(1, 1);     // 2
add(2, 2); // 4

Slides

Prompt

Implement an immutable binary search tree class. The class constructor should accept (at least) a single argument which will represent the value for its root node. Each instance should have two methods: insert, which takes a numerical value and returns a new binary search tree containing that value, and contains, which takes a numerical value and returns true or false based on whether the tree contains it.

Insert should not mutate the existing binary search tree. That is:

const bstA = new ImmutableBST(5);

Slides


Prompt

You're an industrious programmer that lives off the grid. The local well that you use to fetch water has gone dry, so you've decided to collect rain water to filter; however, your collection device isn't flat.

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water your collection device is able to trap after raining.