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
/** | |
* Problem: Word Ladder | |
* | |
* Given a `beginWord`, an `endWord`, and a list of `wordList`: | |
* Transform `beginWord` into `endWord` by changing **only one letter at a time**, | |
* and each intermediate word must exist in the `wordList`. | |
* | |
* Return the **minimum number of transformations** required. | |
* If no such sequence exists, return 0. | |
* |
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
/** | |
* Problem: Detect Cycle in a Directed Graph | |
* | |
* You are given a directed graph represented as an adjacency list. | |
* Each key is a node, and its value is an array of neighbors. | |
* | |
* Goal: | |
* Return true if the graph contains a **cycle**, false otherwise. | |
* | |
* Example: |
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
/** | |
* Problem: Coin Change (Leetcode #322) | |
* | |
* You are given an array of coin denominations `coins` and an integer `amount`. | |
* Return the **fewest number of coins** needed to make up that amount. | |
* | |
* If it's not possible, return -1. | |
* | |
* You may use **each coin unlimited times** (unbounded knapsack). | |
* |
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
/** | |
* Problem: 0/1 Knapsack | |
* | |
* You are given two arrays: | |
* - weights[i] = weight of the i-th item | |
* - values[i] = value of the i-th item | |
* | |
* And an integer `capacity` representing the max weight the knapsack can hold. | |
* | |
* Goal: |
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
/** | |
* Problem: Subsets (Power Set) | |
* | |
* Given an array of distinct integers `nums`, return all possible subsets (the power set). | |
* Each subset must be in non-descending order (order of input), and the full result must not contain duplicates. | |
* | |
* You must return all subsets, including: | |
* - The empty subset [] | |
* - Single element subsets [x] | |
* - All combinations up to the full array [x, y, z, ...] |
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
/** | |
* Problem: Sudoku Solver | |
* | |
* You are given a 9x9 Sudoku board represented as a 2D array of characters. | |
* Empty cells are denoted by '.'. | |
* | |
* Goal: | |
* Fill the board in-place so that it becomes a valid completed Sudoku. | |
* | |
* Rules: |
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
/** | |
* ScrollOptions | |
*/ | |
class ScrollOptions { | |
constructor(obj) { | |
/** | |
* @type {Function} Function called when a scroll in occurs. | |
*/ | |
this.scrollIn = function() {}; |
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
/** | |
* @license MIT | |
* Copyright 2019 @andrei-m | |
* | |
* See original which this code is based on: | |
* https://gist.github.com/andrei-m/982927/0efdf215b00e5d34c90fdc354639f87ddc3bd0a5 | |
* | |
* Basic modifications include using ES6 `const` and `let`. Additionally | |
* condenses if statement. Changes are somewhat trivial overall :) |
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
/** | |
* Renders a model onto a template literal string. Renders the rendered text. | |
*/ | |
function render(model, templateLiteral) { | |
// declare the vars in function scope needed for our replacement | |
for (let key in model) { | |
let value; | |
if (typeof model[key] == 'string') { | |
value = '"' + model[key] + '"'; | |
} else { |
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
/** | |
* Renders a model onto a template literal string. Renders the rendered text. | |
*/ | |
function render(model, templateLiteral) { | |
// declare the vars in function scope needed for our replacement | |
for (let key in model) { | |
let value; | |
if (typeof model[key] == 'string') { | |
value = '"' + model[key] + '"'; | |
} else { |
NewerOlder