Skip to content

Instantly share code, notes, and snippets.

@brandonjyee
brandonjyee / fisher-yates.js
Created January 11, 2019 05:03
Fisher-Yates Shuffle Algorithm
/**
* Shuffles array in place. Fisher-Yates algo.
* @param {Array} a items An array containing the items.
*/
const shuffle = function(arr) {
// Start i from the last element and move left. Swap with a random element to the left of i
for (let i = arr.length - 1; i > 0; i--) {
// j is a random element to the left of i
const j = Math.floor(Math.random() * (i + 1));
// Swap elements at i and j
/*
Node Notes
*/
/*
========== Synchronous command line input w/o using external library ==========
*/
process.stdin.setEncoding('utf8');
function readlineSync() {
@brandonjyee
brandonjyee / Penn_Treebank_POS_tags.md
Last active December 20, 2018 17:44
Meanings for the Penn Treebank Part of Speech (POS) Tags
POS Tag Description Example
CC coordinating conjunction and
CD cardinal number 1, third
DT determiner the
EX existential there there is
FW foreign word les
IN preposition, subordinating conjunction in, of, like
IN/that that as subordinator that
JJ adjective green

class: center middle

Curry


Interviewer Prompt (a)

Currying is the process by which a function of N arguments is implemented as N single-argument functions such that first of them takes in the first argument and returns a function which takes in the 2nd argument and so on, until the Nth single-argument function finally returns the value of the multi-argument function being implemented.

Your Task:

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

Given an an array of numbers, find the length of the longest possible subsequence that is increasing. This subsequence can "jump" over numbers in the array. For example in [3, 10, 4, 5] the longest increasing subsequence (LIS) is [3, 4, 5].

Examples

longestIncreasingSubsequence([3, 4, 2, 1, 10, 6]);
// should return 3, the length of the longest increasing subsequence:
// 3, 4, 6 (or 3, 4, 10)

class: center, middle

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).

class: center middle

Dictionary Word Finder

<style> .remark-code { white-space: pre-wrap; } </style>
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true
@brandonjyee
brandonjyee / .editorconfig
Created May 1, 2018 15:14
Sample config file for VSC EditorConfig extension
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true