This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://gist.github.com/carefree-ladka/f141d0efcefb0260f380daea7cdab425 | |
| class TreeNode { | |
| constructor(val) { | |
| this.val = val; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from 'react'; | |
| const InfiniteScroll = () => { | |
| const [data, setData] = useState([]); | |
| const [page, setPage] = useState(1); // Track current page | |
| const [loading, setLoading] = useState(false); // Track loading state | |
| const fetchData = async () => { | |
| setLoading(true); // Set loading state | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FenwickTree { | |
| constructor(size) { | |
| this.size = size; | |
| this.tree = Array(size + 1).fill(0); // Fenwick Tree array with 1-based indexing | |
| } | |
| update(index, delta) { | |
| // Update the tree with the delta | |
| for (let i = index; i <= this.size; i += i & -i) { | |
| this.tree[i] += delta; // Add delta to the current value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SegmentTree { | |
| constructor(arr) { | |
| this.arr = arr | |
| this.n = arr.length; | |
| this.tree = Array(4 * this.n).fill(0); | |
| this.#build(arr, 0, 0, this.n - 1); | |
| } | |
| #build = (arr, node, start, end) => { | |
| if (start === end) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TrieNode { | |
| constructor() { | |
| this.children = {}; | |
| this.isEndOfWord = false; | |
| this.word = null; // Store the complete word ending at this node | |
| } | |
| } | |
| class Trie { | |
| constructor() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SegmentTree { | |
| constructor(arr) { | |
| this.n = arr.length; | |
| this.treeSum = Array(4 * this.n).fill(0); | |
| this.treeMin = Array(4 * this.n).fill(Infinity); | |
| this.treeMax = Array(4 * this.n).fill(-Infinity); | |
| this.build(arr, 0, 0, this.n - 1); | |
| } | |
| build(arr, node, start, end) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TreeNode { | |
| constructor(val = 0, left = null, right = null) { | |
| this.val = val; | |
| this.left = left; | |
| this.right = right; | |
| } | |
| } | |
| const buildTree = (arr) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function partition(arr, lo, hi, compare) { | |
| // Choose a random pivot and move it to the start | |
| const randomIndex = Math.floor(Math.random() * (hi - lo + 1)) + lo; | |
| swap(arr, lo, randomIndex); | |
| const pivot = arr[lo]; | |
| let i = lo + 1; // Start just after the pivot | |
| let j = hi; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MinMaxPriorityQueue { | |
| #heap = [] | |
| #compare; | |
| constructor(compare = (a, b) => a - b) { | |
| this.#compare = compare; // Default to Min-Heap if no compare function is provided | |
| } | |
| // Add a new element to the priority queue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \documentclass[letterpaper,11pt]{article} | |
| \usepackage{latexsym} | |
| \usepackage[empty]{fullpage} | |
| \usepackage{titlesec} | |
| \usepackage{marvosym} | |
| \usepackage[usenames,dvipsnames]{color} | |
| \usepackage{enumitem} | |
| \usepackage[hidelinks]{hyperref} | |
| \usepackage{fancyhdr} |