[web] qns: modify questions types (#1429)
This commit is contained in:
parent
89b3981632
commit
568cddfd77
|
|
@ -95,7 +95,7 @@ export default {
|
|||
'/interviews/company',
|
||||
'/interviews/roadmap',
|
||||
// Interviews / Questions
|
||||
...codingQuestionsList.map(({ href }) => href),
|
||||
...codingQuestionsList.map(({ metadata }) => metadata.href),
|
||||
// Projects
|
||||
'/projects',
|
||||
'/projects/pricing',
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/binary-search-tree.submit.test.ts": "import BST from './binary-search-tree';\n\ndescribe('BST', () => {\n test('constructor', () => {\n const bst = new BST();\n expect(bst instanceof BST).toBeTruthy();\n expect(bst.root).toBeNull();\n });\n\n test('insert and search', () => {\n const bst = new BST();\n bst.insert(100);\n expect(bst.search(100)).toBeTruthy();\n bst.insert(200);\n expect(bst.search(200)).toBeTruthy();\n bst.insert(50);\n expect(bst.search(50)).toBeTruthy();\n });\n\n test('delete leaf node', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(70);\n bst.delete(30);\n expect(bst.search(30)).toBeFalsy();\n expect(bst.root?.left).toBeNull();\n });\n\n test('delete node with one child', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(20);\n bst.delete(30);\n expect(bst.search(30)).toBeFalsy();\n expect(bst.root?.left?.value).toBe(20);\n });\n\n test('delete node with two children', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(70);\n bst.insert(20);\n bst.insert(40);\n bst.delete(30);\n expect(bst.search(30)).toBeFalsy();\n expect(bst.root?.left?.value).not.toBe(30);\n });\n\n test('delete root node', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(70);\n bst.delete(50);\n expect(bst.search(50)).toBeFalsy();\n expect(bst.root?.value).not.toBe(50);\n });\n\n test('insert many and test structure', () => {\n const bst = new BST();\n const values = [50, 30, 70, 20, 40, 60, 80];\n values.forEach((value) => bst.insert(value));\n expect(bst.root?.value).toBe(50);\n expect(bst.root?.left?.value).toBe(30);\n expect(bst.root?.right?.value).toBe(70);\n expect(bst.root?.left?.left?.value).toBe(20);\n expect(bst.root?.left?.right?.value).toBe(40);\n expect(bst.root?.right?.left?.value).toBe(60);\n expect(bst.root?.right?.right?.value).toBe(80);\n });\n\n test('search non-existent value', () => {\n const bst = new BST();\n bst.insert(50);\n expect(bst.search(100)).toBeFalsy();\n });\n\n test('complex insert and delete sequence', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(70);\n bst.insert(20);\n bst.insert(40);\n bst.insert(60);\n bst.insert(80);\n bst.delete(70);\n expect(bst.search(70)).toBeFalsy();\n bst.delete(50);\n expect(bst.search(50)).toBeFalsy();\n bst.insert(35);\n bst.insert(45);\n expect(bst.search(35)).toBeTruthy();\n expect(bst.search(45)).toBeTruthy();\n });\n\n test('delete on empty BST', () => {\n const bst = new BST();\n bst.delete(100);\n expect(bst.root).toBeNull();\n });\n\n test('maintaining state after multiple operations', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(60);\n bst.delete(50);\n bst.insert(55);\n bst.insert(65);\n expect(bst.search(55)).toBeTruthy();\n expect(bst.search(65)).toBeTruthy();\n bst.delete(65);\n expect(bst.search(65)).toBeFalsy();\n });\n\n test('integration test of operations', () => {\n const bst = new BST();\n bst.insert(50);\n bst.insert(30);\n bst.insert(70);\n bst.insert(20);\n bst.insert(60);\n bst.insert(80);\n bst.insert(40);\n bst.delete(50);\n expect(bst.search(50)).toBeFalsy();\n bst.insert(55);\n expect(bst.search(55)).toBeTruthy();\n bst.delete(55);\n expect(bst.search(55)).toBeFalsy();\n });\n});\n",
|
||||
"/src/binary-search-tree.ts": "class Node<T> {\n value: number | null;\n left: Node<T> | null;\n right: Node<T> | null;\n\n constructor(value: number | null = null) {\n this.value = value;\n this.left = null;\n this.right = null;\n }\n}\n\nexport default class BinarySearchTree<T> {\n root: Node<T> | null;\n\n constructor() {\n this.root = null;\n }\n\n /**\n * Inserts a new value into the BST while maintaining BST properties.\n * @param value The value to be inserted into the BST.\n */\n insert(value: number): void {\n const newNode = new Node(value);\n if (this.root === null) {\n this.root = newNode;\n return;\n }\n\n let currentNode: Node<T> | null = this.root;\n let parent: Node<T> | null = null;\n while (currentNode) {\n parent = currentNode;\n if (value < currentNode.value!) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (parent && value < parent.value!) {\n parent.left = newNode;\n } else if (parent) {\n parent.right = newNode;\n }\n }\n\n /**\n * Searches for a value in the BST. Returns true if the value exists, false otherwise.\n * @param value The value to search for.\n * @return True if the value is found, false otherwise.\n */\n search(value: number): boolean {\n let currentNode = this.root;\n while (currentNode) {\n if (value === currentNode.value) {\n return true;\n }\n currentNode =\n value < currentNode.value! ? currentNode.left : currentNode.right;\n }\n return false;\n }\n\n /**\n * Deletes a value from the BST, if it exists, while maintaining BST properties.\n * @param value The value to be deleted from the BST.\n */\n delete(value: number): void {\n let currentNode = this.root;\n let parent: Node<T> | null = null;\n\n // Find the node and its parent.\n while (currentNode && currentNode.value !== value) {\n parent = currentNode;\n if (value < currentNode.value!) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (!currentNode) {\n return; // Node not found.\n }\n\n // Node has two children.\n if (currentNode.left && currentNode.right) {\n let successor = currentNode.right;\n let successorParent = currentNode;\n\n // Find the node with the smallest value in the right subtree and take note of its parent.\n while (successor.left) {\n successorParent = successor;\n successor = successor.left;\n }\n\n currentNode.value = successor.value; // Replace value.\n currentNode = successor; // Move pointer to successor, which will be deleted.\n parent = successorParent;\n }\n\n // Node has one or zero children.\n let child = currentNode.left ? currentNode.left : currentNode.right;\n\n // If the node to be deleted is the root node.\n if (!parent) {\n this.root = child;\n } else {\n if (parent.left === currentNode) {\n parent.left = child;\n } else {\n parent.right = child;\n }\n }\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a binary search tree data structure including essential BST operations",
|
||||
"title": "Binary Search Tree"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1745539200,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a binary search tree data structure including essential BST operations",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -34,7 +37,6 @@
|
|||
],
|
||||
"slug": "binary-search-tree",
|
||||
"subtitle": null,
|
||||
"title": "Binary Search Tree",
|
||||
"topics": [
|
||||
"binary-tree",
|
||||
"binary-search-tree",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/binary-search.submit.test.ts": "import binarySearch from './binary-search';\n\ndescribe('binarySearch', () => {\n test('empty', () => {\n expect(binarySearch([], 1)).toBe(-1);\n });\n\n test('one element', () => {\n expect(binarySearch([1], 1)).toBe(0);\n expect(binarySearch([1], 2)).toBe(-1);\n });\n\n test('two elements', () => {\n expect(binarySearch([1, 4], 1)).toBe(0);\n expect(binarySearch([1, 4], 4)).toBe(1);\n expect(binarySearch([1, 4], 5)).toBe(-1);\n });\n\n test('more than two elements', () => {\n expect(binarySearch([1, 2, 3, 10, 11, 20], 1)).toBe(0);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 2)).toBe(1);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 3)).toBe(2);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 10)).toBe(3);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 9)).toBe(-1);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 4)).toBe(-1);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 0)).toBe(-1);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 21)).toBe(-1);\n });\n\n test('boundary values', () => {\n expect(binarySearch([1, 2, 3, 10, 11, 20], 1)).toBe(0);\n expect(binarySearch([1, 2, 3, 10, 11, 20], 20)).toBe(5);\n });\n});\n",
|
||||
"/src/binary-search.ts": "export default function binarySearch(\n arr: Array<number>,\n target: number,\n): number {\n // Initialize the left and right indices of the array\n let left = 0;\n let right = arr.length - 1;\n\n // Keep searching until the left and right indices meet.\n while (left <= right) {\n // Calculate the mid index to retrieve the mid element later.\n const mid = Math.floor((left + right) / 2);\n\n if (target < arr[mid]) {\n // If the target element is less than the middle element,\n // search the left half of the array.\n // Adjust the right index so the next loop iteration\n // searches the left side.\n right = mid - 1;\n } else if (target > arr[mid]) {\n // If the target element is greater than the middle element,\n // search the right half of the array.\n // Adjust the left index so the next loop iteration\n // searches the left side.\n left = mid + 1;\n } else {\n // If the target element is equal to the middle element,\n // return the index of the middle element.\n return mid;\n }\n }\n\n // If the element is not found, return -1.\n return -1;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs binary search on an array of numbers",
|
||||
"title": "Binary Search"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a function that performs binary search on an array of numbers",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -37,7 +40,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "binary-search",
|
||||
"subtitle": null,
|
||||
"title": "Binary Search",
|
||||
"topics": [
|
||||
"binary-search",
|
||||
"sorting"
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/breadth-first-search.submit.test.ts": "import breadthFirstSearch from './breadth-first-search';\n\ndescribe('breadthFirstSearch', () => {\n test('empty graph', () => {\n expect(breadthFirstSearch({}, '')).toEqual([]);\n });\n\n test('graphs with one node', () => {\n expect(breadthFirstSearch({ A: [] }, 'A')).toEqual(['A']);\n });\n\n test('graphs with two nodes', () => {\n expect(breadthFirstSearch({ A: ['B'], B: [] }, 'A')).toEqual(['A', 'B']);\n expect(breadthFirstSearch({ A: ['A', 'B'], B: [] }, 'A')).toEqual([\n 'A',\n 'B',\n ]);\n expect(breadthFirstSearch({ A: ['A', 'B'], B: [] }, 'B')).toEqual(['B']);\n expect(breadthFirstSearch({ A: ['A', 'B'], B: ['A'] }, 'B')).toEqual([\n 'B',\n 'A',\n ]);\n });\n\n test('graphs with multiple nodes', () => {\n expect(breadthFirstSearch({ A: ['B'], B: ['C'], C: [] }, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(breadthFirstSearch({ A: ['B', 'C'], B: [], C: [] }, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(\n breadthFirstSearch(\n { A: ['B', 'C'], B: [], C: [], D: ['B'], E: ['C'] },\n 'A',\n ),\n ).toEqual(['A', 'B', 'C']);\n expect(\n breadthFirstSearch(\n { A: ['D', 'E'], B: [], C: [], D: ['B'], E: ['C'] },\n 'A',\n ),\n ).toEqual(['A', 'D', 'E', 'B', 'C']);\n expect(\n breadthFirstSearch(\n {\n A: ['D', 'E'],\n B: ['A', 'B', 'C', 'D', 'E'],\n C: [],\n D: ['B'],\n E: ['C'],\n },\n 'A',\n ),\n ).toEqual(['A', 'D', 'E', 'B', 'C']);\n // Graph taken from https://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/\n const graph = {\n A: ['B', 'C'],\n B: ['A', 'D', 'E'],\n C: ['A', 'E'],\n D: ['B', 'E', 'F'],\n E: ['B', 'C', 'D', 'F'],\n F: ['D', 'E'],\n };\n expect(breadthFirstSearch(graph, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n ]);\n expect(breadthFirstSearch(graph, 'B')).toEqual([\n 'B',\n 'A',\n 'D',\n 'E',\n 'C',\n 'F',\n ]);\n expect(breadthFirstSearch(graph, 'C')).toEqual([\n 'C',\n 'A',\n 'E',\n 'B',\n 'D',\n 'F',\n ]);\n expect(breadthFirstSearch(graph, 'D')).toEqual([\n 'D',\n 'B',\n 'E',\n 'F',\n 'A',\n 'C',\n ]);\n });\n\n test('disjoint graphs', () => {\n const disjoinGraph = { A: ['B'], B: [], C: [], D: ['C'] };\n expect(breadthFirstSearch(disjoinGraph, 'A')).toEqual(['A', 'B']);\n expect(breadthFirstSearch(disjoinGraph, 'C')).toEqual(['C']);\n expect(breadthFirstSearch(disjoinGraph, 'D')).toEqual(['D', 'C']);\n });\n\n test('cyclic graphs', () => {\n expect(breadthFirstSearch({ A: ['A'] }, 'A')).toEqual(['A']);\n const cyclicGraphOne = {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n };\n const cyclicGraphTwo = {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n };\n expect(breadthFirstSearch(cyclicGraphOne, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n 'H',\n 'I',\n 'J',\n ]);\n expect(breadthFirstSearch(cyclicGraphOne, 'B')).toEqual([\n 'B',\n 'E',\n 'F',\n 'D',\n 'I',\n 'J',\n ]);\n expect(breadthFirstSearch(cyclicGraphTwo, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n ]);\n expect(breadthFirstSearch(cyclicGraphTwo, 'E')).toEqual(['E']);\n });\n});\n",
|
||||
"/src/breadth-first-search.ts": "export default function breadthFirstSearch(\n graph: Record<string, Array<string>>,\n source: string,\n): Array<string> {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create a queue to store the nodes to be visited.\n // Add the root node since we're doing a level-order BFS.\n const queue = new Queue<string>();\n queue.enqueue(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set<string>();\n\n // While there are nodes to visit.\n while (!queue.isEmpty()) {\n // Dequeue the node at the front of the queue.\n const node = queue.dequeue()!;\n\n // Mark the node as visited.\n visited.add(node);\n\n // Enqueue the neighbors of the current node.\n graph[node].forEach((neighbor) => {\n // Skip nodes that have already been visited.\n if (visited.has(neighbor)) {\n return;\n }\n\n queue.enqueue(neighbor);\n });\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n\n/* Auxiliary classes */\n\n/**\n * A Queue class with O(1) enqueue and dequeue is provided for you.\n * You can use it directly should you wish to.\n *\n * Example usage:\n * const q = new Queue();\n * q.enqueue('a');\n * q.enqueue('b');\n * q.dequeue(); //'a'\n * q.isEmpty(); // False\n */\nclass Node<T> {\n value: T;\n next: Node<T> | null;\n\n constructor(value: T) {\n this.value = value;\n this.next = null;\n }\n}\n\nclass Queue<T> {\n head: Node<T> | null;\n tail: Node<T> | null;\n length: number;\n\n constructor() {\n this.head = null;\n this.tail = null;\n this.length = 0;\n }\n\n isEmpty(): boolean {\n return this.length === 0;\n }\n\n enqueue(item: T): void {\n const newNode = new Node(item);\n if (this.isEmpty()) {\n this.head = newNode;\n } else if (this.tail) {\n this.tail.next = newNode;\n }\n this.tail = newNode;\n this.length++;\n }\n\n dequeue(): T | null {\n if (this.isEmpty() || !this.head) {\n return null;\n } else {\n const removedNode = this.head;\n this.head = this.head.next;\n removedNode.next = null;\n this.length--;\n if (this.isEmpty()) {\n this.tail = null;\n }\n return removedNode.value;\n }\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner",
|
||||
"title": "Breadth-first Search"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1679788800,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "breadth-first-search",
|
||||
"subtitle": null,
|
||||
"title": "Breadth-first Search",
|
||||
"topics": [
|
||||
"bfs"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/bubble-sort.submit.test.ts": "import bubbleSort from './bubble-sort';\n\ndescribe('bubbleSort', () => {\n test('empty', () => {\n expect(bubbleSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(bubbleSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(bubbleSort([2, 1])).toEqual([1, 2]);\n expect(bubbleSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(bubbleSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(bubbleSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(bubbleSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(bubbleSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(bubbleSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(bubbleSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(bubbleSort([1, 1])).toEqual([1, 1]);\n expect(bubbleSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(bubbleSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(bubbleSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(bubbleSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/bubble-sort.ts": "export default function bubbleSort(arr: Array<number>): Array<number> {\n // Do multiple iterations over the array.\n for (let i: number = 0; i < arr.length; i++) {\n // For each iteration, compare every adjacent pairs while ignoring the last i elements that are already sorted.\n for (let j: number = 0; j < arr.length - i; j++) {\n // If the left element in the pair is larger than the right one, swap their positions to ensure that elements are sorted ascendingly.\n if (arr[j] > arr[j + 1]) {\n let temp: number = arr[j];\n arr[j] = arr[j + 1];\n arr[j + 1] = temp;\n }\n }\n }\n\n // Return the sorted array.\n return arr;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a bubble sort",
|
||||
"title": "Bubble Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1745539200,
|
||||
"difficulty": "easy",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a function that performs a bubble sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -36,7 +39,6 @@
|
|||
],
|
||||
"slug": "bubble-sort",
|
||||
"subtitle": null,
|
||||
"title": "Bubble Sort",
|
||||
"topics": [
|
||||
"sorting"
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/depth-first-search.submit.test.ts": "import depthFirstSearch from './depth-first-search';\n\ndescribe('depthFirstSearch', () => {\n test('empty graph', () => {\n expect(depthFirstSearch({}, 'A')).toEqual([]);\n });\n\n test('graphs with one node', () => {\n expect(depthFirstSearch({ A: [] }, 'A')).toEqual(['A']);\n });\n\n test('graphs with two nodes', () => {\n expect(depthFirstSearch({ A: ['B'], B: [] }, 'A')).toEqual(['A', 'B']);\n expect(depthFirstSearch({ A: ['A', 'B'], B: [] }, 'A')).toEqual(['A', 'B']);\n expect(depthFirstSearch({ A: ['A', 'B'], B: [] }, 'B')).toEqual(['B']);\n expect(depthFirstSearch({ A: ['A', 'B'], B: ['A'] }, 'B')).toEqual([\n 'B',\n 'A',\n ]);\n });\n\n test('graphs with multiple nodes', () => {\n expect(depthFirstSearch({ A: ['B'], B: ['C'], C: [] }, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(depthFirstSearch({ A: ['B', 'C'], B: [], C: [] }, 'A')).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(\n depthFirstSearch(\n { A: ['B', 'C'], B: [], C: [], D: ['B'], E: ['C'] },\n 'A',\n ),\n ).toEqual(['A', 'B', 'C']);\n expect(\n depthFirstSearch(\n { A: ['D', 'E'], B: [], C: [], D: ['B'], E: ['C'] },\n 'A',\n ),\n ).toEqual(['A', 'D', 'B', 'E', 'C']);\n expect(\n depthFirstSearch(\n {\n A: ['D', 'E'],\n B: ['A', 'B', 'C', 'D', 'E'],\n C: [],\n D: ['B'],\n E: ['C'],\n },\n 'A',\n ),\n ).toEqual(['A', 'D', 'B', 'C', 'E']);\n expect(\n depthFirstSearch(\n {\n A: ['A', 'B', 'C', 'D', 'E'],\n B: [],\n C: [],\n D: ['B'],\n E: ['C'],\n },\n 'A',\n ),\n ).toEqual(['A', 'B', 'C', 'D', 'E']);\n // Graph taken from https://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/\n const graph = {\n A: ['B', 'C'],\n B: ['A', 'D', 'E'],\n C: ['A', 'E'],\n D: ['B', 'E', 'F'],\n E: ['B', 'C', 'D', 'F'],\n F: ['D', 'E'],\n };\n expect(depthFirstSearch(graph, 'A')).toEqual([\n 'A',\n 'B',\n 'D',\n 'E',\n 'C',\n 'F',\n ]);\n expect(depthFirstSearch(graph, 'B')).toEqual([\n 'B',\n 'A',\n 'C',\n 'E',\n 'D',\n 'F',\n ]);\n expect(depthFirstSearch(graph, 'C')).toEqual([\n 'C',\n 'A',\n 'B',\n 'D',\n 'E',\n 'F',\n ]);\n expect(depthFirstSearch(graph, 'D')).toEqual([\n 'D',\n 'B',\n 'A',\n 'C',\n 'E',\n 'F',\n ]);\n expect(depthFirstSearch(graph, 'E')).toEqual([\n 'E',\n 'B',\n 'A',\n 'C',\n 'D',\n 'F',\n ]);\n expect(depthFirstSearch(graph, 'F')).toEqual([\n 'F',\n 'D',\n 'B',\n 'A',\n 'C',\n 'E',\n ]);\n });\n\n test('disjoint graphs', () => {\n expect(depthFirstSearch({ A: ['B'], B: [], C: [], D: ['C'] }, 'A')).toEqual(\n ['A', 'B'],\n );\n expect(depthFirstSearch({ A: ['B'], B: [], C: [], D: ['C'] }, 'C')).toEqual(\n ['C'],\n );\n expect(depthFirstSearch({ A: ['B'], B: [], C: [], D: ['C'] }, 'D')).toEqual(\n ['D', 'C'],\n );\n });\n\n test('cyclic graphs', () => {\n expect(depthFirstSearch({ A: ['A'] }, 'A')).toEqual(['A']);\n expect(\n depthFirstSearch(\n {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n },\n 'A',\n ),\n ).toEqual(['A', 'B', 'E', 'D', 'I', 'J', 'F', 'C', 'G', 'H']);\n expect(\n depthFirstSearch(\n {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n },\n 'B',\n ),\n ).toEqual(['B', 'E', 'D', 'I', 'J', 'F']);\n expect(\n depthFirstSearch(\n {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n },\n 'A',\n ),\n ).toEqual(['A', 'B', 'D', 'E', 'C', 'F', 'G']);\n expect(\n depthFirstSearch(\n {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n },\n 'E',\n ),\n ).toEqual(['E']);\n });\n});\n",
|
||||
"/src/depth-first-search.ts": "export default function depthFirstSearch(\n graph: Record<string, Array<string>>,\n source: string,\n): Array<string> {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create an stack to store the nodes to be visited. We can simulate\n // stacks using arrays in JavaScript.\n // Add the root node since we're doing a pre-order DFS.\n const toBeVisited: Array<string> = [];\n toBeVisited.push(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set<string>();\n\n // Loop as long as array is empty (i.e. there are still nodes to be visited).\n while (toBeVisited.length !== 0) {\n // Pop top node from array (toBeVisited) and add it to the set (visited).\n const node = toBeVisited.pop()!;\n visited.add(node);\n\n // Retrieve neighbors (values of the adjacency list input Object)\n const neighbors = graph[node];\n // Push neighbors, in reverse order, onto array to be visited\n // to preserve original order of neighbors when visiting (popping off the array).\n for (let i = neighbors.length - 1; i >= 0; i--) {\n const neighbor = neighbors[i];\n // First check if the neighbor has already been visited before adding it.\n if (!visited.has(neighbor)) {\n toBeVisited.push(neighbor);\n }\n }\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a depth-first search algorithm that traverses a directed graph in a depth-first manner",
|
||||
"title": "Depth-first Search"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a depth-first search algorithm that traverses a directed graph in a depth-first manner",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "depth-first-search",
|
||||
"subtitle": null,
|
||||
"title": "Depth-first Search",
|
||||
"topics": [
|
||||
"dfs"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/dijkstra.submit.test.ts": "import dijkstra from './dijkstra';\n\ndescribe('dijkstra', () => {\n test('empty graph', () => {\n expect(dijkstra({}, 'A')).toEqual({});\n });\n\n test('graph with one node', () => {\n expect(dijkstra({ A: {} }, 'A')).toEqual({ A: 0 });\n });\n\n test('graph with two nodes', () => {\n expect(dijkstra({ A: { B: 1 }, B: {} }, 'A')).toEqual({ A: 0, B: 1 });\n expect(dijkstra({ A: { B: 5 }, B: { A: 2 } }, 'A')).toEqual({ A: 0, B: 5 });\n expect(dijkstra({ A: { B: 5 }, B: { A: 2 } }, 'B')).toEqual({ A: 2, B: 0 });\n });\n\n test('graphs with multiple nodes', () => {\n expect(\n dijkstra({ A: { B: 1, C: 4 }, B: { D: 1 }, C: {}, D: {} }, 'A'),\n ).toEqual({\n A: 0,\n B: 1,\n C: 4,\n D: 2,\n });\n expect(\n dijkstra({ A: { B: 2, C: 5 }, B: { C: 3 }, C: { D: 1 }, D: {} }, 'A'),\n ).toEqual({\n A: 0,\n B: 2,\n C: 5,\n D: 6,\n });\n expect(\n dijkstra(\n { A: { B: 1, C: 2 }, B: { C: 1, D: 2 }, C: { D: 5 }, D: {} },\n 'A',\n ),\n ).toEqual({\n A: 0,\n B: 1,\n C: 2,\n D: 3,\n });\n });\n\n test('disjoint graphs', () => {\n expect(dijkstra({ A: { B: 3 }, B: {}, C: { D: 1 }, D: {} }, 'A')).toEqual({\n A: 0,\n B: 3,\n C: Infinity,\n D: Infinity,\n });\n expect(dijkstra({ A: { B: 3 }, B: {}, C: { D: 1 }, D: {} }, 'C')).toEqual({\n A: Infinity,\n B: Infinity,\n C: 0,\n D: 1,\n });\n });\n\n test('graph with cycles', () => {\n expect(\n dijkstra(\n { A: { B: 1, C: 2 }, B: { A: 2 }, C: { D: 3 }, D: { A: 1 } },\n 'A',\n ),\n ).toEqual({\n A: 0,\n B: 1,\n C: 2,\n D: 5,\n });\n expect(\n dijkstra(\n { A: { B: 4, C: 1 }, B: { C: 2, D: 2 }, C: { D: 2 }, D: { A: 7 } },\n 'A',\n ),\n ).toEqual({\n A: 0,\n B: 4,\n C: 1,\n D: 3,\n });\n });\n});\n",
|
||||
"/src/dijkstra.ts": "type HeapItem = { vertex: string; weight: number };\n\n/**\n * MinHeap: A minimum heap implementation to serve as a priority queue.\n * Each heap element is of type HeapItem.\n */\nclass MinHeap {\n private heap: HeapItem[];\n private position: { [vertex: string]: number };\n\n constructor() {\n this.heap = [];\n this.position = {};\n }\n\n // Helper method to swap two elements and update their positions.\n private swap(i: number, j: number): void {\n [this.heap[i], this.heap[j]] = [this.heap[j], this.heap[i]];\n this.position[this.heap[i].vertex] = i;\n this.position[this.heap[j].vertex] = j;\n }\n\n // Bubbles up the element at index i to restore heap property.\n private percolateUp(i: number): void {\n while (i > 0) {\n const parent = Math.floor((i - 1) / 2);\n if (this.heap[parent].weight > this.heap[i].weight) {\n this.swap(i, parent);\n i = parent;\n } else {\n break;\n }\n }\n }\n\n // Bubbles down the element at index i to restore heap property.\n private percolateDown(i: number): void {\n const n = this.heap.length;\n while (true) {\n const left = 2 * i + 1;\n const right = 2 * i + 2;\n let smallest = i;\n\n if (left < n && this.heap[left].weight < this.heap[smallest].weight) {\n smallest = left;\n }\n if (right < n && this.heap[right].weight < this.heap[smallest].weight) {\n smallest = right;\n }\n if (smallest !== i) {\n this.swap(i, smallest);\n i = smallest;\n } else {\n break;\n }\n }\n }\n\n /**\n * Inserts a new item into the heap or updates it if it already exists.\n * @param item The item to insert or update.\n */\n public insert(item: HeapItem): void {\n // If the vertex already exists, perform a decrease-key operation.\n if (this.position.hasOwnProperty(item.vertex)) {\n const i = this.position[item.vertex];\n if (item.weight < this.heap[i].weight) {\n this.heap[i].weight = item.weight;\n this.percolateUp(i);\n }\n return;\n }\n // Otherwise, add it as a new item.\n this.heap.push(item);\n const idx = this.heap.length - 1;\n this.position[item.vertex] = idx;\n this.percolateUp(idx);\n }\n\n /**\n * Removes and returns the minimum element (the root) from the heap.\n * @returns The removed element or undefined if the heap is empty.\n */\n public delete(): HeapItem | undefined {\n if (this.heap.length === 0) return undefined;\n const min = this.heap[0];\n const last = this.heap.pop();\n // Remove mapping for the vertex being removed.\n delete this.position[min.vertex];\n if (this.heap.length > 0 && last !== undefined) {\n this.heap[0] = last;\n this.position[last.vertex] = 0;\n this.percolateDown(0);\n }\n return min;\n }\n\n /**\n * Checks if the heap is empty.\n * @returns True if the heap is empty; otherwise, false.\n */\n public isEmpty(): boolean {\n return this.heap.length === 0;\n }\n\n /**\n * Returns the minimum element of the heap without removing it.\n * @returns The minimum element, or undefined if the heap is empty.\n */\n public findMin(): HeapItem | undefined {\n return this.heap.length > 0 ? this.heap[0] : undefined;\n }\n}\n\n/**\n * Executes Dijkstra's algorithm to find the shortest paths from a source node\n * in a weighted graph.\n *\n * @param graph - The adjacency list representing the graph with weights.\n * @param source - The source node from which to calculate shortest paths.\n * @returns A dictionary where keys are node labels and values represent the shortest distances from the source node.\n */\nexport default function dijkstra(\n graph: Record<string, Record<string, number>>,\n source: string,\n): Record<string, number> {\n const distances: Record<string, number> = {};\n const minHeap = new MinHeap();\n\n // Initialize distances for every vertex.\n for (const vertex in graph) {\n distances[vertex] = vertex === source ? 0 : Infinity;\n minHeap.insert({ vertex, weight: distances[vertex] });\n }\n\n const visited = new Set<string>();\n\n while (!minHeap.isEmpty()) {\n // Extract the vertex with the smallest tentative distance.\n const current = minHeap.delete();\n if (!current) break;\n const { vertex: u } = current;\n if (visited.has(u)) continue;\n visited.add(u);\n\n // For each neighbor of u, update its distance if a shorter path is found.\n for (const neighbor in graph[u]) {\n const newDist = distances[u] + graph[u][neighbor];\n if (newDist < distances[neighbor]) {\n distances[neighbor] = newDist;\n minHeap.insert({ vertex: neighbor, weight: newDist });\n }\n }\n }\n\n return distances;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement Dijkstra's algorithm to find the shortest paths from a source vertex in a graph represented as an adjacency list.",
|
||||
"title": "Dijkstra's Algorithm"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1745539200,
|
||||
"difficulty": "medium",
|
||||
"duration": 20,
|
||||
"excerpt": "Implement Dijkstra's algorithm to find the shortest paths from a source vertex in a graph represented as an adjacency list.",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "dijkstra",
|
||||
"subtitle": null,
|
||||
"title": "Dijkstra's Algorithm",
|
||||
"topics": [
|
||||
"dfs",
|
||||
"graph"
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/heap-sort.submit.test.ts": "import heapSort from './heap-sort';\n\ndescribe('heapSort', () => {\n test('empty', () => {\n expect(heapSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(heapSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(heapSort([2, 1])).toEqual([1, 2]);\n expect(heapSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(heapSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(heapSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(heapSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(heapSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(heapSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(heapSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(heapSort([1, 1])).toEqual([1, 1]);\n expect(heapSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(heapSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(heapSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(heapSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/heap-sort.ts": "export default function heapSort(arr: Array<number>): Array<number> {\n // Begin by building a max heap.\n const size = arr.length;\n for (let i = Math.floor(size / 2 - 1); i >= 0; i--) {\n // Start with the index of the last parent node.\n // heapify: Swaps parent with child as long as child is larger than parent.\n heapify(arr, size, i);\n }\n\n // Iterate through the heap backwards, swapping the last element of the heap with the max element (the root of a max heap).\n // Max elements swapped to the end constitute the sorted part of the array (ignored in the next iteration by \"i--\").\n for (let i = size - 1; i >= 0; i--) {\n [arr[0], arr[i]] = [arr[i], arr[0]];\n\n // Build a max heap again in preparation for the swap in the next iteration.\n heapify(arr, i, 0);\n }\n\n return arr;\n}\n\nfunction heapify(arr: Array<number>, size: number, parentIdx: number) {\n let largest = parentIdx; // Initiate largest value's index with parent index.\n const leftChildIdx = 2 * parentIdx + 1; // Calculate index of left child.\n const rightChildIdx = 2 * parentIdx + 2; // Calculate index of right child.\n // Set `largest` to index with highest value between parent, left and right child.\n // See if left child of parent exists and is larger than parent.\n if (leftChildIdx < size && arr[leftChildIdx] > arr[largest]) {\n largest = leftChildIdx;\n }\n // See if right child of parent exists and is larger than parent.\n if (rightChildIdx < size && arr[rightChildIdx] > arr[largest]) {\n largest = rightChildIdx;\n }\n // If `largest` is not the current parent, swap positions with the current parent.\n if (largest !== parentIdx) {\n [arr[parentIdx], arr[largest]] = [arr[largest], arr[parentIdx]];\n // Continue to recursively heapify the affected subtree.\n heapify(arr, size, largest);\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a heap sort",
|
||||
"title": "Heap Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1673395200,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a function that performs a heap sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -35,7 +38,6 @@
|
|||
],
|
||||
"slug": "heap-sort",
|
||||
"subtitle": null,
|
||||
"title": "Heap Sort",
|
||||
"topics": [
|
||||
"heap",
|
||||
"sorting"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/heap.submit.test.ts": "import Heap from './heap';\n\ndescribe('Heap', () => {\n test('constructor', () => {\n const heap = new Heap<number>();\n expect(heap instanceof Heap).toBeTruthy();\n });\n\n test('insert and findMax', () => {\n const heap = new Heap<number>();\n heap.insert(100);\n expect(heap.findMax()).toBe(100);\n heap.insert(200);\n expect(heap.findMax()).toBe(200);\n heap.insert(50);\n expect(heap.findMax()).toBe(200);\n });\n\n test('delete functionality', () => {\n const heap = new Heap<number>();\n heap.insert(300);\n heap.insert(100);\n heap.insert(200);\n expect(heap.delete()).toBe(300);\n expect(heap.findMax()).toBe(200);\n expect(heap.delete()).toBe(200);\n expect(heap.findMax()).toBe(100);\n heap.insert(400);\n expect(heap.delete()).toBe(400);\n expect(heap.findMax()).toBe(100);\n });\n\n test('heapify from array', () => {\n const array = [5, 3, 17, 10, 84, 19, 6, 22, 9];\n const heap = new Heap<number>(array);\n expect(heap.findMax()).toBe(84);\n expect(heap.delete()).toBe(84);\n expect(heap.findMax()).toBe(22);\n });\n\n test('complex insert and delete sequence', () => {\n const heap = new Heap<number>();\n heap.insert(20);\n heap.insert(15);\n heap.insert(30);\n heap.insert(10);\n expect(heap.findMax()).toBe(30);\n expect(heap.delete()).toBe(30);\n expect(heap.findMax()).toBe(20);\n heap.insert(35);\n heap.insert(45);\n expect(heap.delete()).toBe(45);\n expect(heap.findMax()).toBe(35);\n });\n\n test('delete on empty heap', () => {\n const heap = new Heap<number>();\n expect(heap.delete()).toBeUndefined();\n });\n\n test('maintaining state after multiple operations', () => {\n const heap = new Heap<number>();\n heap.insert(50);\n heap.insert(30);\n heap.insert(60);\n expect(heap.delete()).toBe(60);\n heap.insert(55);\n heap.insert(65);\n expect(heap.findMax()).toBe(65);\n expect(heap.delete()).toBe(65);\n expect(heap.findMax()).toBe(55);\n });\n\n test('integration test of operations', () => {\n const heap = new Heap<number>();\n heap.insert(5);\n heap.insert(3);\n heap.insert(17);\n heap.insert(10);\n heap.insert(84);\n heap.insert(19);\n heap.insert(6);\n heap.insert(22);\n heap.insert(9);\n expect(heap.delete()).toBe(84);\n expect(heap.findMax()).toBe(22);\n heap.insert(55);\n expect(heap.findMax()).toBe(55);\n expect(heap.delete()).toBe(55);\n expect(heap.findMax()).toBe(22);\n });\n});\n",
|
||||
"/src/heap.ts": "export default class Heap<T> {\n values: T[];\n\n constructor(array: T[] = []) {\n this.values = [];\n if (array.length > 0) {\n this.heapify(array);\n }\n }\n\n /**\n * Constructs the initial heap structure with a given `array`.\n * @param array The initial array to be used for the heap.\n */\n heapify(array: T[]): void {\n this.values = [];\n array.forEach((element) => this.insert(element));\n }\n\n /**\n * Adds an item to the heap.\n * @param value The item to be added into the heap.\n */\n insert(value: T): void {\n this.values.push(value);\n let index = this.values.length - 1;\n let parentIndex = Math.floor((index - 1) / 2);\n\n // Move up the newly added value until the heap property is restored.\n while (index > 0 && this.values[parentIndex] < this.values[index]) {\n [this.values[parentIndex], this.values[index]] = [\n this.values[index],\n this.values[parentIndex],\n ];\n index = parentIndex;\n parentIndex = Math.floor((index - 1) / 2);\n }\n }\n\n /**\n * Removes the top of the heap / maximum element.\n * @return The element removed, or undefined if the heap is empty.\n */\n delete(): T | undefined {\n if (this.values.length === 0) {\n return undefined;\n }\n const max = this.values[0];\n const last = this.values.pop();\n if (this.values.length > 0 && last !== undefined) {\n this.values[0] = last;\n let index = 0;\n\n // Restore heap property by moving down the root value.\n while (true) {\n const left = 2 * index + 1;\n const right = 2 * index + 2;\n let largest = index;\n\n // If left child exists and is larger than the current largest, replace largest with value of left child.\n if (\n left < this.values.length &&\n this.values[left] > this.values[largest]\n ) {\n largest = left;\n }\n\n // If right child exists and is larger than the current largest, replace largest with value of right child.\n if (\n right < this.values.length &&\n this.values[right] > this.values[largest]\n ) {\n largest = right;\n }\n\n if (largest === index) {\n break; // The current root is already the largest, heap property is satisfied.\n }\n\n // Swap the position such that the largest value is above `index`, following the heap property.\n [this.values[index], this.values[largest]] = [\n this.values[largest],\n this.values[index],\n ];\n index = largest;\n }\n }\n return max;\n }\n\n /**\n * Returns the value of the maximum element.\n * @return The maximum element.\n */\n findMax(): T | undefined {\n return this.values.length > 0 ? this.values[0] : undefined;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a heap data structure containing essential heap operations",
|
||||
"title": "Heap"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1745539200,
|
||||
"difficulty": "hard",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a heap data structure containing essential heap operations",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -35,7 +38,6 @@
|
|||
],
|
||||
"slug": "heap",
|
||||
"subtitle": null,
|
||||
"title": "Heap",
|
||||
"topics": [
|
||||
"heap"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/insertion-sort.submit.test.ts": "import insertionSort from './insertion-sort';\n\ndescribe('insertionSort', () => {\n test('empty', () => {\n expect(insertionSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(insertionSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(insertionSort([2, 1])).toEqual([1, 2]);\n expect(insertionSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(insertionSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(insertionSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(insertionSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(insertionSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(insertionSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(insertionSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(insertionSort([1, 1])).toEqual([1, 1]);\n expect(insertionSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(insertionSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(insertionSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(insertionSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/insertion-sort.ts": "export default function insertionSort(arr: Array<number>): Array<number> {\n // Iterate through the array, starting with the 2nd element.\n for (let i = 1; i < arr.length; i++) {\n // Store the current value in a variable so it\n // can be shifted to the correct position after the comparisons.\n let currentValue = arr[i];\n\n // Initialize a pointer for the index of the previous element\n // so we can use it to iterate progressively backwards\n // through preceding elements.\n let j = i - 1;\n\n // Keep iterating backwards through preceding elements\n // as long as the previous element is greater than the current value.\n while (j >= 0 && arr[j] > currentValue) {\n // \"Move\" the previous element one position to the right.\n // if it's bigger than currentValue.\n arr[j + 1] = arr[j];\n\n // Decrement the pointer so as to keep comparing with the\n // previous element.\n j--;\n }\n\n // Set the currentValue into its final position.\n arr[j + 1] = currentValue;\n }\n\n // Return the sorted array.\n return arr;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs an insertion sort",
|
||||
"title": "Insertion Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "easy",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a function that performs an insertion sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -35,7 +38,6 @@
|
|||
],
|
||||
"slug": "insertion-sort",
|
||||
"subtitle": null,
|
||||
"title": "Insertion Sort",
|
||||
"topics": [
|
||||
"sorting"
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/linked-list.submit.test.ts": "import LinkedList from './linked-list';\n\ndescribe('LinkedList', () => {\n test('constructor', () => {\n const list = new LinkedList();\n expect(list).toBeInstanceOf(LinkedList);\n });\n\n describe('insert', () => {\n test('insertHead()', () => {\n const list = new LinkedList();\n list.insertHead(200);\n list.insertHead(100);\n expect(list.toArray()).toEqual([100, 200]);\n });\n \n test('insertTail()', () => {\n const list = new LinkedList();\n list.insertTail(100);\n list.insertTail(150);\n list.insertTail(200);\n expect(list.toArray()).toEqual([100, 150, 200]);\n });\n });\n\n describe('get()', () => {\n test('returns correct value at valid index', () => {\n const list = new LinkedList();\n list.insertTail(10);\n list.insertTail(20);\n expect(list.get(0)).toBe(10);\n expect(list.get(1)).toBe(20);\n });\n \n test('returns undefined for out-of-bounds indexes', () => {\n const list = new LinkedList();\n expect(list.get(0)).toBeUndefined();\n list.insertTail(5);\n expect(list.get(1)).toBeUndefined();\n });\n });\n\n test('remove()', () => {\n const list = new LinkedList();\n list.insertHead(100);\n list.insertTail(200);\n expect(list.remove(1)).toBe(200);\n expect(list.length()).toEqual(1);\n expect(list.remove(1)).toBe(undefined);\n expect(list.length()).toEqual(1);\n });\n\n test('remove()', () => {\n const list = new LinkedList();\n expect(list.length()).toEqual(0);\n expect(list.toArray()).toEqual([]);\n list.insertTail(2);\n expect(list.length()).toEqual(1);\n expect(list.toArray()).toEqual([2]);\n list.remove(0);\n expect(list.toArray()).toEqual([]);\n expect(list.length()).toEqual(0);\n });\n\n test('mixed', () => {\n const linked = new LinkedList();\n expect(linked.toArray()).toEqual([]);\n linked.insertTail(1);\n linked.insertHead(2);\n expect(linked.toArray()).toEqual([2, 1]);\n linked.insertTail(3);\n expect(linked.toArray()).toEqual([2, 1, 3]);\n expect(linked.get(1)).toBe(1);\n expect(linked.get(2)).toBe(3);\n expect(linked.remove(1)).toBe(1);\n expect(linked.toArray()).toEqual([2, 3]);\n expect(linked.remove(1)).toBe(3);\n expect(linked.remove(4)).toBe(undefined);\n expect(linked.remove(0)).toBe(2);\n expect(linked.remove(0)).toBe(undefined);\n expect(linked.toArray()).toEqual([]);\n });\n});\n",
|
||||
"/src/linked-list.ts": "class Node<T> {\n value: any;\n next: Node<T> | null;\n\n constructor(value: any, next: Node<T> | null = null) {\n this.value = value;\n this.next = next;\n }\n}\n\nexport default class LinkedList<T> {\n head: Node<T> | null;\n tail: Node<T> | null;\n\n constructor() {\n this.head = null;\n this.tail = null;\n }\n\n /**\n * Adds an item to the head of the linked list.\n * @param {*} value The item to be added to the head of the list.\n */\n insertHead<T>(value: T): void {\n const node = new Node<T>(value, this.head);\n if (this.head == null) {\n this.tail = node;\n }\n this.head = node;\n }\n\n /**\n * Adds an item to the tail of the linked list.\n * @param {*} value The item to be added to the tail of the list.\n */\n insertTail<T>(value: T): void {\n const node = new Node<T>(value);\n if (this.tail == null) {\n this.head = node;\n } else {\n this.tail.next = node;\n }\n this.tail = node;\n }\n\n /**\n * Remove the item in the given index and return its value or `undefined` if index is out of bound.\n * @param {number} i The index of the item to be removed.\n * @return {*} The value of the item in index i if it exists, `undefined` otherwise.\n */\n remove<T>(i: number): T | undefined {\n // To remove index 0, we have to replace the value of head, if it exists.\n if (i === 0 && this.head != null) {\n let value = this.head.value;\n this.head = this.head.next;\n if (this.head == null) {\n this.tail = null;\n } // If there is no node left in the linked list, replace tail with null as well.\n return value;\n }\n\n let curr: Node<T> | null = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i-1 times to reach index i-1.\n for (let j = 1; j < i; j++) {\n if (curr == null || curr.next == null) {\n return undefined;\n } // Return `undefined` if linked list ends before reaching index i.\n\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n if (curr == null || curr.next == null) {\n return undefined;\n }\n\n let value = curr.next.value; // Save the value of the node in index i.\n curr.next = curr.next.next;\n\n // If curr.next, which is to be removed, is the last node in the linked list, update tail to the previous node (curr).\n this.tail = curr.next == null ? curr : this.tail;\n\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return the value of the item in the given index or `undefined` if index is out of bound.\n * @param {number} i The index of the value of the item to be returned.\n * @return {*} The value of the item in index i if it exists, `undefined` otherwise.\n */\n get<T>(i: number): T | undefined {\n let curr: Node<T> | null = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i times to reach index i.\n for (let j = 0; j < i; j++) {\n if (curr == null) {\n return undefined;\n } // Return `undefined` if linked list ends before reaching index i.\n\n curr = curr.next;\n }\n\n let value = curr != null ? curr.value : undefined;\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return an array containing all the values of the items in the linked list from head to tail.\n * @return {*} The array of all the values in the linked list from head to tail.\n */\n toArray<T>(): Array<T> {\n const array: Array<T> = [];\n let curr: Node<T> | null = this.head; // Set a pointer to the first node of the linked list.\n\n // Continue to traverse through the linked list until it reaches the tail (null).\n while (curr != null) {\n array.push(curr.value);\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n return array;\n }\n\n /**\n * Return the length / number of elements in the linked list.\n * @return {*} Length of the linked list.\n */\n length(): number {\n let length = 0;\n let curr = this.head;\n\n while (curr) {\n length += 1;\n curr = curr.next;\n }\n\n return length;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a linked list data structure containing the common linked list methods",
|
||||
"title": "Linked List"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1745539200,
|
||||
"difficulty": "medium",
|
||||
"duration": 20,
|
||||
"excerpt": "Implement a linked list data structure containing the common linked list methods",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -34,7 +37,6 @@
|
|||
],
|
||||
"slug": "linked-list",
|
||||
"subtitle": null,
|
||||
"title": "Linked List",
|
||||
"topics": [
|
||||
"linked-list"
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/merge-sort.submit.test.ts": "import mergeSort from './merge-sort';\n\ndescribe('mergeSort', () => {\n test('empty', () => {\n expect(mergeSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(mergeSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(mergeSort([2, 1])).toEqual([1, 2]);\n expect(mergeSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(mergeSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(mergeSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(mergeSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(mergeSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(mergeSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(mergeSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(mergeSort([1, 1])).toEqual([1, 1]);\n expect(mergeSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(mergeSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(mergeSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(mergeSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/merge-sort.ts": "export default function mergeSort(arr: Array<number>): Array<number> {\n // Return if array only has 0 or 1 elements (base case).\n if (arr.length <= 1) {\n return arr;\n }\n\n // Divide the array into two.\n const midPoint = Math.floor(arr.length / 2);\n const left = arr.slice(0, midPoint);\n const right = arr.slice(midPoint);\n\n // Merge sort each half recursively.\n const sortedLeft = mergeSort(left);\n const sortedRight = mergeSort(right);\n\n // Merge sorted halves.\n return merge(sortedLeft, sortedRight);\n}\n\n/**\n * Merges two sorted arrays of elements into one.\n */\nfunction merge(left: Array<number>, right: Array<number>): Array<number> {\n // Create an empty array to store the merged result.\n const mergedResult = [];\n\n let l = 0;\n let r = 0;\n // Repeatedly compare smallest element from each half\n // and append it to the merged result.\n // When one half runs out of elements,\n // append all the elements of the remaining half to the merged array\n while (l < left.length && r < right.length) {\n if (left[l] < right[r]) {\n mergedResult.push(left[l]);\n l++;\n } else {\n mergedResult.push(right[r]);\n r++;\n }\n }\n\n // Append any remaining elements from each sides.\n mergedResult.push(...left.slice(l), ...right.slice(r));\n return mergedResult;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a recursive merge sort",
|
||||
"title": "Merge Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "medium",
|
||||
"duration": 20,
|
||||
"excerpt": "Implement a function that performs a recursive merge sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "merge-sort",
|
||||
"subtitle": null,
|
||||
"title": "Merge Sort",
|
||||
"topics": [
|
||||
"sorting"
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,10 @@
|
|||
"/src/queue.submit.test.ts": "import Queue from './queue';\n\ndescribe('Queue', () => {\n test('constructor', () => {\n const q = new Queue();\n expect(q instanceof Queue);\n });\n\n test('enqueue()', () => {\n const q = new Queue();\n expect(q.enqueue(100)).toBe(1);\n expect(q.enqueue(200)).toBe(2);\n });\n\n test('dequeue()', () => {\n const q = new Queue();\n q.enqueue(100);\n q.enqueue(200);\n expect(q.dequeue()).toBe(100);\n expect(q.length()).toBe(1);\n expect(q.dequeue()).toBe(200);\n expect(q.length()).toBe(0);\n expect(q.dequeue()).toBe(undefined);\n });\n\n test('isEmpty()', () => {\n const q = new Queue();\n expect(q.isEmpty()).toBeTruthy();\n q.enqueue(100);\n expect(q.isEmpty()).toBeFalsy();\n q.dequeue();\n expect(q.isEmpty()).toBeTruthy();\n });\n\n test('length()', () => {\n const q = new Queue();\n q.enqueue(100);\n expect(q.length()).toBe(1);\n q.enqueue(200);\n expect(q.length()).toBe(2);\n q.dequeue();\n expect(q.length()).toBe(1);\n q.enqueue(300);\n expect(q.length()).toBe(2);\n });\n\n test('front()', () => {\n const q = new Queue();\n q.enqueue(100);\n expect(q.front()).toBe(100);\n q.enqueue(200);\n expect(q.front()).toBe(100);\n q.dequeue();\n expect(q.front()).toBe(200);\n q.enqueue(300);\n expect(q.front()).toBe(200);\n q.dequeue();\n q.dequeue();\n expect(q.front()).toBe(undefined);\n });\n\n test('back()', () => {\n const q = new Queue();\n q.enqueue(100);\n expect(q.back()).toBe(100);\n q.enqueue(200);\n expect(q.back()).toBe(200);\n q.dequeue();\n expect(q.back()).toBe(200);\n q.enqueue(300);\n expect(q.back()).toBe(300);\n q.dequeue();\n q.dequeue();\n expect(q.back()).toBe(undefined);\n });\n\n test('integration', () => {\n const q = new Queue();\n q.enqueue(100);\n expect(q.length()).toBe(1);\n expect(q.dequeue()).toBe(100);\n expect(q.length()).toBe(0);\n q.enqueue(200);\n expect(q.length()).toBe(1);\n expect(q.dequeue()).toBe(200);\n });\n});\n",
|
||||
"/src/queue.ts": "class Node<T> {\n value: T | undefined;\n next: Node<T> | null;\n prev: Node<T> | null;\n\n constructor(value?: T) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nexport default class Queue<T> {\n _dummyHead: Node<T>;\n _dummyTail: Node<T>;\n _length: number;\n\n constructor() {\n this._dummyHead = new Node<T>();\n this._dummyTail = new Node<T>();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n */\n enqueue(item: T) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast!.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n */\n dequeue(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node!.prev;\n this._dummyHead.prev = newFirst;\n newFirst!.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node!.prev = null;\n node!.next = null;\n this._length--;\n return node!.value;\n }\n\n /**\n * Determines if the queue is empty.\n */\n isEmpty(): boolean {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n */\n front(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev!.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n */\n back(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next!.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length(): number {\n return this._length;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a queue data structure containing the common queue methods",
|
||||
"title": "Queue"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": "yangshun",
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1670457600,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement a queue data structure containing the common queue methods",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "queue",
|
||||
"subtitle": null,
|
||||
"title": "Queue",
|
||||
"topics": [
|
||||
"queue"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/quick-sort.submit.test.ts": "import quickSort from './quick-sort';\n\ndescribe('quickSort', () => {\n test('empty', () => {\n expect(quickSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(quickSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(quickSort([2, 1])).toEqual([1, 2]);\n expect(quickSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(quickSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(quickSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(quickSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(quickSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(quickSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(quickSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(quickSort([1, 1])).toEqual([1, 1]);\n expect(quickSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(quickSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(quickSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(quickSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/quick-sort.ts": "/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array<number>} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr: Array<number>, lo: number, hi: number): number {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array<number>} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr: Array<number>, lo: number, hi: number) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {Array<number>} arr The array to be sorted.\n * @return {Array<number>}\n */\nexport default function quickSort(arr: Array<number>) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a recursive quick sort",
|
||||
"title": "Quick Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "medium",
|
||||
"duration": 20,
|
||||
"excerpt": "Implement a function that performs a recursive quick sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
],
|
||||
"slug": "quick-sort",
|
||||
"subtitle": null,
|
||||
"title": "Quick Sort",
|
||||
"topics": [
|
||||
"sorting"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/selection-sort.submit.test.ts": "import selectionSort from './selection-sort';\n\ndescribe('selectionSort', () => {\n test('empty', () => {\n expect(selectionSort([])).toEqual([]);\n });\n\n test('one element', () => {\n expect(selectionSort([1])).toEqual([1]);\n });\n\n test('two elements', () => {\n expect(selectionSort([2, 1])).toEqual([1, 2]);\n expect(selectionSort([1, 2])).toEqual([1, 2]);\n });\n\n test('more than two elements', () => {\n expect(selectionSort([10, 2, 4])).toEqual([2, 4, 10]);\n expect(selectionSort([4, 5, 6, 1, 2, 3])).toEqual([1, 2, 3, 4, 5, 6]);\n expect(selectionSort([1, 2, 3, 4, 5, 0])).toEqual([0, 1, 2, 3, 4, 5]);\n expect(selectionSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(selectionSort([5, 4, 3, 2, 1, 10, 9, 8, 7, 6])).toEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n ]);\n expect(selectionSort([98322, 3242, 876, -234, 34, 12331])).toEqual([\n -234, 34, 876, 3242, 12331, 98322,\n ]);\n });\n\n test('duplicate elements', () => {\n expect(selectionSort([1, 1])).toEqual([1, 1]);\n expect(selectionSort([2, 2, 2])).toEqual([2, 2, 2]);\n expect(selectionSort([2, 1, 2])).toEqual([1, 2, 2]);\n expect(selectionSort([1, 1, 1, 1, 1, 1])).toEqual([1, 1, 1, 1, 1, 1]);\n expect(selectionSort([7, 2, 4, 3, 1, 2])).toEqual([1, 2, 2, 3, 4, 7]);\n });\n});\n",
|
||||
"/src/selection-sort.ts": "export default function selectionSort(arr: Array<number>): Array<number> {\n // Iterate through the unsorted portion of the array.\n for (let i = 0; i < arr.length; i++) {\n // Initialize index of min element to the start\n // of the unsorted section.\n let minIndex = i;\n // Find the min element.\n for (let j = i + 1; j < arr.length; j++) {\n if (arr[j] < arr[minIndex]) {\n minIndex = j;\n }\n }\n\n // Swap the found min element with the first element of the\n // unsorted section.\n [arr[i], arr[minIndex]] = [arr[minIndex], arr[i]];\n\n // By the end of each outer loop iteration,\n // [0, i] are sorted.\n }\n\n return arr;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a selection sort",
|
||||
"title": "Selection Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1671667200,
|
||||
"difficulty": "easy",
|
||||
"duration": 10,
|
||||
"excerpt": "Implement a function that performs a selection sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -35,7 +38,6 @@
|
|||
],
|
||||
"slug": "selection-sort",
|
||||
"subtitle": null,
|
||||
"title": "Selection Sort",
|
||||
"topics": [
|
||||
"sorting"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/stack.submit.test.ts": "import Stack from './stack';\n\ndescribe('Stack', () => {\n test('constructor', () => {\n const s = new Stack();\n expect(s instanceof Stack);\n });\n\n test('push()', () => {\n const s = new Stack();\n expect(s.push(100)).toBe(1);\n expect(s.length()).toBe(1);\n expect(s.push(200)).toBe(2);\n expect(s.length()).toBe(2);\n });\n\n test('pop()', () => {\n const s = new Stack();\n s.push(100);\n expect(s.length()).toBe(1);\n expect(s.pop()).toBe(100);\n expect(s.length()).toBe(0);\n expect(s.pop()).toBe(undefined);\n });\n\n test('isEmpty()', () => {\n const s = new Stack();\n expect(s.isEmpty()).toBeTruthy();\n s.push(100);\n expect(s.isEmpty()).toBeFalsy();\n s.pop();\n expect(s.isEmpty()).toBeTruthy();\n });\n\n test('length()', () => {\n const s = new Stack();\n expect(s.length()).toBe(0);\n s.push(100);\n expect(s.length()).toBe(1);\n s.push(200);\n expect(s.length()).toBe(2);\n s.pop();\n expect(s.length()).toBe(1);\n s.push(300);\n expect(s.length()).toBe(2);\n });\n\n test('peek()', () => {\n const s = new Stack();\n expect(s.peek()).toBe(undefined);\n s.push(100);\n expect(s.peek()).toBe(100);\n s.push(200);\n expect(s.peek()).toBe(200);\n s.pop();\n expect(s.peek()).toBe(100);\n s.push(300);\n expect(s.peek()).toBe(300);\n s.pop();\n s.pop();\n expect(s.peek()).toBe(undefined);\n });\n});\n",
|
||||
"/src/stack.ts": "export default class Stack<T> {\n _items: Array<T>;\n\n constructor() {\n this._items = [];\n }\n\n /**\n * Pushes an item onto the top of the stack.\n */\n push(item: T): number {\n return this._items.push(item);\n }\n\n /**\n * Remove an item at the top of the stack.\n */\n pop(): T | undefined {\n return this._items.pop();\n }\n\n /**\n * Determines if the stack is empty.\n */\n isEmpty(): boolean {\n return this.length() === 0;\n }\n\n /**\n * Returns the item at the top of the stack without removing it from the stack.\n */\n peek(): T | undefined {\n return this.isEmpty() ? undefined : this._items[this.length() - 1];\n }\n\n /**\n * Returns the number of items in the stack.\n */\n length(): number {\n return this._items.length;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a stack data structure containing the common stack methods",
|
||||
"title": "Stack"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": "yangshun",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1670025600,
|
||||
"difficulty": "easy",
|
||||
"duration": 10,
|
||||
"excerpt": "Implement a stack data structure containing the common stack methods",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -37,7 +40,6 @@
|
|||
],
|
||||
"slug": "stack",
|
||||
"subtitle": null,
|
||||
"title": "Stack",
|
||||
"topics": [
|
||||
"stack"
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -9,6 +9,10 @@
|
|||
"/src/sum-without-addition.submit.test.ts": "import sumWithoutAddition from './sum-without-addition';\nimport submitTestCases from './submit.tests.json';\n\ndescribe('sumWithoutAddition', () => {\n submitTestCases.forEach((example: any) => {\n test(`a = ${example.input[0][1]} b = ${example.input[1][1]}`, () => {\n expect(\n sumWithoutAddition(example.input[0][1], example.input[1][1]),\n ).toStrictEqual(example.output);\n });\n });\n});\n",
|
||||
"/src/sum-without-addition.ts": "export default function sumWithoutAddition(a: number, b: number): number {\n // Initialize a variable carry to hold the carry bits generated during each iteration\n let carry: number = 0;\n\n // Loop continues as long as there's a carry bit or bits to process in a or b\n while (b !== 0 || carry !== 0) {\n // Extract the carry bit from the AND operation of a and b\n carry = a & b;\n\n // Use the XOR operation to add a and b without the carry bit\n a = a ^ b;\n\n // Left shift the carry bit for the next iteration\n b = carry << 1;\n }\n\n // Return the final result, which is stored in 'a' after all carry bits have been processed\n return a;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function to find the sum of two integers without using + and - operator",
|
||||
"title": "Sum Without Addition"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": "hiten",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1718928000,
|
||||
"difficulty": "medium",
|
||||
"duration": 35,
|
||||
"excerpt": "Implement a function to find the sum of two integers without using + and - operator",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "sum-without-addition",
|
||||
"subtitle": null,
|
||||
"title": "Sum Without Addition",
|
||||
"topics": [
|
||||
"binary"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
"/src/task-coordination.submit.test.ts": "import taskCoordinator from './task-coordination';\nimport submitTestCases from './submit.tests.json';\n\ndescribe('taskCoordinator', () => {\n (submitTestCases as any[]).forEach((example: any) => {\n test(`tasks = [${example.input[0][1]}] k = ${example.input[1][1]}`, () => {\n expect(\n taskCoordinator(example.input[0][1], example.input[1][1]),\n ).toStrictEqual(example.output);\n });\n });\n});\n",
|
||||
"/src/task-coordination.ts": "export default function taskCoordinator(tasks: string[], k: number): number {\n // Array to store the frequency of each task (26 letters, A-Z)\n const counter: number[] = new Array(26).fill(0);\n let maximum = 0; // Maximum frequency of any task\n let maxCount = 0; // Number of tasks with maximum frequency\n\n // Traverse through tasks to calculate task frequencies\n for (const task of tasks) {\n const index = task.charCodeAt(0) - 'A'.charCodeAt(0);\n counter[index]++;\n\n if (maximum === counter[index]) {\n maxCount++;\n } else if (maximum < counter[index]) {\n maximum = counter[index];\n maxCount = 1;\n }\n }\n\n // Calculate idle slots, available tasks, and idles needed\n const partCount = maximum - 1;\n const partLength = k - (maxCount - 1);\n const emptySlots = partCount * partLength;\n const availableTasks = tasks.length - maximum * maxCount;\n const idles = Math.max(0, emptySlots - availableTasks);\n\n // Return the total time required\n return tasks.length + idles;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function to find minimum intervals for tasks with cooldown",
|
||||
"title": "Task Coordination"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": "hiten",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1725408000,
|
||||
"difficulty": "medium",
|
||||
"duration": 40,
|
||||
"excerpt": "Implement a function to find minimum intervals for tasks with cooldown",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "task-coordination",
|
||||
"subtitle": null,
|
||||
"title": "Task Coordination",
|
||||
"topics": [
|
||||
"greedy",
|
||||
"heap"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/topological-sort.submit.test.ts": "import topologicalSort from './topological-sort';\n\ndescribe('topologicalSort', () => {\n test('empty graph', () => {\n expect(topologicalSort({})).toEqual([]);\n });\n\n test('graphs with one node', () => {\n expect(topologicalSort({ A: [] })).toEqual(['A']);\n });\n\n test('graphs with two nodes', () => {\n expect(topologicalSort({ A: ['B'], B: [] })).toEqual(['A', 'B']);\n expect(topologicalSort({ A: [], B: ['A'] })).toEqual(['B', 'A']);\n });\n\n test('graphs with multiple nodes', () => {\n expect(topologicalSort({ A: ['B', 'C'], B: ['C'], C: [] })).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(\n topologicalSort({\n A: ['B', 'C', 'E'],\n B: ['C'],\n C: [],\n D: ['B'],\n E: ['C', 'D'],\n }),\n ).toEqual(['A', 'E', 'D', 'B', 'C']);\n expect(\n topologicalSort({\n A: ['B', 'C'],\n B: ['C', 'D', 'E'],\n C: ['F'],\n D: [],\n E: ['F'],\n F: [],\n }),\n ).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);\n expect(\n topologicalSort({\n A: ['B', 'C'],\n B: ['C', 'D'],\n C: ['D'],\n D: ['E'],\n E: ['F'],\n F: [],\n }),\n ).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);\n });\n\n test('linked list', () => {\n expect(topologicalSort({ A: ['B'], B: ['C'], C: [] })).toEqual([\n 'A',\n 'B',\n 'C',\n ]);\n expect(\n topologicalSort({\n A: [],\n B: ['A'],\n C: ['B'],\n D: ['C'],\n E: ['D'],\n F: ['E'],\n }),\n ).toEqual(['F', 'E', 'D', 'C', 'B', 'A']);\n });\n\n test('graph with cycles', () => {\n expect(topologicalSort({ A: ['A'] })).toEqual([]);\n expect(topologicalSort({ A: ['A', 'B'], B: [] })).toEqual([]);\n expect(topologicalSort({ A: ['A', 'B'], B: ['A'] })).toEqual([]);\n expect(\n topologicalSort({\n A: ['D', 'E'],\n B: ['A', 'B', 'C', 'D', 'E'],\n C: [],\n D: ['B'],\n E: ['C'],\n }),\n ).toEqual([]);\n });\n});\n",
|
||||
"/src/topological-sort.ts": "export default function topologicalSort(\n graph: Record<string, Array<string>>,\n): Array<string> {\n // Initialize a Map object to store each node's incoming and outgoing edges,\n // an array to store the output topological sort order,\n // and a Queue object to store nodes to be processed\n const nodes = new Map<string, { in: number; out: Set<string> }>();\n const queue = new Queue<string>();\n const order = [];\n\n // Iterating over all the keys in the input graph object\n // add each key to the \"nodes\" Map object\n // with properties \"in\" with value 0\n // and \"out\" with the value of set of neighboring nodes.\n Object.keys(graph).forEach((node) => {\n nodes.set(node, { in: 0, out: new Set(graph[node]) });\n });\n\n // Set the Map with the correct `in` values.\n // Iterating over all the keys in the input graph object,\n // for each node increase the `in` property of its neighbor node by 1.\n Object.keys(graph).forEach((node) => {\n graph[node].forEach((neighbor) => {\n nodes.get(neighbor)!.in += 1;\n });\n });\n\n // Iterate over the nodes and add all the nodes with `in: 0` to the queue.\n nodes.forEach((value, node) => {\n if (value.in === 0) {\n queue.enqueue(node);\n }\n });\n\n // While queue is not empty.\n while (queue.length()) {\n // Dequeue a node from the front of the queue.\n const node = queue.dequeue()!;\n\n // For each neighbor of this dequeued node decrease its `in` property by 1,\n // if the `in` becomes 0, enqueue the neighbor node.\n nodes.get(node)?.out.forEach((neighbor) => {\n nodes.get(neighbor)!.in -= 1;\n if (nodes.get(neighbor)!.in === 0) {\n queue.enqueue(neighbor);\n }\n });\n\n // Add the dequeued node to the output array.\n order.push(node);\n }\n\n // Return topological-ordered array if it has the same length as\n // the number of keys in the graph, otherwise there is a cycle\n // and we return an empty array.\n return order.length === Object.keys(graph).length ? order : [];\n}\n\nclass Node<T> {\n value: T | undefined;\n next: Node<T> | null;\n prev: Node<T> | null;\n\n constructor(value?: T) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nclass Queue<T> {\n _dummyHead: Node<T>;\n _dummyTail: Node<T>;\n _length: number;\n\n constructor() {\n this._dummyHead = new Node<T>();\n this._dummyTail = new Node<T>();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n */\n enqueue(item: T) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast!.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n */\n dequeue(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node!.prev;\n this._dummyHead.prev = newFirst;\n newFirst!.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node!.prev = null;\n node!.next = null;\n this._length--;\n return node!.value;\n }\n\n /**\n * Determines if the queue is empty.\n */\n isEmpty(): boolean {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n */\n front(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev!.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n */\n back(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next!.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length(): number {\n return this._length;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function that performs a topological sort",
|
||||
"title": "Topological Sort"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "free",
|
||||
"author": null,
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1673395200,
|
||||
"difficulty": "medium",
|
||||
"duration": 20,
|
||||
"excerpt": "Implement a function that performs a topological sort",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -37,7 +40,6 @@
|
|||
],
|
||||
"slug": "topological-sort",
|
||||
"subtitle": null,
|
||||
"title": "Topological Sort",
|
||||
"topics": [
|
||||
"topological-sort",
|
||||
"graph"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
"/src/trie-prefix-tree.submit.test.ts": "import Trie from './trie-prefix-tree';\nimport submitTestCases from './submit.tests.json';\n\nfunction processMethods(methods: string[], words: string[]): (number | null)[] {\n const res: (number | null)[] = [];\n const obj = new Trie();\n\n for (let i = 0; i < methods.length; i++) {\n switch (methods[i]) {\n case 'insert': {\n obj.insert(words[i]);\n res.push(null);\n break;\n }\n case 'search': {\n res.push(+obj.search(words[i]));\n break;\n }\n case 'startsWith': {\n res.push(+obj.startsWith(words[i]));\n break;\n }\n }\n }\n\n return res;\n}\n\ndescribe('trie', () => {\n (submitTestCases as any[]).forEach((example: any) => {\n test(`methods = [${example.input[0][1]}] words = [${example.input[1][1]}]`, () => {\n const result = processMethods(example.input[0][1], example.input[1][1]);\n\n expect(result).toStrictEqual(example.output);\n });\n });\n});\n",
|
||||
"/src/trie-prefix-tree.ts": "class TrieNode {\n // Array to hold child nodes\n private links: TrieNode[] = [];\n private static readonly NUM_ALPHABETS = 26; // Number of possible links (a-z)\n private isEnd: boolean = false; // Indicates if this node is the end of a word\n\n constructor() {\n this.links = new Array(TrieNode.NUM_ALPHABETS); // Initialize the array with 26 slots\n }\n\n // Check if a child node for the given character exists\n public containsKey(ch: string): boolean {\n return this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)] !== undefined;\n }\n\n // Get the child node for the given character\n public get(ch: string): TrieNode | undefined {\n return this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)];\n }\n\n // Put a child node for the given character\n public put(ch: string, node: TrieNode): void {\n this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)] = node;\n }\n\n // Set this node as the end of a word\n public setEnd(): void {\n this.isEnd = true;\n }\n\n // Check if this node is the end of a word\n public isEndNode(): boolean {\n return this.isEnd;\n }\n}\n\nexport default class Trie {\n private root: TrieNode = new TrieNode();\n\n constructor() {\n this.root = new TrieNode();\n }\n\n // Inserts a word into the trie\n public insert(word: string): void {\n let node: TrieNode = this.root;\n\n for (let i = 0; i < word.length; i++) {\n const currentChar: string = word.charAt(i);\n if (!node.containsKey(currentChar)) {\n node.put(currentChar, new TrieNode());\n }\n node = node.get(currentChar)!; // Non-null assertion since containsKey checks existence\n }\n\n node.setEnd();\n }\n\n // Search for the prefix or whole key in the trie\n private searchPrefix(word: string): TrieNode | null {\n let node: TrieNode = this.root;\n for (let i = 0; i < word.length; i++) {\n const curLetter: string = word.charAt(i);\n if (node.containsKey(curLetter)) {\n node = node.get(curLetter)!; // Non-null assertion since containsKey checks existence\n } else {\n return null;\n }\n }\n return node;\n }\n\n // Returns if the word is in the trie\n public search(word: string): boolean {\n const node: TrieNode | null = this.searchPrefix(word);\n return node !== null && node.isEndNode();\n }\n\n // Returns if there is any word in the trie that starts with the given prefix\n public startsWith(prefix: string): boolean {\n const node: TrieNode | null = this.searchPrefix(prefix);\n return node !== null;\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a trie-prefix-tree with insert, search, and starts with functionality",
|
||||
"title": "Trie (Prefix Tree)"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": "hiten",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1724976000,
|
||||
"difficulty": "medium",
|
||||
"duration": 40,
|
||||
"excerpt": "Implement a trie-prefix-tree with insert, search, and starts with functionality",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "trie-prefix-tree",
|
||||
"subtitle": null,
|
||||
"title": "Trie (Prefix Tree)",
|
||||
"topics": [
|
||||
"tree",
|
||||
"trie"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
"/src/triplet-sum.submit.test.ts": "import tripletSum from './triplet-sum';\nimport submitTestCases from './submit.tests.json';\n\ndescribe('tripletSum', () => {\n (submitTestCases as any[]).forEach((example: any) => {\n test(`numbers = [${example.input[0][1]}]`, () => {\n expect(tripletSum(example.input[0][1])).toStrictEqual(example.output);\n });\n });\n});\n",
|
||||
"/src/triplet-sum.ts": "export default function tripletSum(numbers: number[]): number[][] {\n const ans: number[][] = [];\n\n // Sort the input array for efficient two-pointer search\n numbers.sort((a, b) => a - b);\n\n for (let i = 0; i < numbers.length - 2; i++) {\n // Skip duplicates: only consider unique starting elements (i)\n if (i > 0 && numbers[i] === numbers[i - 1]) continue;\n\n // Two-pointer approach for remaining elements (j & k)\n let j = i + 1;\n let k = numbers.length - 1;\n\n while (j < k) {\n const sum = numbers[i] + numbers[j] + numbers[k];\n\n if (sum === 0) {\n // Found a triplet, add it to the answer\n ans.push([numbers[i], numbers[j], numbers[k]]);\n\n // Move pointers to skip duplicates\n do {\n j++;\n } while (j < k && numbers[j] === numbers[j - 1]);\n do {\n k--;\n } while (j < k && numbers[k] === numbers[k + 1]);\n } else if (sum < 0) {\n // Move j forward to search for a larger positive number\n j++;\n } else {\n // Move k backward to search for a smaller negative number\n k--;\n }\n }\n }\n\n return ans;\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a function to find all unique triplets with distinct indices that sum to 0",
|
||||
"title": "Triplet Sum"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": "hiten",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1718928000,
|
||||
"difficulty": "medium",
|
||||
"duration": 35,
|
||||
"excerpt": "Implement a function to find all unique triplets with distinct indices that sum to 0",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "triplet-sum",
|
||||
"subtitle": null,
|
||||
"title": "Triplet Sum",
|
||||
"topics": [
|
||||
"array"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
"/src/word-finder.submit.test.ts": "import WordFinder from './word-finder';\nimport submitTestCases from './submit.tests.json';\n\nfunction processMethods(\n methods: string[],\n words: string[],\n): (boolean | null)[] {\n const res: (boolean | null)[] = [];\n const obj = new WordFinder();\n\n for (let i = 0; i < methods.length; i++) {\n switch (methods[i]) {\n case 'addWord': {\n obj.addWord(words[i]);\n res.push(null);\n break;\n }\n case 'search': {\n res.push(obj.search(words[i]));\n break;\n }\n }\n }\n\n return res;\n}\n\ndescribe('WordFinder', () => {\n (submitTestCases as any[]).forEach((example: any) => {\n test(`methods = [${example.input[0][1]}] words = [${example.input[1][1]}]`, () => {\n const result = processMethods(example.input[0][1], example.input[1][1]);\n\n expect(result).toStrictEqual(example.output);\n });\n });\n});\n",
|
||||
"/src/word-finder.ts": "class TrieNode {\n // A map to hold child nodes\n children: Map<string, TrieNode> = new Map();\n // Indicates whether this node is the end of a word\n word: boolean = false;\n}\n\nexport default class WordFinder {\n private trie: TrieNode;\n\n constructor() {\n // Initialize the root of the trie\n this.trie = new TrieNode();\n }\n\n addWord(word: string): void {\n let node = this.trie;\n\n for (const ch of word) {\n // If the character is not already a child node, add it\n if (!node.children.has(ch)) {\n node.children.set(ch, new TrieNode());\n }\n // Move to the next node in the trie\n node = node.children.get(ch)!;\n }\n // Mark the end of the word\n node.word = true;\n }\n\n private searchInNode(word: string, node: TrieNode): boolean {\n for (let i = 0; i < word.length; i++) {\n const ch = word[i];\n // If the character is not found, check if it's a '.'\n if (!node.children.has(ch)) {\n if (ch === '.') {\n // Iterate over all children nodes using forEach\n let found = false;\n node.children.forEach((child) => {\n // Recursively search for the remaining substring in each child node\n if (this.searchInNode(word.substring(i + 1), child)) {\n found = true;\n }\n });\n return found;\n }\n // If the character is not a '.' and not found, return false\n return false;\n } else {\n // If the character is found, move down to the next level in the trie\n node = node.children.get(ch)!;\n }\n }\n // Return true if the current node marks the end of a word\n return node.word;\n }\n\n search(word: string): boolean {\n return this.searchInNode(word, this.trie);\n }\n}\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement a data structure where words can be added and support wildcard searching",
|
||||
"title": "Word Finder"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "standard",
|
||||
"author": "hiten",
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1724976000,
|
||||
"difficulty": "medium",
|
||||
"duration": 45,
|
||||
"excerpt": "Implement a data structure where words can be added and support wildcard searching",
|
||||
"featured": false,
|
||||
"format": "algo",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -33,7 +36,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "word-finder",
|
||||
"subtitle": null,
|
||||
"title": "Word Finder",
|
||||
"topics": [
|
||||
"matrix",
|
||||
"graph",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -7,6 +7,10 @@
|
|||
"/src/array-at.submit.test.ts": "import './array-at';\n\ndescribe('Array.prototype.myAt', () => {\n test('empty array', () => {\n expect([].myAt(0)).toBeUndefined();\n expect([].myAt(-1)).toBeUndefined();\n expect([].myAt(1)).toBeUndefined();\n });\n\n describe('one value', () => {\n const arr = [42];\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(1)).toBeUndefined();\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(-2)).toBeUndefined();\n });\n });\n\n describe('two values', () => {\n const arr = [42, 79];\n\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n expect(arr.myAt(1)).toBe(79);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(79);\n expect(arr.myAt(-2)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(3)).toBeUndefined();\n expect(arr.myAt(-3)).toBeUndefined();\n expect(arr.myAt(-4)).toBeUndefined();\n });\n });\n\n describe('multiple values', () => {\n const arr = [42, 79, 103];\n\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n expect(arr.myAt(1)).toBe(79);\n expect(arr.myAt(2)).toBe(103);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(103);\n expect(arr.myAt(-2)).toBe(79);\n expect(arr.myAt(-3)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(3)).toBeUndefined();\n expect(arr.myAt(4)).toBeUndefined();\n expect(arr.myAt(-4)).toBeUndefined();\n expect(arr.myAt(-5)).toBeUndefined();\n });\n });\n\n test('sparse arrays', () => {\n const arr = [1, 2, , 4];\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(-2)).toBeUndefined();\n });\n});\n",
|
||||
"/src/array-at.ts": "interface Array<T> {\n myAt(index: number): T | undefined;\n}\n\nArray.prototype.myAt = function (index: number) {\n const len = this.length;\n if (index < -len || index >= len) {\n return;\n }\n\n return this[(index + len) % len];\n};\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement the Array.prototype.at() method",
|
||||
"title": "Array.prototype.at"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "premium",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1658102400,
|
||||
"difficulty": "easy",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement the Array.prototype.at() method",
|
||||
"featured": false,
|
||||
"format": "javascript",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -31,7 +34,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "array-at",
|
||||
"subtitle": null,
|
||||
"title": "Array.prototype.at",
|
||||
"topics": []
|
||||
},
|
||||
"skeleton": {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/array-at.submit.test.ts": "import './array-at';\n\ndescribe('Array.prototype.myAt', () => {\n test('empty array', () => {\n expect([].myAt(0)).toBeUndefined();\n expect([].myAt(-1)).toBeUndefined();\n expect([].myAt(1)).toBeUndefined();\n });\n\n describe('one value', () => {\n const arr = [42];\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(1)).toBeUndefined();\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(-2)).toBeUndefined();\n });\n });\n\n describe('two values', () => {\n const arr = [42, 79];\n\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n expect(arr.myAt(1)).toBe(79);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(79);\n expect(arr.myAt(-2)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(3)).toBeUndefined();\n expect(arr.myAt(-3)).toBeUndefined();\n expect(arr.myAt(-4)).toBeUndefined();\n });\n });\n\n describe('multiple values', () => {\n const arr = [42, 79, 103];\n\n test('non-negative', () => {\n expect(arr.myAt(0)).toBe(42);\n expect(arr.myAt(1)).toBe(79);\n expect(arr.myAt(2)).toBe(103);\n });\n\n test('negative', () => {\n expect(arr.myAt(-1)).toBe(103);\n expect(arr.myAt(-2)).toBe(79);\n expect(arr.myAt(-3)).toBe(42);\n });\n\n test('out-of-range', () => {\n expect(arr.myAt(3)).toBeUndefined();\n expect(arr.myAt(4)).toBeUndefined();\n expect(arr.myAt(-4)).toBeUndefined();\n expect(arr.myAt(-5)).toBeUndefined();\n });\n });\n\n test('sparse arrays', () => {\n const arr = [1, 2, , 4];\n expect(arr.myAt(2)).toBeUndefined();\n expect(arr.myAt(-2)).toBeUndefined();\n });\n});\n",
|
||||
"/src/array-at.ts": "interface Array<T> {\n myAt(index: number): T | undefined;\n}\n\nArray.prototype.myAt = function (index: number) {\n const len = this.length;\n if (index < -len || index >= len) {\n return;\n }\n\n return this[(index + len) % len];\n};\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "实现 Array.prototype.at() 方法",
|
||||
"title": "Array.prototype.at"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "premium",
|
||||
"author": null,
|
||||
|
|
@ -14,7 +18,6 @@
|
|||
"created": 1658102400,
|
||||
"difficulty": "easy",
|
||||
"duration": 15,
|
||||
"excerpt": "实现 Array.prototype.at() 方法",
|
||||
"featured": false,
|
||||
"format": "javascript",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -31,7 +34,6 @@
|
|||
"similarQuestions": [],
|
||||
"slug": "array-at",
|
||||
"subtitle": null,
|
||||
"title": "Array.prototype.at",
|
||||
"topics": []
|
||||
},
|
||||
"skeleton": {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/array-concat.submit.test.ts": "import './array-concat';\n\ndescribe('Array.prototype.myConcat', () => {\n test('empty arguments', () => {\n expect([].myConcat()).toStrictEqual([]);\n expect([1, 2, 3].myConcat()).toStrictEqual([1, 2, 3]);\n });\n\n test('empty array', () => {\n expect([].myConcat([])).toStrictEqual([]);\n expect([1].myConcat([])).toStrictEqual([1]);\n expect([1, 2].myConcat([])).toStrictEqual([1, 2]);\n });\n\n test('single array argument', () => {\n expect([1].myConcat([2])).toStrictEqual([1, 2]);\n expect([1, 2, 3].myConcat([4, 5, 6])).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n\n test('multiple arrays arguments', () => {\n expect([1, 2, 3].myConcat([4, 5, 6], [7, 8, 9])).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9,\n ]);\n });\n\n test('primitive arguments', () => {\n expect([1, 2].myConcat(3, 4)).toStrictEqual([1, 2, 3, 4]);\n expect([1, 2, 3].myConcat(4, 5, 6)).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n\n test('mixed arguments', () => {\n expect([1, 2, 3].myConcat([4, 5, 6], 7)).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n expect([1, 2, 3].myConcat(4, [5, 6, 7])).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n expect([1, 2, 3].myConcat(4, [5, 6], 7)).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n });\n\n test('sparse arrays', () => {\n const combined = [1, , 2].myConcat(3, 4);\n expect(combined).toHaveLength(5);\n expect(combined[0]).toBe(1);\n expect(combined[2]).toBe(2);\n expect(combined[3]).toBe(3);\n expect(combined[4]).toBe(4);\n });\n\n test('new array is returned', () => {\n const orig = [1, 2, 3];\n const res = orig.myConcat([4, 5, 6]);\n expect(res).toStrictEqual([1, 2, 3, 4, 5, 6]);\n\n orig.push(4);\n expect(res).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n});\n",
|
||||
"/src/array-concat.ts": "interface Array<T> {\n myConcat(...items: Array<T | Array<T>>): Array<T>;\n}\n\nArray.prototype.myConcat = function (...items) {\n const newArray = [...this];\n\n for (let i = 0; i < items.length; i++) {\n if (Array.isArray(items[i])) {\n newArray.push(...items[i]);\n } else {\n newArray.push(items[i]);\n }\n }\n\n return newArray;\n};\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "Implement the Array.prototype.concat() method",
|
||||
"title": "Array.prototype.concat"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "premium",
|
||||
"author": null,
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1699574400,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "Implement the Array.prototype.concat() method",
|
||||
"featured": true,
|
||||
"format": "javascript",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -37,7 +40,6 @@
|
|||
],
|
||||
"slug": "array-concat",
|
||||
"subtitle": null,
|
||||
"title": "Array.prototype.concat",
|
||||
"topics": []
|
||||
},
|
||||
"skeleton": {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
"/src/array-concat.submit.test.ts": "import './array-concat';\n\ndescribe('Array.prototype.myConcat', () => {\n test('empty arguments', () => {\n expect([].myConcat()).toStrictEqual([]);\n expect([1, 2, 3].myConcat()).toStrictEqual([1, 2, 3]);\n });\n\n test('empty array', () => {\n expect([].myConcat([])).toStrictEqual([]);\n expect([1].myConcat([])).toStrictEqual([1]);\n expect([1, 2].myConcat([])).toStrictEqual([1, 2]);\n });\n\n test('single array argument', () => {\n expect([1].myConcat([2])).toStrictEqual([1, 2]);\n expect([1, 2, 3].myConcat([4, 5, 6])).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n\n test('multiple arrays arguments', () => {\n expect([1, 2, 3].myConcat([4, 5, 6], [7, 8, 9])).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7, 8, 9,\n ]);\n });\n\n test('primitive arguments', () => {\n expect([1, 2].myConcat(3, 4)).toStrictEqual([1, 2, 3, 4]);\n expect([1, 2, 3].myConcat(4, 5, 6)).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n\n test('mixed arguments', () => {\n expect([1, 2, 3].myConcat([4, 5, 6], 7)).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n expect([1, 2, 3].myConcat(4, [5, 6, 7])).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n expect([1, 2, 3].myConcat(4, [5, 6], 7)).toStrictEqual([\n 1, 2, 3, 4, 5, 6, 7,\n ]);\n });\n\n test('sparse arrays', () => {\n const combined = [1, , 2].myConcat(3, 4);\n expect(combined).toHaveLength(5);\n expect(combined[0]).toBe(1);\n expect(combined[2]).toBe(2);\n expect(combined[3]).toBe(3);\n expect(combined[4]).toBe(4);\n });\n\n test('new array is returned', () => {\n const orig = [1, 2, 3];\n const res = orig.myConcat([4, 5, 6]);\n expect(res).toStrictEqual([1, 2, 3, 4, 5, 6]);\n\n orig.push(4);\n expect(res).toStrictEqual([1, 2, 3, 4, 5, 6]);\n });\n});\n",
|
||||
"/src/array-concat.ts": "interface Array<T> {\n myConcat(...items: Array<T | Array<T>>): Array<T>;\n}\n\nArray.prototype.myConcat = function (...items) {\n const newArray = [...this];\n\n for (let i = 0; i < items.length; i++) {\n if (Array.isArray(items[i])) {\n newArray.push(...items[i]);\n } else {\n newArray.push(items[i]);\n }\n }\n\n return newArray;\n};\n"
|
||||
},
|
||||
"info": {
|
||||
"excerpt": "实现 Array.prototype.concat() 方法",
|
||||
"title": "Array.prototype.concat"
|
||||
},
|
||||
"metadata": {
|
||||
"access": "premium",
|
||||
"author": null,
|
||||
|
|
@ -16,7 +20,6 @@
|
|||
"created": 1699574400,
|
||||
"difficulty": "medium",
|
||||
"duration": 15,
|
||||
"excerpt": "实现 Array.prototype.concat() 方法",
|
||||
"featured": true,
|
||||
"format": "javascript",
|
||||
"frameworkDefault": null,
|
||||
|
|
@ -37,7 +40,6 @@
|
|||
],
|
||||
"slug": "array-concat",
|
||||
"subtitle": null,
|
||||
"title": "Array.prototype.concat",
|
||||
"topics": []
|
||||
},
|
||||
"skeleton": {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue