migrate 392 questions to pattern format
This commit is contained in:
@@ -177,3 +177,83 @@ patterns:
|
||||
- Flood fill
|
||||
- Rotting oranges
|
||||
- Word search in grid
|
||||
|
||||
- name: Topological Sort
|
||||
slug: topological-sort
|
||||
description: Order vertices in a directed acyclic graph (DAG) such that for every edge u→v, u comes before v.
|
||||
when_to_use: |
|
||||
- Course scheduling with prerequisites
|
||||
- Build order / dependency resolution
|
||||
- Task scheduling with dependencies
|
||||
- Alien dictionary problems
|
||||
- Detecting cycles in directed graphs
|
||||
|
||||
- name: Bit Manipulation
|
||||
slug: bit-manipulation
|
||||
description: Use bitwise operations (AND, OR, XOR, shifts) to solve problems efficiently.
|
||||
when_to_use: |
|
||||
- Finding single/missing numbers (XOR tricks)
|
||||
- Counting set bits
|
||||
- Power of two checks
|
||||
- Subset generation with bitmasks
|
||||
- Swapping without temp variable
|
||||
|
||||
- name: Counting / Bucket Sort
|
||||
slug: counting-sort
|
||||
description: Sort or process elements by using their values as indices when the range is bounded.
|
||||
when_to_use: |
|
||||
- Top K frequent elements (bounded frequency range)
|
||||
- Sort Colors (Dutch National Flag)
|
||||
- H-Index calculation
|
||||
- Problems where values are in known small range
|
||||
- Frequency-based grouping
|
||||
|
||||
- name: Cyclic Sort
|
||||
slug: cyclic-sort
|
||||
description: Place each element at its correct index when values are in range [1, n] or [0, n-1].
|
||||
when_to_use: |
|
||||
- Find missing number in [1, n]
|
||||
- Find duplicate in [1, n]
|
||||
- Find all missing/duplicate numbers
|
||||
- First missing positive
|
||||
- Set mismatch problems
|
||||
|
||||
- name: Divide and Conquer
|
||||
slug: divide-and-conquer
|
||||
description: Split problem into smaller subproblems, solve recursively, and combine results.
|
||||
when_to_use: |
|
||||
- Merge sort and related problems
|
||||
- Quick select for kth element
|
||||
- Binary search variants
|
||||
- Matrix multiplication
|
||||
- Closest pair of points
|
||||
|
||||
- name: Hashing
|
||||
slug: hashing
|
||||
description: Use hash tables for O(1) average lookup, insertion, and deletion.
|
||||
when_to_use: |
|
||||
- Two Sum and variants
|
||||
- Detecting duplicates
|
||||
- Frequency counting
|
||||
- Anagram grouping
|
||||
- LRU/LFU cache implementation
|
||||
|
||||
- name: Matrix Manipulation
|
||||
slug: matrix-manipulation
|
||||
description: Transform or process 2D matrices using rotation, transposition, or in-place modifications.
|
||||
when_to_use: |
|
||||
- Rotate image 90 degrees
|
||||
- Spiral matrix traversal
|
||||
- Set matrix zeroes
|
||||
- Transpose matrix
|
||||
- Game of Life state updates
|
||||
|
||||
- name: Synchronization
|
||||
slug: synchronization
|
||||
description: Coordinate multiple threads or processes using locks, semaphores, or barriers.
|
||||
when_to_use: |
|
||||
- Print in order problems
|
||||
- Producer-consumer patterns
|
||||
- Dining philosophers
|
||||
- Building H2O molecules
|
||||
- Concurrent data structure design
|
||||
|
||||
@@ -7,9 +7,12 @@ categories:
|
||||
- arrays
|
||||
- graphs
|
||||
patterns:
|
||||
- bfs
|
||||
- matrix-traversal
|
||||
- dynamic-programming
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: matrix-traversal
|
||||
is_optimal: false
|
||||
- slug: dynamic-programming
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def update_matrix(mat: list[list[int]]) -> list[list[int]]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- stack
|
||||
patterns:
|
||||
- monotonic-stack
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def find132pattern(nums: list[int]) -> bool:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- dynamic-programming
|
||||
- math
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def min_steps(n: int) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- math
|
||||
- recursion
|
||||
patterns:
|
||||
- backtracking
|
||||
- slug: backtracking
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def judge_point24(cards: list[int]) -> bool:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- hash-tables
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: counting-sort
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def three_sum_multi(arr: list[int], target: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- hash-tables
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: hashing
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def four_sum_count(nums1: list[int], nums2: list[int], nums3: list[int], nums4: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/a-number-after-a-double-reversal/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def is_same_after_reversals(num: int) -> bool:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- hash-tables
|
||||
- strings
|
||||
patterns:
|
||||
- union-find
|
||||
- dfs
|
||||
- slug: union-find
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def accounts_merge(accounts: list[list[str]]) -> list[list[str]]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_binary(a: str, b: str) -> str:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/add-digits/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_digits(num: int) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/add-minimum-number-of-rungs/
|
||||
categories:
|
||||
- arrays
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_rungs(rungs: list[int], dist: int) -> int:"
|
||||
|
||||
|
||||
@@ -8,9 +8,12 @@ categories:
|
||||
- queue
|
||||
- recursion
|
||||
patterns:
|
||||
- bfs
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def add_one_row(root: TreeNode, val: int, depth: int) -> TreeNode:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_strings(num1: str, num2: str) -> str:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_to_array_form(num: list[int], k: int) -> list[int]:"
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ leetcode_id: 2235
|
||||
leetcode_url: https://leetcode.com/problems/add-two-integers/
|
||||
categories:
|
||||
- math
|
||||
patterns: []
|
||||
patterns:
|
||||
- slug: bit-manipulation
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def sum(num1: int, num2: int) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- stack
|
||||
- math
|
||||
patterns:
|
||||
- linkedlist-reversal
|
||||
- slug: linkedlist-reversal
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_two_numbers(l1: ListNode, l2: ListNode) -> ListNode:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- linked-lists
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_two_numbers(l1: ListNode | None, l2: ListNode | None) -> ListNode | None:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- arrays
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_spaces(s: str, spaces: list[int]) -> str:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def add_negabinary(arr1: list[int], arr2: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- recursion
|
||||
patterns:
|
||||
- backtracking
|
||||
- slug: backtracking
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def is_additive_number(num: str) -> bool:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- arrays
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- two-pointers
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def advantage_count(nums1: list[int], nums2: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- math
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def nth_person_gets_nth_seat(n: int) -> float:"
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ categories:
|
||||
- strings
|
||||
- sorting
|
||||
patterns:
|
||||
- sliding-window
|
||||
- slug: sliding-window
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def alert_names(key_name: list[str], key_time: list[str]) -> list[str]:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/all-divisions-with-the-highest-score
|
||||
categories:
|
||||
- arrays
|
||||
patterns:
|
||||
- prefix-sum
|
||||
- slug: prefix-sum
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_score_indices(nums: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- sorting
|
||||
patterns:
|
||||
- tree-traversal
|
||||
- two-pointers
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def get_all_elements(root1: TreeNode, root2: TreeNode) -> list[int]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- graphs
|
||||
- hash-tables
|
||||
patterns:
|
||||
- bfs
|
||||
- dfs
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def distance_k(root: TreeNode, target: TreeNode, k: int) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- graphs
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- backtracking
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: backtracking
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def all_paths_source_target(graph: list[list[int]]) -> list[list[int]]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- recursion
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- backtracking
|
||||
- dynamic-programming
|
||||
- slug: backtracking
|
||||
is_optimal: false
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def all_possible_fbt(n: int) -> list[TreeNode]:"
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ categories:
|
||||
- sorting
|
||||
- math
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def min_distance(houses: list[int], k: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- hash-tables
|
||||
patterns:
|
||||
- matrix-traversal
|
||||
- slug: matrix-traversal
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def alphabet_board_path(target: str) -> str:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/alternating-digit-sum/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def alternate_digit_sum(n: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- recursion
|
||||
patterns:
|
||||
- backtracking
|
||||
- slug: backtracking
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def ambiguous_coordinates(s: str) -> list[str]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- graphs
|
||||
- hash-tables
|
||||
patterns:
|
||||
- bfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def amount_of_time(root: TreeNode, start: int) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/angle-between-hands-of-a-clock/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def angle_clock(hour: int, minutes: int) -> float:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- strings
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- greedy
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def append_characters(s: str, t: str) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- math
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def min_sum(nums: list[int], k: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def make_strings_equal(s: str, target: str) -> bool:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def apply_operations(nums: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- dynamic-programming
|
||||
- hash-tables
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def number_of_arithmetic_slices(nums: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def number_of_arithmetic_slices(nums: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- hash-tables
|
||||
- sorting
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def check_arithmetic_subarrays(nums: list[int], l: list[int], r: list[int]) -> list[bool]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- math
|
||||
- binary-search
|
||||
patterns:
|
||||
- binary-search
|
||||
- slug: binary-search
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def arrange_coins(n: int) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/array-nesting/
|
||||
categories:
|
||||
- arrays
|
||||
patterns:
|
||||
- dfs
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def array_nesting(nums: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- hash-tables
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def can_reorder_doubled(arr: list[int]) -> bool:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def array_pair_sum(nums: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def rearrange_array(nums: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- arrays
|
||||
- graphs
|
||||
patterns:
|
||||
- bfs
|
||||
- matrix-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: matrix-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def max_distance(grid: list[list[int]]) -> int:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- sorting
|
||||
- two-pointers
|
||||
patterns:
|
||||
- greedy
|
||||
- two-pointers
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def find_content_children(g: list[int], s: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- stack
|
||||
patterns:
|
||||
- monotonic-stack
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def asteroid_collision(asteroids: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/available-captures-for-rook/
|
||||
categories:
|
||||
- arrays
|
||||
patterns:
|
||||
- matrix-traversal
|
||||
- slug: matrix-traversal
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def num_rook_captures(board: list[list[str]]) -> int:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- queue
|
||||
patterns:
|
||||
- bfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def average_of_levels(root: TreeNode) -> list[float]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- sorting
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def average(salary: list[int]) -> float:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- prefix-sum
|
||||
- slug: prefix-sum
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def average_value(nums: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/average-waiting-time/
|
||||
categories:
|
||||
- arrays
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def average_waiting_time(customers: list[list[int]]) -> float:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- arrays
|
||||
- hash-tables
|
||||
patterns:
|
||||
- greedy
|
||||
- binary-search
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
- slug: binary-search
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def avoid_flood(rains: list[int]) -> list[int]:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- stack
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def backspace_compare(s: str, t: str) -> bool:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- sorting
|
||||
- two-pointers
|
||||
patterns:
|
||||
- two-pointers
|
||||
- greedy
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def bag_of_tokens_score(tokens: list[int], power: int) -> int:"
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ leetcode_url: https://leetcode.com/problems/balance-a-binary-search-tree/
|
||||
categories:
|
||||
- trees
|
||||
patterns:
|
||||
- tree-traversal
|
||||
- dfs
|
||||
- slug: tree-traversal
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def balance_bst(root: TreeNode) -> TreeNode:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def is_balanced(root: TreeNode) -> bool:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def convert_to_base7(num: int) -> str:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- stack
|
||||
patterns:
|
||||
- monotonic-stack
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def cal_points(operations: list[str]) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- stack
|
||||
- math
|
||||
patterns:
|
||||
- monotonic-stack
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def calculate(s: str) -> int:"
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ categories:
|
||||
- stack
|
||||
- math
|
||||
patterns:
|
||||
- backtracking
|
||||
- slug: backtracking
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def basic_calculator_iv(expression: str, evalvars: list[str], evalints: list[int]) -> list[str]:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- stack
|
||||
- math
|
||||
patterns:
|
||||
- monotonic-stack
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def calculate(s: str) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- graphs
|
||||
patterns:
|
||||
- matrix-traversal
|
||||
- slug: matrix-traversal
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def count_battleships(board: list[list[str]]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def construct_array(n: int, k: int) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- recursion
|
||||
patterns:
|
||||
- backtracking
|
||||
- slug: backtracking
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def count_arrangement(n: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def beautiful_array(n: int) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- hash-tables
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def best_hand(ranks: list[int], suits: list[str]) -> str:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def get_min_dist_sum(positions: list[list[int]]) -> float:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_score_sightseeing_pair(values: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ categories:
|
||||
- dynamic-programming
|
||||
- sorting
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def best_team_score(scores: list[int], ages: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_profit(prices: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_profit(prices: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_profit(k: int, prices: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_profit(prices: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dynamic-programming
|
||||
- greedy
|
||||
- slug: dynamic-programming
|
||||
is_optimal: true
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def max_profit(prices: list[int], fee: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def max_profit(prices: list[int]) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/binary-gap/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- two-pointers
|
||||
- slug: two-pointers
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def binary_gap(n: int) -> int:"
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ leetcode_url: https://leetcode.com/problems/binary-number-with-alternating-bits/
|
||||
categories:
|
||||
- math
|
||||
patterns:
|
||||
- greedy
|
||||
- slug: greedy
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def has_alternating_bits(n: int) -> bool:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- math
|
||||
patterns:
|
||||
- prefix-sum
|
||||
- slug: prefix-sum
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def prefixes_div_by5(nums: list[int]) -> list[bool]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- stack
|
||||
patterns:
|
||||
- tree-traversal
|
||||
- monotonic-stack
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
- slug: monotonic-stack
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "class BSTIterator:\n def __init__(self, root: TreeNode): ...\n def next(self) -> int: ...\n def hasNext(self) -> bool: ..."
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ leetcode_url: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tr
|
||||
categories:
|
||||
- trees
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def bst_to_gst(root: TreeNode) -> TreeNode:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- arrays
|
||||
- binary-search
|
||||
patterns:
|
||||
- binary-search
|
||||
- slug: binary-search
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def search(nums: list[int], target: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ categories:
|
||||
- strings
|
||||
- math
|
||||
patterns:
|
||||
- sliding-window
|
||||
- slug: sliding-window
|
||||
is_optimal: true
|
||||
|
||||
function_signature: "def query_string(s: str, n: int) -> bool:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- arrays
|
||||
- hash-tables
|
||||
patterns:
|
||||
- sliding-window
|
||||
- prefix-sum
|
||||
- slug: sliding-window
|
||||
is_optimal: true
|
||||
- slug: prefix-sum
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def num_subarrays_with_sum(nums: list[int], goal: int) -> int:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- dynamic-programming
|
||||
patterns:
|
||||
- dfs
|
||||
- greedy
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: greedy
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def min_camera_cover(root: TreeNode) -> int:"
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ leetcode_url: https://leetcode.com/problems/binary-tree-coloring-game/
|
||||
categories:
|
||||
- trees
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def btree_game_winning_move(root: TreeNode, n: int, x: int) -> bool:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- stack
|
||||
- recursion
|
||||
patterns:
|
||||
- tree-traversal
|
||||
- dfs
|
||||
- slug: tree-traversal
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def inorder_traversal(root: TreeNode) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- queue
|
||||
patterns:
|
||||
- bfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def level_order_bottom(root: TreeNode) -> list[list[int]]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- queue
|
||||
patterns:
|
||||
- bfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def level_order(root: TreeNode | None) -> list[list[int]]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- dynamic-programming
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- dynamic-programming
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: dynamic-programming
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def max_path_sum(root: TreeNode) -> int:"
|
||||
|
||||
|
||||
@@ -8,9 +8,12 @@ categories:
|
||||
- strings
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- backtracking
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: backtracking
|
||||
is_optimal: false
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def binary_tree_paths(root: TreeNode) -> list[str]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- stack
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def postorder_traversal(root: TreeNode) -> list[int]:"
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ categories:
|
||||
- stack
|
||||
- recursion
|
||||
patterns:
|
||||
- tree-traversal
|
||||
- dfs
|
||||
- slug: tree-traversal
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def preorder_traversal(root: TreeNode) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def prune_tree(root: TreeNode) -> TreeNode:"
|
||||
|
||||
|
||||
@@ -6,9 +6,12 @@ leetcode_url: https://leetcode.com/problems/binary-tree-right-side-view/
|
||||
categories:
|
||||
- trees
|
||||
patterns:
|
||||
- bfs
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: dfs
|
||||
is_optimal: false
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def right_side_view(root: TreeNode) -> list[int]:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- recursion
|
||||
patterns:
|
||||
- dfs
|
||||
- tree-traversal
|
||||
- slug: dfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def find_tilt(root: TreeNode) -> int:"
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ categories:
|
||||
- trees
|
||||
- queue
|
||||
patterns:
|
||||
- bfs
|
||||
- tree-traversal
|
||||
- slug: bfs
|
||||
is_optimal: true
|
||||
- slug: tree-traversal
|
||||
is_optimal: false
|
||||
|
||||
function_signature: "def zigzag_level_order(root: TreeNode) -> list[list[int]]:"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user