MCPcopy Create free account

hub / github.com/PinkyJie/leetcode-patterns / functions

Functions252 in github.com/PinkyJie/leetcode-patterns

↓ 109 callersMethodpush
(item)
_utils.js:101
↓ 72 callersMethodpush
* * Time: O(log(n)) * * @param {number} num * @return void
13_top-k-elements/895_maximum-frequency-stack.js:66
↓ 42 callersMethodsize
()
_utils.js:25
↓ 35 callersMethodpop
()
_utils.js:106
↓ 34 callersFunctionbuildTreeBFS
(array)
_utils.js:171
↓ 29 callersMethodpeek
()
_utils.js:29
↓ 22 callersFunctionbuildLinkedList
(array)
_utils.js:154
↓ 21 callersMethodpop
* * Time: O(log(n)) * * @return {number}
13_top-k-elements/895_maximum-frequency-stack.js:86
↓ 14 callersFunctionprintLinkedList
(head)
_utils.js:144
↓ 9 callersMethodget
(index)
11_binary-search/702_search-in-a-sorted-array-of-unknown-size.js:70
↓ 6 callersFunctionfindKthSmallestNumberWithHeap
* * Problem: * Given an unsorted array of numbers, find Kth smallest number in it. * * Example 1: * Input: [1, 5, 12, 2, 11, 5], K = 3 * Output:
13_top-k-elements/0_kth-smallest-element-in-an-array.js:28
↓ 6 callersFunctionfindKthSmallestNumberWithQuickSort
* Time: O(n) the original quick sort time complexity is O(n log(n)), where log(n) is * the tree depth, for each tree level, it requires O(n) to do pa
13_top-k-elements/0_kth-smallest-element-in-an-array.js:70
↓ 5 callersFunctionfindMinimumDifferentElement
* * Problem: * Given an array of numbers sorted in ascending order, find the element in the array * that has the minimum difference with the given
11_binary-search/0_minimum-difference-element.js:25
↓ 5 callersFunctionsearchBitonicArray
* * Problem: * Given a Bitonic array, find if a given 'key' is present in it. An array is considered * bitonic if it is monotonically increasing an
11_binary-search/0_search-bitonic-array.js:26
↓ 5 callersFunctionsearchRotatedArray
* * Problem: * Given an array of numbers which is sorted in ascending order and also rotated by some * arbitrary number, find if a given 'key' is p
11_binary-search/33_search-in-rotated-sorted-array.js:28
↓ 4 callersFunction_getNextIndex
* Get the next index based on the `currentIndex`.
3_fast-slow-pointers/457_circular-array-loop.js:91
↓ 4 callersFunction_printTreeLevelNodesWithNext
(root)
7_BFS/116_populating-next-right-pointers-in-each-node.js:127
↓ 4 callersMethodadd
* * Time: O(log(k)) * * @param {number} val
13_top-k-elements/703_kth-largest-element-in-a-stream.js:55
↓ 4 callersFunctionceilingOfNumber
* * Problem: * Given an array of numbers sorted in an ascending order, find the ceiling of a given * number 'key'. The ceiling of the 'key' will be
11_binary-search/0_ceiling-of-a-number.js:28
↓ 4 callersFunctionfindBitonicArrayMaximum
* * Problem: * Find the maximum index in a given Bitonic array. An array is considered bitonic if it * is monotonically increasing and then monoton
11_binary-search/162_bitonic-array-maximum.js:25
↓ 4 callersFunctionsearchInUnknownSizeArray
* * Problem: * Given an infinite sorted array (or an array with unknown size), find if a given * number "key" is present in the array. Write a func
11_binary-search/702_search-in-a-sorted-array-of-unknown-size.js:31
↓ 3 callersMethod_getParentIndex
(index)
_utils.js:37
↓ 3 callersFunction_getSumOfAllDigitsSquare
(number)
3_fast-slow-pointers/202_happy-number.js:61
↓ 3 callersFunction_swap
(array, i, j)
13_top-k-elements/0_kth-smallest-element-in-an-array.js:114
↓ 3 callersFunctionbinarySearchWithUnknownOrder
* * Problem: * Given a sorted array of numbers, find if a given number key is present in the array. * Though we know that the array is sorted, we d
11_binary-search/0_order-agnostic-binary-search.js:26
↓ 3 callersFunctioncanPartitionToEqualSum1
* * Solution 1: recursive brute force. * * @param {number[]} nums * @return {boolean}
15_dynamic-programming/416_partition-equal-subset-sum.js:34
↓ 3 callersFunctioncanReconstructUniqueSequence
* * Problem: * Given a sequence originalSeq and an array of sequences, write a method to find if * originalSeq can be uniquely reconstructed from t
16_topological-sort/444_sequence-reconstruction.js:34
↓ 3 callersFunctionfindAlienDictionaryOrder
* * Problem: * There is a dictionary containing words from an alien language for which we don’t know * the ordering of the alphabets. Write a metho
16_topological-sort/269_alien-dictionary.js:41
↓ 3 callersFunctionfindAllTasksSchedulingOrders
* * Problem: * There are N tasks, labeled from 0 to N-1. Each task can have some prerequisite * tasks which need to be completed before it can be s
16_topological-sort/0_all-tasks-scheduling-orders.js:39
↓ 3 callersFunctionfindCycleStartInLinkedList
* * Problem: * Given the head of a Singly LinkedList that contains a cycle, write a function to * find the starting node of the cycle. * https://l
3_fast-slow-pointers/142_linked-list-cycle-ii.js:16
↓ 3 callersFunctionfindMiddleOfLinkedList
* * Problem: * Given the head of a Singly LinkedList, write a method to return the middle node of * the LinkedList. If the total number of nodes in
3_fast-slow-pointers/876_middle-of-the-linked-list.js:25
↓ 3 callersFunctionfindMinHeightTrees
* * Problem: * We are given an undirected graph that has characteristics of a k-ary tree. In such a * graph, we can choose any node as the root to
16_topological-sort/310_minimum-height-trees.js:43
↓ 3 callersFunctionfindMissingNumber
* * Problem: * We are given an array containing n distinct numbers taken from the range 0 to * n. Since the array has only n numbers out of the tot
5_cyclic-sort/268_missing-number.js:23
↓ 3 callersFunctionfindMissingNumber
* * Problem: * We are given an array containing n distinct numbers taken from the range 0 to * n. Since the array has only n numbers out of the tot
12_bitwise-xor/268_missing-number.js:23
↓ 3 callersFunctionfindNumberRange
* * Problem: * Given an array of numbers sorted in ascending order, find the range of a given * number "key". The range of the "key" will be the fi
11_binary-search/34_find-first-and-last-position-of-element-in-sorted-array.js:25
↓ 3 callersFunctionfindRightInterval
* * Problem: * Given an array of intervals, find the next interval of each interval. In a list of * intervals, for an interval `i` its next interva
9_two-heaps/436_find-right-interval.js:34
↓ 3 callersFunctionfindTargetSumWays1
* * Solution 1: recursive brute force. * * @param {number[]} nums * @param {number} targetSum * @return {number}
15_dynamic-programming/494_target-sum.js:30
↓ 3 callersFunctionfindTargetSumWays2
* * Solution 2: top-down dynamic programming with memoization. * The only changing variable are again `currentIndex` and `targetSum`, the possible
15_dynamic-programming/494_target-sum.js:80
↓ 3 callersFunctionfindTargetSumWays3
* * Solution 3: bottom-up dynamic programming. * The meaning of `dp[i][j]` is given the first i numbers, how many ways we can find * to make its "s
15_dynamic-programming/494_target-sum.js:134
↓ 3 callersFunctionfindTargetSumWays4
* * Solution 4: bottom-up dynamic programming with reduced space. * * Time: O(mn) m: 2 * targetSum * Space: O(m) <- for `dp` and `cache` * * @pa
15_dynamic-programming/494_target-sum.js:220
↓ 3 callersFunctionfindTargetSumWays5
* Solution 5: Smaller sum range. * Based on the above analysis, the sum range for DP will be [-totalSum, totalSum], * we can shrink this range by ut
15_dynamic-programming/494_target-sum.js:279
↓ 3 callersFunctionhasLoopInCircularArray
* * Problem: * We are given an array containing positive and negative numbers. Suppose the array * contains a number M at a particular index. Now,
3_fast-slow-pointers/457_circular-array-loop.js:34
↓ 3 callersFunctionminimumSubsetSumDiff1
* * Solution 1: recursive brute force. * * @param {number[]} nums * @return {number}
15_dynamic-programming/0_minimum-subset-sum-difference.js:30
↓ 3 callersFunctionminimumSubsetSumDiff2
* * Solution 2: top-down dynamic programming with memoization. * * @param {number[]} nums * @return {number}
15_dynamic-programming/0_minimum-subset-sum-difference.js:90
↓ 3 callersFunctionminimumSubsetSumDiff3
* * Solution 3: bottom-up dynamic programming. * How to derive the formula from row `i - 1` to row `i`? From the above solutions * we know that the
15_dynamic-programming/0_minimum-subset-sum-difference.js:144
↓ 3 callersFunctionminimumSubsetSumDiff4
* * Solution 4: bottom-up dynamic programming with reduced space. * * Time: O(mn) m: total sum * Space: O(m) * * @param {number[]} nums * @retu
15_dynamic-programming/0_minimum-subset-sum-difference.js:186
↓ 3 callersFunctionrearrangeStringWithKDistanceApart
* * Problem: * Given a string and a number K, find if the string can be rearranged such that the * same characters are at least K distance apart fr
13_top-k-elements/358_rearrange-string-k-distance-apart.js:28
↓ 3 callersFunctionreorganizeString1
* * Problem: * Given a string, find if its letters can be rearranged in such a way that no two * same characters come next to each other. * https:
13_top-k-elements/767_reorganize-string.js:27
↓ 3 callersFunctionreorganizeString2
* * Another solution with better time complexity. * * Time: O(n) * Space: O(n) <- for `freqMap` and `buckets` * * @param {string} str * @return
13_top-k-elements/767_reorganize-string.js:88
↓ 3 callersMethodtoArray
()
_utils.js:33
↓ 2 callersFunctionLongestSubstringWithAtMostKDistinctCharacters
* * Problem: * Given a string, find the length of the longest substring in it with no more than * K distinct characters. * https://leetcode.com/pr
1_sliding-window/340_longest-substring-with-at-most-k-distinct-characters.js:25
↓ 2 callersMethod_getLeftChildIndex
(index)
_utils.js:45
↓ 2 callersFunction_getNextIndex
(str, startIndex)
2_two-pointers/844_backspace-string-compare.js:55
↓ 2 callersMethod_getRightChildIndex
(index)
_utils.js:53
↓ 2 callersMethod_hasParent
(index)
_utils.js:41
↓ 2 callersMethod_heapifyDown
(index)
_utils.js:73
↓ 2 callersMethod_heapifyUp
(index)
_utils.js:61
↓ 2 callersFunction_printNodesWithNext
(root)
7_BFS/0_connect-all-level-order-siblings.js:52
↓ 2 callersFunction_reBalanceHeaps
(smallerPart, largerPart)
9_two-heaps/480_sliding-window-median.js:73
↓ 2 callersFunction_recursive
* * For each number, we have 2 options: make it positive or make it negative, so it's * similar as the 0_0-1-knapsack problem (choose or skip). One
15_dynamic-programming/494_target-sum.js:49
↓ 2 callersFunction_recursive
* * Similar as the problem 416_partition-equal-subset-sum, the only difference here * is we need to return the count, so if we have a match return 1
15_dynamic-programming/0_count-of-subset-sum.js:54
↓ 2 callersFunction_recursive
* * Time: O(2^n) <- for each number, we can choose to select or skip, 2 options. * Space: O(nm) m: targetSum <- for recursion stack * * @param {*}
15_dynamic-programming/416_partition-equal-subset-sum.js:56
↓ 2 callersFunction_recursive
* * Consider we have two subsets S1 and S2, we have `S1 + S2 = totalSum`, if we assume * S1's sum is less than S2, we can get `S2 - diff + S2 = tota
15_dynamic-programming/0_minimum-subset-sum-difference.js:57
↓ 2 callersFunction_recursive
* * We can think about the whole process as a decision tree. For example, * Item: A B C * Weights: 1 2 3 * Profits: 1 6
15_dynamic-programming/0_0-1-knapsack.js:67
↓ 2 callersMethod_removeIndex
(index)
_utils.js:115
↓ 2 callersFunction_reverse
* * Reverse the linked list from node p (inclusive) and node q (exclusive). * * @param {ListNode} p * @param {ListNode} q * @return {ListNode}
6_in-place-reversal-of-a-linked-list/25_reverse-nodes-in-k-group.js:87
↓ 2 callersFunction_swap
(array, i, j)
_utils.js:135
↓ 2 callersFunction_swap
(array, i, j)
2_two-pointers/75_sort-colors.js:69
↓ 2 callersFunctionaverageOfLevel
* * Problem: * Given a binary tree, populate an array to represent the averages of all of its * levels. * https://leetcode.com/problems/average-of
7_BFS/637_average-of-levels-in-binary-tree.js:26
↓ 2 callersFunctionbackspaceStringCompare
* * Problem: * Given two strings containing backspaces (identified by the character ‘#’), check if the * two strings are equal. Note that after bac
2_two-pointers/844_backspace-string-compare.js:26
↓ 2 callersFunctioncanAttendAllAppointments
* * Problem: * Given an array of intervals representing ‘N’ appointments, find out if a person * can attend all the appointments. * * Example 1:
4_merge-intervals/0_conflicting-appointments.js:25
↓ 2 callersFunctioncombinationSum2
* * Problem: * Given a collection of candidate numbers (`candidates`) and a target number * (`target`), find all unique combinations in `candidates
10_subsets/40_combination-sum-ii.js:36
↓ 2 callersFunctionconnectAllLevelNodeSiblings
* * Problem: * Given a binary tree, connect each node with its level order successor. The last * node of each level should point to the first node
7_BFS/0_connect-all-level-order-siblings.js:20
↓ 2 callersFunctionconnectLevelNodeSibling
* * Problem: * Given a binary tree, connect each node with its level order successor. The last * node of each level should point to a null node. *
7_BFS/116_populating-next-right-pointers-in-each-node.js:17
↓ 2 callersFunctioncountOfSubsetSum1
* * Solution 1: recursive brute force. * * @param {number[]} nums * @param {number} targetSum * @return {number}
15_dynamic-programming/0_count-of-subset-sum.js:35
↓ 2 callersFunctioncountOfSubsetSum2
* * Solution 2: top-down dynamic programming with memoization. * * @param {number[]} nums * @param {number} targetSum * @return {number}
15_dynamic-programming/0_count-of-subset-sum.js:78
↓ 2 callersFunctioncountOfSubsetSum3
* * Solution 3: bottom-up dynamic programming. * The meaning of `dp[i][j]` here is given the first i numbers in the array, * what is the count of a
15_dynamic-programming/0_count-of-subset-sum.js:118
↓ 2 callersFunctioncountOfSubsetSum4
* * Solution 4: bottom-up dynamic programming with reduced space. * * Time: O(mn) m: `targetSum` * Space: O(m) <- for `dp` * * @param {number[]}
15_dynamic-programming/0_count-of-subset-sum.js:155
↓ 2 callersFunctioncountPathOfSum
* * Problem: * Given a binary tree and a number S, find all paths in the tree such that the sum * of all the node values of each path equals S. Ple
8_DFS/437_path-sum-iii.js:30
↓ 2 callersFunctioncountUniqueBST
* * Problem: * Given a number n, write a function to return the count of structurally unique Binary * Search Trees (BST) that can store values 1 to
17_divide-and-conquer/96_unique-binary-search-trees.js:26
↓ 2 callersFunctioncyclicSort
* * Problem: * Given an array containing all the number from 1 to n without any duplicates, write * a function to sort the array in-place in O(n) a
5_cyclic-sort/0_cyclic-sort.js:21
↓ 2 callersFunctiondetectCycleInLinkedList
* * Problem: * Given the head of a Singly LinkedList, write a function to determine if the * LinkedList has a cycle in it or not. * https://leetco
3_fast-slow-pointers/141_linked-list-cycle.js:16
↓ 2 callersFunctiondiameterOfBinaryTree
* * Problem: * Given a binary tree, find the length of its diameter. The diameter of a tree is * the number of nodes on the longest path between an
8_DFS/543_diameter-of-binary-tree.js:30
↓ 2 callersFunctiondifferentWaysToEvaluateExpression
* * Problem: * Given an expression containing digits and operations (+, -, *), find all possible * ways in which the expression can be evaluated by
17_divide-and-conquer/241_different-ways-to-add-parentheses.js:39
↓ 2 callersFunctionfindAllAnagramsInString
* * Problem: * Given a string and a pattern, find all anagrams of the pattern in the given string. * "Anagram" is actually a Permutation of a strin
1_sliding-window/438_find-all-anagrams-in-a-string.js:31
↓ 2 callersFunctionfindAllDuplicateNumbers
* * Problem: * We are given an unsorted array containing n numbers taken from the range 1 to n. * The array has some numbers appearing twice, find
5_cyclic-sort/442_find-all-duplicates-in-an-array.js:23
↓ 2 callersFunctionfindAllMissingNumbers
* * Problem: * We are given an unsorted array containing numbers taken from the range 1 to n. * The array can have duplicates, which means some num
5_cyclic-sort/448_find-all-numbers-disappeared-in-an-array.js:25
↓ 2 callersFunctionfindComplementOfBase10Integer
* * Problem: * Every non-negative integer N has a binary representation, for example, 8 can be * represented as "1000" in binary and 7 as "0111" in
12_bitwise-xor/1009_complement-of-base-10-integer.js:31
↓ 2 callersFunctionfindCorruptPair
* * Problem: * We are given an unsorted array containing n numbers taken from the range 1 to n. * The array originally contained all the numbers fr
5_cyclic-sort/0_find-the-corrupt-pair.js:26
↓ 2 callersFunctionfindDuplicateNumber
* * Problem: * We are given an unsorted array containing n+1 numbers taken from the range 1 to * n. The array has only one duplicate but it can be
5_cyclic-sort/287_find-the-duplicate-number.js:24
↓ 2 callersFunctionfindDuplicateNumberWithoutModify
* * How to do this without modifying the array? * * We can think about the array as a linked list, take `[1, 4, 4, 3, 2]` as an * example, array c
5_cyclic-sort/287_find-the-duplicate-number.js:66
↓ 2 callersFunctionfindEmployeeFreeTime
* * Problem: * For K employees, we are given a list of intervals representing the working hours * of each employee. Our goal is to find out if ther
4_merge-intervals/759_employee-free-time.js:28
↓ 2 callersFunctionfindFirstKMissingPositiveNumbers
* * Problem: * Given an unsorted array containing numbers and a number ‘k’, find the first ‘k’ * missing positive numbers in the array. * * Examp
5_cyclic-sort/0_find-first-k-missing-positive-numbers.js:24
↓ 2 callersFunctionfindKClosestElements
* * Problem: * Given a sorted number array and two integers K and X, find K closest numbers to * X in the array. Return the numbers in the sorted o
11_binary-search/658_find-k-closest-elements.js:27
↓ 2 callersFunctionfindKClosestPointsToOrigin
* * Problem: * Given an array of points in the a 2D plane, find K closest points to the origin * (0, 0). Here, the distance between two points on a
13_top-k-elements/973_k-closest-points-to-origin.js:29
↓ 2 callersFunctionfindKPairsWithSmallestSums
* * Problem: * Given two sorted arrays in ascending order, find K pairs with the smallest sum where * each pair consists of numbers from both the a
14_k-way-merge/373_find-k-pairs-with-smallest-sums.js:31
↓ 2 callersFunctionfindKPairsWithSmallestSums2
* * We can also think about this problem as "Merge 2 sorted lists", here the "list" is * not the original array, instead we need to construct a list
14_k-way-merge/373_find-k-pairs-with-smallest-sums.js:90
↓ 2 callersFunctionfindKthLargestNumber
* * Problem: * Given an unsorted array of numbers, find the Kth largest numbers in it. * https://leetcode.com/problems/kth-largest-element-in-an-ar
13_top-k-elements/215_kth-largest-element-in-an-array.js:25
↓ 2 callersFunctionfindLeastNumberOfUniqueIntegersAfterRemovingKElements
* * Problem: * Given an array of integers and an integer k. Find the least number of unique * integers after removing exactly k elements. * https:
13_top-k-elements/1481_least-number-of-unique-integers-after-k-removals.js:30
↓ 2 callersFunctionfindLetterCaseStringPermutation
* * Problem: * Given a string, find all of its permutations preserving the character sequence but * changing case. * https://leetcode.com/problems
10_subsets/784_letter-case-permutation.js:23
next →1–100 of 252, ranked by callers