随笔分类 - Algorithms
摘要:Prim's algorithm is a popular method used in computer science for finding a minimum spanning tree for a connected, undirected graph. This means it fin
阅读全文
摘要:An LRU (Least Recently Used) cache is a type of data structure that maintains a limited size of items and evicts the least recently accessed item when
阅读全文
摘要:export default function compare( a: BinaryNode<number> | null, b: BinaryNode<number> | null, ): boolean { if (a null && b null) { return true; } if (a
阅读全文
摘要:// Base case // 1. Off the map // 2. Hit a wall // 3. Already visited // 4. It's the end const dirs = [ [1, 0], //top [0, 1], //right [-1, 0], //botto
阅读全文
摘要:Using Linked list to implement a Queue. In javascript, if you want to push a item in front of an Array, it need to shift the rest of items, not good f
阅读全文
摘要:You're given two identical crystal balls and a 100-story building. The balls are incredibly tough, but there exists some floor in the building, above
阅读全文
摘要:Write a function that takes in an array of positive integers and returns the maximum sum of non-adjacent elements in the array. If the input array is
阅读全文
[Algorithm] Dynamic programming - 02 - Longest Common Subsequence - Drawing 2d matrix + back tracing
摘要:Write a function that takes in two strings and returns their longest common subsequence. A subsequence of a string is a set of characters that aren't
阅读全文
摘要:Problem: Levenshtein Distance Write a function that takes in two strings and returns the minimum number of edit operations that need to be performed o
阅读全文
摘要:You're given a non-empty array of arrays where each subarray holds three integers and represents a disk. These integers denote each disk's width, dept
阅读全文
摘要:A company has hired N interns to each join one of N different teams. Each intern has ranked their preferences for which teams they wish to join, and e
阅读全文
摘要:function validIPAddresses(string) { const res= [] for (let i = 1; i < Math.min(string.length, 4); i++) { const parts = ['', '', '', ''] parts[0] = str
阅读全文
摘要:You're given a non-empty array of positive integers where each integer represents the maximum number of steps you can take forward in the array. For e
阅读全文
摘要:Write a function that takes in a non-empty array of integers and returns the maximum sum that can be obtained by summing up all of the integers in a n
阅读全文
摘要:Write a function that takes in an array of unique integers and returns an array of all permutations of those integers in no particular order. If the i
阅读全文
摘要:Write a MinMaxStack class for a Min Max Stack. The class should support: Pushing and popping values on and off the stack. Peeking at the value at the
阅读全文
摘要:You're given an array of integers and another array of three distinct integers. The first array is guaranteed to only contain integers that are in the
阅读全文
摘要:// This is an input class. Do not edit. class Node { constructor(value) { this.value = value; this.prev = null; this.next = null; } } // Feel free to
阅读全文
摘要:Write a BST class for a Binary Search Tree. The class should support: Inserting values with the insert method. Removing values with the remove method;
阅读全文
摘要:Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if i
阅读全文