MCPcopy Create free account

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

Functions252 in github.com/PinkyJie/leetcode-patterns

↓ 2 callersFunctionfindMaximumDistinctElementsAfterRemovingKElements
* * Problem: * Given an array of numbers and a number K, we need to remove K numbers from the * array such that we are left with maximum distinct n
13_top-k-elements/0_maximum-distinct-elements-after-removing-k-elements.js:33
↓ 2 callersFunctionfindMinCostToConnectSticks
* * Problem: * Given N sticks with different lengths, we need to connect these sticks into one big * rope with minimum cost. The cost of connecting
13_top-k-elements/1167_minimum-cost-to-connect-sticks.js:30
↓ 2 callersFunctionfindMinimumInRotatedArray
* * Problem: * Given an array of numbers which is sorted in ascending order and also rotated by some * arbitrary number, find the minimum number in
11_binary-search/154_find-minimum-in-rotated-sorted-array-ii.js:25
↓ 2 callersFunctionfindMinimumInRotatedArray
* * Problem: * Given an array of numbers which is sorted in ascending order and also rotated by some * arbitrary number, find the minimum number in
11_binary-search/153_find-minimum-in-rotated-sorted-array.js:24
↓ 2 callersFunctionfindPermutations
* * Problem: * Given a set of distinct numbers, find all of its permutations. Permutation is * defined as the re-arranging of the elements of the s
10_subsets/46_permutations.js:26
↓ 2 callersFunctionfindSingleNumber
* * Problem: * In a non-empty array of integers, every number appears twice except for one, find * that single number. * https://leetcode.com/prob
12_bitwise-xor/136_single-number.js:23
↓ 2 callersFunctionfindSmallestLetterGreaterThanTarget
* * Problem: * Given an array of lowercase letters sorted in ascending order, find the smallest * letter in the given array greater than a given "k
11_binary-search/744_find-smallest-letter-greater-than-target.js:31
↓ 2 callersFunctionfindSmallestMissingPositive
* * Problem: * Given an unsorted array containing numbers, find the smallest missing positive * number in it. * https://leetcode.com/problems/firs
5_cyclic-sort/41_first-smallest-missing-positive.js:23
↓ 2 callersFunctionfindSmallestRange
* * Problem: * Given k sorted arrays, find the smallest range that includes at least one number from * each of the k lists. * https://leetcode.com
14_k-way-merge/632_smallest-range-covering-elements-from-k-lists.js:27
↓ 2 callersFunctionfindSubsets
* * Problem: * Given a set with distinct elements, find all of its distinct subsets. * https://leetcode.com/problems/subsets/ * * Example 1: * I
10_subsets/78_subsets.js:22
↓ 2 callersFunctionfindSubsetsWithDuplicates
* * Problem: * Given a set of numbers that might contain duplicates, find all of its distinct * subsets. * https://leetcode.com/problems/subsets-i
10_subsets/90_subsets-ii.js:24
↓ 2 callersFunctionfindTopKFrequentElements
* * Problem: * Given an unsorted array of numbers, find the top K frequently occurring numbers in * it. * https://leetcode.com/problems/top-k-freq
13_top-k-elements/347_top-k-frequent-elements.js:29
↓ 2 callersFunctionfindTwoSingleNumbers
* * Problem: * In a non-empty array of numbers, every number appears exactly twice except two * numbers that appear only once. Find the two numbers
12_bitwise-xor/260_single-number-iii.js:23
↓ 2 callersFunctionfindUniqueBST
* * Problem: * Given a number n, write a function to return all structurally unique Binary Search * Trees (BST) that can store values 1 to n? * *
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:34
↓ 2 callersFunctionflipAndInvertImage
* * Problem: * Given a binary matrix representing an image, we want to flip the image horizontally, * then invert it. To flip an image horizontally
12_bitwise-xor/82_flipping-an-image.js:48
↓ 2 callersFunctionfruitIntoBaskets
* * Problem: * Given an array of characters where each character represents a fruit tree, you are given * two baskets and your goal is to put maxim
1_sliding-window/904_fruit-into-baskets.js:27
↓ 2 callersFunctiongenerateGeneralizedAbbreviation
* * Problem: * Given a word, write a function to generate all of its unique generalized * abbreviations. Generalized abbreviation of a word can be
10_subsets/320_generalized-abbreviation.js:28
↓ 2 callersFunctiongenerateParentheses
* * Problem: * For a given number N, write a function to generate all combination of ‘N’ pairs * of balanced parentheses. * https://leetcode.com/p
10_subsets/22_generate-parentheses.js:23
↓ 2 callersFunctiongetAllPathsWithSum
* * Problem: * Given a binary tree and a number S, find all paths from root-to-leaf such that * the sum of all the node values of each path equals
8_DFS/113_path-sum-ii.js:27
↓ 2 callersFunctionhasPathSum
* * Problem: * Given a binary tree and a number S, find if the tree has a path from * root-to-leaf such that the sum of all the node values of that
8_DFS/112_path-sum.js:26
↓ 2 callersFunctionhasPathWithGiveSequence
* * Problem: * Given a binary tree and a number sequence, find if the sequence is present as a * root-to-leaf path in the given tree. * https://le
8_DFS/1430_check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree.js:26
↓ 2 callersFunctioninsertInterval
* * Problem: * Given a list of non-overlapping intervals sorted by their start time, insert a * given interval at the correct position and merge al
4_merge-intervals/57_insert-interval.js:28
↓ 2 callersFunctionintervalIntersection
* * Problem: * Given two lists of intervals, find the intersection of these two lists. Each list * consists of disjoint intervals sorted on their s
4_merge-intervals/986_interval-list-intersections.js:25
↓ 2 callersFunctionisHappyNumber
* * Problem: * Any number will be called a happy number if, after repeatedly replacing it with a * number equal to the sum of the square of all of
3_fast-slow-pointers/202_happy-number.js:47
↓ 2 callersFunctionisPalindromeLinkedList
* * Problem: * Given the head of a Singly LinkedList, write a method to check if the LinkedList * is a palindrome or not. You algorithm should use
3_fast-slow-pointers/234_palindrome-linked-list.js:26
↓ 2 callersFunctionkthSmallestNumberInMSortedLists
* * Problem: * Given M sorted arrays, find the Kth smallest number among all the arrays. * * Example 1: * Input: L1=[2, 6, 8], L2=[3, 6, 7], L3=[
14_k-way-merge/0_kth-smallest-number-in-m-sorted-lists.js:27
↓ 2 callersFunctionlevelOrderSuccessor
* * Problem: * Given a binary tree and a node, find the level order successor of the given node * in the tree. The level order successor is the nod
7_BFS/0_level-order-successor.js:27
↓ 2 callersFunctionlevelOrderTraverse
* * Problem: * Given a binary tree, populate an array to represent its level-by-level traversal. * You should populate the values of all nodes of e
7_BFS/102_binary-tree-level-order-traversal.js:25
↓ 2 callersFunctionlongestRepeatingCharacterReplacement
* * Problem: * Given a string with lowercase letters only, if you are allowed to replace no more than * k letters with any letter, find the length
1_sliding-window/424_longest-repeating-character-replacement.js:25
↓ 2 callersFunctionlongestSubstringWithoutRepeatingCharacters
* * Problem: * Given a string, find the length of the longest substring without repeating characters. * https://leetcode.com/problems/longest-subst
1_sliding-window/3_longest-substring-without-repeating-characters.js:23
↓ 2 callersFunctionmaxConsecutiveOnesIII
* * Problem: * Given an array containing 0s and 1s, if you are allowed to replace no more than ‘k’ 0s * with 1s, find the length of the longest con
1_sliding-window/1004_max-consecutive-ones-iii.js:31
↓ 2 callersFunctionmaxPathSum
* * Problem: * Find the path with the maximum sum in a given binary tree. Write a function that * returns the maximum sum. A path can be defined as
8_DFS/124_binary-tree-maximum-path-sum.js:29
↓ 2 callersFunctionmaximumCPULoad
* * Problem: * We are given a list of Jobs. Each job has a Start time, an End time, and a CPU * load when it is running. Our goal is to find the ma
4_merge-intervals/0_maximum-cpu-load.js:34
↓ 2 callersFunctionmaximumSumSubarrayOfSizeK
* * Problem: * Given an array of positive numbers and a positive number k, find the maximum sum of * any contiguous subarray of size k. * * Examp
1_sliding-window/0_maximum-sum-subarray-of-size-k.js:24
↓ 2 callersFunctionmedianOfSlidingWindow
* * Problem: * Given an array of numbers and a number k, find the median of all the k sized * sub-arrays (or windows) of the array. * https://leet
9_two-heaps/480_sliding-window-median.js:36
↓ 2 callersFunctionmergeIntervals
* * Problem: * Given a list of intervals, merge all the overlapping intervals to produce a list * that has only mutually exclusive intervals. * ht
4_merge-intervals/56_merge-intervals.js:26
↓ 2 callersFunctionmergeKSortedLists
* * Problem: * Given an array of K sorted LinkedLists, merge them into one sorted list. * https://leetcode.com/problems/merge-k-sorted-lists/ * *
14_k-way-merge/23_merge-k-sorted-lists.js:32
↓ 2 callersFunctionminimumMeetingRooms
* * Problem: * Given a list of intervals representing the start and end time of ‘N’ meetings, find * the minimum number of rooms required to hold a
4_merge-intervals/253_meeting-rooms-ii.js:28
↓ 2 callersFunctionminimumTreeDepth
* * Problem: * Find the minimum depth of a binary tree. The minimum depth is the number of nodes * along the shortest path from the root node to th
7_BFS/111_minimum-depth-of-binary-tree.js:25
↓ 2 callersFunctionminimumWindowSubstring
* * Problem: * Given a string and a pattern, find the smallest substring in the given string which has * all the characters of the given pattern.
1_sliding-window/76_minimum-window-substring.js:25
↓ 2 callersFunctionpermutationInString
* * Problem: * Given a string and a pattern, find out if the string contains any permutation of the * pattern. * https://leetcode.com/problems/per
1_sliding-window/567_permutation-in-string.js:25
↓ 2 callersFunctionquadrupleSumToTarget
* * Problem: * Given an array of unsorted numbers and a target number, find all unique quadruplets in * it, whose sum is equal to the target number
2_two-pointers/18_4sum.js:28
↓ 2 callersMethodremove
(item)
_utils.js:110
↓ 2 callersFunctionremoveDuplicatesFromSortedArray
* * Problem: * Given an array of sorted numbers, remove all duplicates from it. You should not use any * extra space; after removing the duplicates
2_two-pointers/26_remove-duplicates-from-sorted-array.js:25
↓ 2 callersFunctionreverseAlternateKNodes
* * Problem: * Given the head of a LinkedList and a number k, reverse every alternating k * sized sub-list starting from the head. If, in the end,
6_in-place-reversal-of-a-linked-list/0_reverse-alternating-k-group.js:17
↓ 2 callersFunctionreverseNodesInKGroup
* * Problem: * Given the head of a LinkedList and a number k, reverse every k sized sub-list * starting from the head. If, in the end, you are left
6_in-place-reversal-of-a-linked-list/25_reverse-nodes-in-k-group.js:18
↓ 2 callersFunctionreverseNodesInKGroupRecursive
* Do it recursively.
6_in-place-reversal-of-a-linked-list/25_reverse-nodes-in-k-group.js:64
↓ 2 callersFunctionreversedLevelOrderTraverse
* * Problem: * Given a binary tree, populate an array to represent its level-by-level traversal * in reverse order, i.e., the lowest level comes fi
7_BFS/107_binary-tree-level-order-traversal-ii.js:25
↓ 2 callersFunctionreversedLevelOrderTraverseRecursive
(root)
7_BFS/107_binary-tree-level-order-traversal-ii.js:58
↓ 2 callersFunctionrightViewOfBinaryTree
* * Problem: * Given a binary tree, return an array containing nodes in its right view. The right * view of a binary tree is the set of nodes visib
7_BFS/199_binary-tree-right-side-view.js:26
↓ 2 callersFunctionrightViewOfBinaryTreeRecursive
* A recursive solution which does not require storing all level nodes. The key * logic is to do DFS traversal but visiting the right node first, beca
7_BFS/199_binary-tree-right-side-view.js:61
↓ 2 callersFunctionrotateLinkedList
* * Problem: * Given a linked list, rotate the list to the right by k places, where k is * non-negative. * https://leetcode.com/problems/rotate-li
6_in-place-reversal-of-a-linked-list/61_rotate-list.js:33
↓ 2 callersFunctionscheduleTasks
* * Problem: * You are given a list of tasks that need to be run, in any order, on a server. Each task * will take one CPU interval to execute but
13_top-k-elements/621_task-scheduler.js:31
↓ 2 callersFunctionsearchRotatedArrayWithDuplicates
* * Problem: * Follow up on the 33_search-in-rotated-sorted-array problem, how do we search in a * sorted and rotated array that also has duplicate
11_binary-search/81_search-in-rotated-sorted-array-ii.js:26
↓ 2 callersFunctionshortestUnsortedContinuousSubarray
* * Problem: * Given an array, find the length of the smallest subarray in it which when sorted * will sort the whole array. * https://leetcode.co
2_two-pointers/581_shortest-unsorted-continuous-subarray.js:26
↓ 2 callersFunctionsmallestSubarrayWithGiveSum
* * Problem: * Given an array of positive numbers and a positive number ‘S’, find the length * of the smallest contiguous subarray whose sum is gre
1_sliding-window/0_smallest-subarray-with-given-sum.js:25
↓ 2 callersFunctionsortCharactersByFrequency
* * Problem: * Given a string, sort it based on the decreasing frequency of its characters. * https://leetcode.com/problems/sort-characters-by-freq
13_top-k-elements/451_sort-characters-by-frequency.js:29
↓ 2 callersFunctionsortColors
* * Problem: * Given an array containing 0s, 1s and 2s, sort the array in-place. You should treat * numbers of the array as objects, hence, we can’
2_two-pointers/75_sort-colors.js:25
↓ 2 callersFunctionsquaresOfSortedArray
* * Problem: * Given a sorted array, create a new array containing squares of of the input array in * the sorted order. * https://leetcode.com/pr
2_two-pointers/977_squares-of-a-sorted-array.js:22
↓ 2 callersFunctionsquaresOfSortedArray1
(sortedArray)
2_two-pointers/977_squares-of-a-sorted-array.js:79
↓ 2 callersFunctionsubarrayProductLessThanK
* * Problem: * Given an array with positive numbers and a target number, find all of its contiguous * subarrays whose product is less than the targ
1_sliding-window/713_subarray-product-less-than-k.js:28
↓ 2 callersFunctionsubstringWithConcatenationOfAllWords
* * Problem: * Given a string and a list of words, find all the starting indices of substrings in the * given string that are a concatenation of al
1_sliding-window/30_substring-with-concatenation-of-all-words.js:30
↓ 2 callersFunctionsumOfElementsBetweenK1AndK2
* * Problem: * Given an array, find the sum of all numbers between the K1'th and K2'th smallest * elements (not inclusive) of that array. * * Exa
13_top-k-elements/0_sum-of-elements-between-k1-and-k2.js:30
↓ 2 callersFunctionsumOfRootToLeafNumbers
* * Problem: * Given a binary tree where each node can only have a digit (0-9) value, each * root-to-leaf path will represent a number. Find the to
8_DFS/129_sum-root-to-leaf-numbers.js:28
↓ 2 callersFunctiontopologicalSort
* * Problem: * Topological Sort of a directed graph (a graph with unidirectional edges) is a linear * ordering of its vertices such that for every
16_topological-sort/0_topological-sort.js:36
↓ 2 callersFunctiontripletSumCloseToTarget
* * Problem: * Given an array of unsorted numbers and a target number, find a triplet in the array * whose sum is as close to the target number as
2_two-pointers/16_3sum-closest.js:29
↓ 2 callersFunctiontripletSumToZero
* * Problem: * Given an array of unsorted numbers, find all unique triplets in it that add up to zero. * Notice that the solution set must not cont
2_two-pointers/15_3sum.js:24
↓ 2 callersFunctiontripletsCountWithSmallerSum
* * Problem: * Given an array arr of unsorted numbers and a target sum, count all triplets in it such * that arr[i] + arr[j] + arr[k] < target wher
2_two-pointers/259_3sum-smaller.js:30
↓ 2 callersFunctiontwoSumIIInputArrayIsSorted
* * Problem: * Given an array of sorted numbers and a target sum, find a pair in the array whose sum * is equal to the given target. Write a functi
2_two-pointers/167_two-sum-ii-input-array-is-sorted.js:26
↓ 2 callersFunctionzigzagLevelOrderTraverse
* * Problem: * Given a binary tree, populate an array to represent its zigzag level order * traversal. You should populate the values of all nodes
7_BFS/103_binary-tree-zigzag-level-order-traversal.js:26
↓ 1 callersFunction_backtrack
(num, curList, openCount, closeCount, result)
10_subsets/22_generate-parentheses.js:29
↓ 1 callersFunction_backtrack
* * @param {number[]} candidates * @param {number} target * @param {number} currentIndex * @param {number[]} currentArr * @param {number[][]} com
10_subsets/40_combination-sum-ii.js:52
↓ 1 callersFunction_backtrack
(nums, curResult, startIndex, result)
10_subsets/90_subsets-ii.js:32
↓ 1 callersFunction_backtrack
(str, curIndex, curList, result)
10_subsets/320_generalized-abbreviation.js:34
↓ 1 callersFunction_backtrack
(str, curIndex, curList, result)
10_subsets/784_letter-case-permutation.js:29
↓ 1 callersFunction_backtrack
(nums, curList, result, used)
10_subsets/46_permutations.js:33
↓ 1 callersFunction_backtrack
(nums, curList, startIndex, result)
10_subsets/78_subsets.js:85
↓ 1 callersFunction_backtrack
(n, root, used, result)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:115
↓ 1 callersFunction_cloneNode
(node)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:178
↓ 1 callersFunction_countUniqueBSTBetween
* * Follow the same approach as 95_unique-binary-search-trees-ii, but this time we * can use memoization because the result is just a plain number (
17_divide-and-conquer/96_unique-binary-search-trees.js:36
↓ 1 callersFunction_deleteFromBST
(node, value)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:145
↓ 1 callersFunction_findRightMostNode
(node)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:171
↓ 1 callersFunction_findUniqueBSTBetween
(start, end)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:48
↓ 1 callersFunction_getDistance
(point)
13_top-k-elements/973_k-closest-points-to-origin.js:50
↓ 1 callersFunction_getOrderFromSources
* * @param {number[]} sources * @param {number[][]} graph * @param {number[]} inDegrees * @param {boolean[]} used * @param {number[]} currentResu
16_topological-sort/0_all-tasks-scheduling-orders.js:87
↓ 1 callersFunction_getOrderFromTwoWords
* Compare `word1` and `word2` to find a order between 2 characters. * * Time: O(m) m: max length of `word1` and `word2` * * @param {string} word1
16_topological-sort/269_alien-dictionary.js:123
↓ 1 callersMethod_hasLeftChild
(index)
_utils.js:49
↓ 1 callersMethod_hasRightChild
(index)
_utils.js:57
↓ 1 callersFunction_insertToBST
(node, value)
17_divide-and-conquer/95_unique-binary-search-trees-ii.js:133
↓ 1 callersFunction_isNumber
(char)
10_subsets/320_generalized-abbreviation.js:66
↓ 1 callersFunction_isNumber
(char)
10_subsets/784_letter-case-permutation.js:56
↓ 1 callersFunction_isOperator
(char)
17_divide-and-conquer/241_different-ways-to-add-parentheses.js:104
↓ 1 callersFunction_partition
(nums, start, end)
13_top-k-elements/0_kth-smallest-element-in-an-array.js:96
↓ 1 callersFunction_quickSort
(nums, start, end, k)
13_top-k-elements/0_kth-smallest-element-in-an-array.js:81
↓ 1 callersFunction_recursiveWithMemo
* * Time: O(mn) m: 2 * targetSum * Space: O(mn) <- for `memo` and recursion stack * * @param {number[]} nums * @param {number} targetSum * @para
15_dynamic-programming/494_target-sum.js:104
↓ 1 callersFunction_recursiveWithMemo
* * The only changing variables are `currentIndex` and `targetSum`, so use two-dimension * `memo` to prevent duplication sub-problems. * * Time: O
15_dynamic-programming/0_count-of-subset-sum.js:98
↓ 1 callersFunction_recursiveWithMemo
* * Time: O(mn) m: target sum * Space: O(mn) <- for `memo` and recursion stack * * @param {*} nums * @param {*} targetSum * @param {*} currentIn
15_dynamic-programming/416_partition-equal-subset-sum.js:120
↓ 1 callersFunction_recursiveWithMemo
* * Time: O(mn) m: total sum * Space: O(mn) * * @param {number[]} nums * @param {number} totalSum * @param {number} currentSum * @param {number
15_dynamic-programming/0_minimum-subset-sum-difference.js:112
↓ 1 callersFunction_recursiveWithMemo
* * From the above solution 1, we can easily identify that each call of `_recursive` * the only changing variables are `currentIndex` and `capacity`
15_dynamic-programming/0_0-1-knapsack.js:149
↓ 1 callersFunction_rightView
(node, depth, values)
7_BFS/199_binary-tree-right-side-view.js:67
← previousnext →101–200 of 252, ranked by callers