problems
dz / leetcode / problemsSubgraphs
Node Tree
- 1004_max_consecutive_ones_iii
- 1011_capacity_ship_packages_d_days
- 104_max_depth_binary_tree
- 1071_GCD_of_strings
- 110_balanced_binary_tree
- 1137_nth_tribonacci_number
- 1143_longest_common_subsequence
- 1161_max_level_sum_binary_tree
- 1207_unique_number_of_occurrences
- 121_best_time_to_sell_and_buy_stock
- 125_valid_palindrome
- 1335_minimum_difficulty_job_schedule
- 1372_longest_zigzag_path
- 137_single_number_2
- 141_linked_list_cycle
- 1431_kids_with_greatest_number_of_candies
- 1448_count_good_nodes
- 1456_max_vowels_in_substring
- 1466_reorder_routes_to_city_zero
- 146_LRU_cache
- 1493_longest_subarray_ones_deleting_elem
- 151_reverse_words_in_a_string
- 155_min_stack
- 162_find_peak_element
- 1657_close_strings
- 1659_maximize_grid_happiness
- 1679_max_number_of_ksum_pairs
- 169_majority_element
- 1732_find_highest_altitude
- 1768_merge_strings_alternately
- 1770_max_score_multiplication_operations
- 187_repeated_DNA_sequences
- 1926_nearest_exit_from_entrance_in_maze
- 198_house_robber
- 1_two_sum
- 200_number_of_islands
- 2034_stock_price_fluctuation
- 208_implement_trie
- 20_valid_parentheses
- 211_design_add_and_search_words_data_structure
- 212_word_search_2
- 2130_max_twin_sum_linked_list
- 215_kth_largest_element
- 216_combination_sum_iii
- 217_contains_duplicate
- 21_merge_two_sorted_lists
- 2215_difference_two_arrays
- 221_maximal_square
- 2300_successful_pairs_potions_spells
- 232_implement_queue_using_stacks
- 2336_smallest_number_in_infinite_set
- 2352_equal_row_column_pairs
- 235_lowest_common_ancestor_BST
- 238_product_of_array_except_self
- 2390_removing_stars_from_a_string
- 242_valid_anagram
- 2462_total_cost_hire_k_workers
- 2542_maximum_subsequence_score
- 260_single_number_3
- 278_first_bad_version
- 282_move_zeros
- 287_find_the_duplicate_number
- 300_longest_increasing_subsequence
- 318_max_product_word_lengths
- 322_coin_change
- 328_odd_even_linked_list
- 334_increasing_triplet_subseq
- 336_palindrome_pairs
- 338_counting_bits
- 33_search_in_rotated_sorted_array
- 345_reverse_vowels_stringa
- 349_decode_string
- 34_first_last_sorted_array
- 374_guess_number_lower_higher
- 392_is_subsequence
- 399_evaluate_division
- 39_combination_sum
- 421_max_XOR_two_numbers
- 437_path_sum_iii
- 443_string_compression
- 450_delete_node_BST
- 543_diameter_of_binary_tree
- 547_number_of_provinces
- 605_can_place_flowers
- 635_design_log_storage_system
- 642_design_search_autocomplete_system
- 643_maximum_average_subarray
- 648_replace_words
- 649_dota2_senate
- 677_map_sum_pairs
- 67_add_binary
- 700_binary_search_tree
- 704_binary_search
- 70_climbing_stairs
- 714_best_time_buy_sell_stock_transaction_free
- 724_pivot_index
- 72_edit_distance
- 735_asteroid_collision
- 740_delete_and_earn
- 746_min_cost_climbing_stairs
- 790_domino_tromino_tiling
- 79_word_search
- 841_keys_and_rooms
- 872_leaf_similar_trees
- 875_koko_eating_bananas
- 876_middle_of_linked_list
- 89_validate_binary_search_tree
- 933_number_of_recent_cals
- 994_rotting_oranges
Nodes
322_coin_change | |
content | 322: Coin Change |
children | leetcode/python/lru_cache (used in top-down dynamic programming solution to avoid TLE), leetcode/references/bottom_up_top_down (DP solutions for top-down and bottoms-up), leetcode/references/optimization_problem (can be modeled as an optimization problem,using the "standard form"), leetcode/references/optimal_substructure (the coin change problem has an optimal substructure property), leetcode/references/recurrence_relation (Editorial: "the following recurrence relation holds") |
parents | leetcode/paradigms/dynamic_programming, leetcode/grind75, leetcode/explore/dynamic_programming/2_common_patterns/2_examples |
hyperlink | https://leetcode.com/problems/coin-change |
location | knowledge/leetcode/leetcode.dz:21 |
2025-01-02 20:27 Coin Change 2025-01-02 21:17 Trying to get the recurrence relation I think the state variables are the starting coin, and the amount to add up to. I could probably code something up and sort of get it, but I'd like to be able to notate this in a more mathematical way that shows I actually grok this problem. 2025-01-02 21:44 Recurrence relation looks right, code is wrong Giving up for tonight 2025-01-03 10:22 Another attempt at coin change. 2025-01-03 11:02 I don't think I'm handling edge cases correctly. I'm currently trying to implement a top-down solution. I think I have the variables correct, and I have established a recurrence relation I believe is correct. However, I'm running into issues with actually getting edge cases set up.
238_product_of_array_except_self | |
content | 238: Product of array except self |
children | leetcode/references/prefix_sum (Left/right product sum solution reminds me of prefix sum tables) |
parents | leetcode/grind75 |
hyperlink | https://leetcode.com/problems/product-of-array-except-self |
location | knowledge/leetcode/leetcode.dz:112 |
155_min_stack | |
content | 155: Min Stack |
parents | leetcode/grind75 |
hyperlink | https://leetcode.com/problems/min-stack |
location | knowledge/leetcode/leetcode.dz:123 |
89_validate_binary_search_tree | |
content | 89: Validate Binary Search Tree |
children | leetcode/references/tree_traversal/in_order (one solution for validating BST is using in-order traversal), leetcode/data_structures/binary_search_tree |
parents | leetcode/grind75 |
hyperlink | https://leetcode.com/problems/validate-binary-search-tree |
location | knowledge/leetcode/leetcode.dz:128 |
200_number_of_islands | |
content | LC 200: number of islands |
children | leetcode/references/disjoint_data_set (One of the esoteric solutions involves using a union find,disjoint data set), leetcode/paradigms/breadth_first_search |
parents | leetcode/grind75, leetcode/paradigms/depth_first_search |
hyperlink | https://leetcode.com/problems/number-of-islands |
location | knowledge/leetcode/leetcode.dz:156 |
994_rotting_oranges | |
content | 994: number of islands |
parents | leetcode/paradigms/breadth_first_search |
hyperlink | https://leetcode.com/problems/rotting-oranges/description/ |
location | knowledge/leetcode/leetcode.dz:187 |
33_search_in_rotated_sorted_array | |
content | 33: search in rotated sorted array |
children | leetcode/paradigms/binary_search |
parents | leetcode/grind75 |
hyperlink | https://leetcode.com/problems/search-in-rotated-sorted-array |
location | knowledge/leetcode/leetcode.dz:192 |
39_combination_sum | |
content | 39: Combination sum |
children | leetcode/references/knapsack_problem (this problem initially reminded me of a knapsack problem,,except that this problem enumerating all possibilities,instead of finding an optimal one) |
parents | leetcode/grind75, leetcode/paradigms/backtracking |
hyperlink | https://leetcode.com/problems/combination-sum/ |
location | knowledge/leetcode/leetcode.dz:233 |
34_first_last_sorted_array | |
content | 34: Find first and last element in sorted array |
parents | leetcode/paradigms/binary_search/upper_bound, leetcode/paradigms/binary_search |
remarks | "find a range" problem |
hyperlink | https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ |
location | knowledge/leetcode/leetcode.dz:280 |
278_first_bad_version | |
content | 278: First Bad Version |
parents | leetcode/paradigms/binary_search/lower_bound, leetcode/paradigms/binary_search |
hyperlink | https://leetcode.com/problems/first-bad-version |
location | knowledge/leetcode/leetcode.dz:288 |
875_koko_eating_bananas | |
content | 875: Koko eating bananas |
parents | leetcode/paradigms/binary_search/lower_bound, leetcode/paradigms/binary_search, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/koko-eating-bananas |
location | knowledge/leetcode/leetcode.dz:295 |
1011_capacity_ship_packages_d_days | |
content | 1011: Capacity to ship packages within D days |
parents | leetcode/paradigms/binary_search/lower_bound |
hyperlink | https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ |
location | knowledge/leetcode/leetcode.dz:302 |
1_two_sum | |
content | 1: two-sum |
parents | leetcode/grind75, leetcode/data_structures/hash_table |
hyperlink | https://leetcode.com/problems/two-sum/ |
location | knowledge/leetcode/leetcode.dz:307 |
20_valid_parentheses | |
content | 20: Valid Parentheses |
parents | leetcode/grind75, leetcode/data_structures/stack |
hyperlink | https://leetcode.com/problems/valid-parentheses/ |
location | knowledge/leetcode/leetcode.dz:338 |
21_merge_two_sorted_lists | |
content | 21: Merge two sorted lists |
parents | leetcode/data_structures/linked_list, leetcode/grind75 |
hyperlink | https://leetcode.com/problems/merge-two-sorted-lists/ |
location | knowledge/leetcode/leetcode.dz:352 |
121_best_time_to_sell_and_buy_stock | |
content | 121: Best Time to Sell and Buy Stock |
children | leetcode/references/kadanes (I thought of Kadane's while working through this, though,I'm not sure how related they are), leetcode/references/maximum_subarray_problem (reminds me of this problem) |
parents | leetcode/paradigms/greedy, leetcode/grind75 |
location | knowledge/leetcode/leetcode.dz:366 |
125_valid_palindrome | |
content | 125: valid palindrome |
children | python/docs/reference/expressions/lambda (used with map/filter in reverse approach), python/docs/stdlib/map (In reversed approach, map is used to converted characters,to be lowercase), python/docs/stdtypes/str/isalnum (used to detect if string is alphanumeric), python/docs/stdtypes/str/isnumeric (I used this initially because I didn't know about isalnum), python/docs/stdtypes/str/lower (Converted to all lowercase to make string case-insensitive), python/docs/stdtypes/str/isalpha (I used this initially because I didn't know about isalnum), python/double_colon_reverse (trick used in reverse approach to do reversing. Not sure,why it didn't use reverse()), python/docs/stdlib/filter (In reversed approach, filter is used to whittle down the,input string to only contain alphanumeric characters) |
parents | leetcode/grind75, leetcode/paradigms/two_pointer |
hyperlink | https://leetcode.com/problems/valid-palindrome |
location | knowledge/leetcode/leetcode.dz:395 |
242_valid_anagram | |
content | 242: valid anagram |
children | python/docs/stdlib/data_types/collections/counter (built-in counter() turns this problem into a one-liner solution) |
parents | leetcode/grind75, leetcode/data_structures/hash_table |
hyperlink | https://leetcode.com/problems/valid-anagram |
location | knowledge/leetcode/leetcode.dz:408 |
704_binary_search | |
content | 704: binary search |
parents | leetcode/grind75, leetcode/paradigms/binary_search |
hyperlink | https://leetcode.com/problems/binary-search/ |
location | knowledge/leetcode/leetcode.dz:414 |
235_lowest_common_ancestor_BST | |
content | 235: Lowest Common Ancestor (LCA) of a Binary Search Tree |
children | leetcode/references/lowest_common_ancestor |
parents | leetcode/grind75, leetcode/data_structures/binary_search_tree |
location | knowledge/leetcode/leetcode.dz:420 |
2034_stock_price_fluctuation | |
content | 2034: Stock Price Fluctuation |
hyperlink | https://leetcode.com/problems/stock-price-fluctuation |
location | knowledge/leetcode/leetcode.dz:433 |
635_design_log_storage_system | |
content | 635: Design Log Storage System |
hyperlink | https://leetcode.com/problems/design-log-storage-system |
location | knowledge/leetcode/leetcode.dz:438 |
110_balanced_binary_tree | |
content | 110: balanced binary tree |
parents | leetcode/grind75, leetcode/data_structures/binary_tree |
hyperlink | https://leetcode.com/problems/balanced-binary-tree |
location | knowledge/leetcode/leetcode.dz:443 |
141_linked_list_cycle | |
content | 141: Linked List Cycle |
children | 2095_delete_middle_node (A simlar solution for this problem also uses fast/slow pointers), python/docs/stdtypes/set (useful data structure in python for simple case), python/docs/glossary/hashable ("Objects which are instances of user-defined classes are hashable by default". This would have been good to know while attempting to solve this problem.) |
parents | leetcode/data_structures/linked_list, leetcode/data_structures/linked_list/fast_slow_pointer, leetcode/grind75, leetcode/references/floyds_algorithm |
hyperlink | https://leetcode.com/problems/linked-list-cycle/ |
location | knowledge/leetcode/leetcode.dz:458 |
287_find_the_duplicate_number | |
content | 287: Find the duplicate number |
parents | leetcode/grind75, leetcode/references/floyds_algorithm |
hyperlink | https://leetcode.com/problems/find-the-duplicate-number/ |
location | knowledge/leetcode/leetcode.dz:476 |
232_implement_queue_using_stacks | |
content | Implement Queue using stacks |
parents | leetcode/data_structures/stack, leetcode/data_structures/queue |
hyperlink | https://leetcode.com/problems/implement-queue-using-stacks |
location | knowledge/leetcode/leetcode.dz:483 |
169_majority_element | |
content | 169: Majority Element |
children | leetcode/references/boyer_moore_majority_vote_algorithm (A way to solve in linear time with O(1) space), python/docs/stdtypes/generator (divide-and-conquer solution, made use of iterator generators in sum() object) |
parents | leetcode/grind75, leetcode/data_structures/hash_table |
remarks | lots of weird solutions for this one, but hash map |
hyperlink | https://leetcode.com/problems/majority-element |
location | knowledge/leetcode/leetcode.dz:497 |
67_add_binary | |
content | 67: Add Binary |
children | python/docs/stdtypes/str/zfill (in bit-by-bit manipulation problem, zfill is used to leftpad with 0s), python/docs/stdlib/bin (used by bitwise manipulation solution to convert number to binary string,at the end.), python/docs/stdlib/int (int(a,2) will convert a base 2 represented string value a to number), python/docs/stdtypes/str/format (One-liner: "{0:b}".format(int(a, 2) + int(b, 2))) |
parents | leetcode/grind75, leetcode/paradigms/bit_manipulation |
hyperlink | https://leetcode.com/problems/add-binary/description/ |
location | knowledge/leetcode/leetcode.dz:511 |
137_single_number_2 | |
content | 137: Single number 2 |
children | 136_single_number (simlar) |
parents | leetcode/paradigms/bit_manipulation |
hyperlink | https://leetcode.com/problems/single-number-ii |
location | knowledge/leetcode/leetcode.dz:520 |
2024-12-28 21:49 attempted. did not finish I did peak at the answer, but I'm too tired to grok it.
260_single_number_3 | |
content | 260: single number 3 |
parents | leetcode/paradigms/bit_manipulation |
hyperlink | https://leetcode.com/problems/single-number-iii |
location | knowledge/leetcode/leetcode.dz:526 |
187_repeated_DNA_sequences | |
content | 187: repeated DNA sequences |
parents | leetcode/paradigms/bit_manipulation |
hyperlink | https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array |
location | knowledge/leetcode/leetcode.dz:532 |
318_max_product_word_lengths | |
content | 318: Maximum product of word lengths |
parents | leetcode/paradigms/bit_manipulation |
hyperlink | https://leetcode.com/problems/maximum-product-of-word-lengths |
location | knowledge/leetcode/leetcode.dz:538 |
543_diameter_of_binary_tree | |
content | 543: Diameter of Binary Tree |
children | leetcode/references/binary_tree/terminology/degree (Article refers to a leaf as any node having 1 degree,,including the root node if it has 1 degree or less), python/docs/reference/simple_statements/nonlocal (used in the editorial example, when a "global", declared inside,of a function, was used inside of nested function) |
parents | leetcode/data_structures/binary_tree, leetcode/data_structures/binary_tree/depth_first_traversal |
hyperlink | https://leetcode.com/problems/diameter-of-binary-tree |
location | knowledge/leetcode/leetcode.dz:544 |
876_middle_of_linked_list | |
content | 876: Middle of Linked List |
parents | leetcode/data_structures/linked_list, leetcode/grind75, leetcode/references/floyds_algorithm |
remarks | Fast/slow pointer |
hyperlink | https://leetcode.com/problems/middle-of-the-linked-list |
location | knowledge/leetcode/leetcode.dz:566 |
104_max_depth_binary_tree | |
content | 104: maximum depth of binary tree |
children | leetcode/references/tail_call (an optimzed solution involves tail recursion and BFS,,where the tail call is the recursive function) |
parents | leetcode/grind75, leetcode/data_structures/binary_tree |
hyperlink | https://leetcode.com/problems/maximum-depth-of-binary-tree |
location | knowledge/leetcode/leetcode.dz:575 |
217_contains_duplicate | |
content | 217: Contains duplicate |
children | python/docs/stdtypes/set |
parents | leetcode/data_structures/hash_table |
hyperlink | https://leetcode.com/problems/contains-duplicate/ |
location | knowledge/leetcode/leetcode.dz:589 |
1768_merge_strings_alternately | |
content | 1768: merge strings alternative |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/merge-strings-alternately |
location | knowledge/leetcode/leetcode.dz:595 |
1071_GCD_of_strings | |
content | 1071: greatest common divisor of strings |
children | python/repeat_strings (Really helpful to use this operator in brute force solution to this problem), python/docs/stdlib/math/gcd (there's this really proof-y math-y solution that is quite,short in python because it uses the built-in gcd() function), python/docs/stdlib/re/sub (The C++ brute force solution uses string substitution, which,can be reproduced with re.sub()) |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/greatest-common-divisor-of-strings |
location | knowledge/leetcode/leetcode.dz:601 |
1431_kids_with_greatest_number_of_candies | |
content | 1431: Kids with greatest number of candies |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/kids-with-the-greatest-number-of-candies |
location | knowledge/leetcode/leetcode.dz:610 |
605_can_place_flowers | |
content | 605: Can place flowers |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/can-place-flowers |
location | knowledge/leetcode/leetcode.dz:616 |
345_reverse_vowels_stringa | |
content | 345: reverse vowels of a string |
parents | leetcode/paradigms/two_pointer, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/reverse-vowels-of-a-string |
location | knowledge/leetcode/leetcode.dz:622 |
151_reverse_words_in_a_string | |
content | 151: Reverse words in a string |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/reverse-words-in-a-string |
location | knowledge/leetcode/leetcode.dz:628 |
334_increasing_triplet_subseq | |
content | 334: Increasing triplet subsequence |
parents | leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/increasing-triplet-subsequence |
location | knowledge/leetcode/leetcode.dz:634 |
443_string_compression | |
content | 443: String Compression |
parents | leetcode/paradigms/array_string, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/string-compression/description |
location | knowledge/leetcode/leetcode.dz:639 |
282_move_zeros | |
content | 282: move zeros |
parents | leetcode/paradigms/two_pointer, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/move-zeroes |
location | knowledge/leetcode/leetcode.dz:645 |
392_is_subsequence | |
content | 392: is subsequence |
parents | leetcode/paradigms/two_pointer, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/is-subsequence |
location | knowledge/leetcode/leetcode.dz:651 |
1679_max_number_of_ksum_pairs | |
content | 1679: Max number of ksum pairs |
parents | leetcode/paradigms/two_pointer, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/max-number-of-k-sum-pairs |
location | knowledge/leetcode/leetcode.dz:657 |
643_maximum_average_subarray | |
content | 643: maximum average subarray |
children | leetcode/references/prefix_sum (editorial used a cumulative sum to solve this,,AKA prefix sum. It was a little strange.) |
parents | leetcode/paradigms/sliding_window, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/maximum-average-subarray-i |
location | knowledge/leetcode/leetcode.dz:663 |
1456_max_vowels_in_substring | |
content | 1456 max vowels in a substring of given length |
children | python/boolean_value_coercion (coercing bools to ints shaves some lines off code) |
parents | leetcode/paradigms/sliding_window, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length |
location | knowledge/leetcode/leetcode.dz:675 |
1004_max_consecutive_ones_iii | |
content | 1001 Max consecutive ones iii |
parents | leetcode/paradigms/sliding_window |
hyperlink | https://leetcode.com/problems/max-consecutive-ones-iii |
location | knowledge/leetcode/leetcode.dz:681 |
1493_longest_subarray_ones_deleting_elem | |
content | 1493: Longest Subarray of Ones after deleting one element |
parents | leetcode/paradigms/sliding_window, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element |
location | knowledge/leetcode/leetcode.dz:686 |
1732_find_highest_altitude | |
content | 1732: find highest altitude |
parents | leetcode/paradigms/prefix_sum, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/find-the-highest-altitude |
location | knowledge/leetcode/leetcode.dz:692 |
724_pivot_index | |
content | 724 Pivot Index |
parents | leetcode/paradigms/prefix_sum, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/find-pivot-index |
location | knowledge/leetcode/leetcode.dz:698 |
2215_difference_two_arrays | |
content | 2215: Find the difference of two arrays |
children | python/docs/stdtypes/set/difference, python/docs/stdtypes/set/intersection (Got familiar with intersection method for this problem) |
parents | leetcode/data_structures/set, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/find-the-difference-of-two-arrays |
location | knowledge/leetcode/leetcode.dz:707 |
1207_unique_number_of_occurrences | |
content | 1207: unique number of occurrences |
parents | leetcode/data_structures/hash_table, leetcode/data_structures/set, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/unique-number-of-occurrences |
location | knowledge/leetcode/leetcode.dz:716 |
1657_close_strings | |
content | 1657: Determine if two strings are close |
parents | leetcode/data_structures/hash_table, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/determine-if-two-strings-are-close |
location | knowledge/leetcode/leetcode.dz:723 |
2352_equal_row_column_pairs | |
content | 2352: Equal row and column pairs |
children | python/docs/glossary/hashable (Tuples are hashable, which you can use to build up a counter map to solve this problem efficiently) |
parents | leetcode/leetcode75, leetcode/data_structures/hash_table |
hyperlink | https://leetcode.com/problems/equal-row-and-column-pairs |
location | knowledge/leetcode/leetcode.dz:729 |
2390_removing_stars_from_a_string | |
content | 2390: removing stars from a string |
children | python/pop_on_empty_stack (Figured out a clever way to pop on empty stacks to day) |
parents | leetcode/data_structures/stack, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/removing-stars-from-a-string |
location | knowledge/leetcode/leetcode.dz:735 |
735_asteroid_collision | |
content | 735: Asteroid Collision |
children | python/docs/reference/while (I fed my solution into claude, and it used an "else",clause in the while loop, which I didn't know you could,do.) |
parents | leetcode/data_structures/stack, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/asteroid-collision |
location | knowledge/leetcode/leetcode.dz:741 |
349_decode_string | |
content | 394: Decode String |
parents | leetcode/data_structures/stack, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/decode-string |
location | knowledge/leetcode/leetcode.dz:747 |
933_number_of_recent_cals | |
content | 933: Number of recent calls |
parents | leetcode/data_structures/queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/number-of-recent-calls |
location | knowledge/leetcode/leetcode.dz:753 |
649_dota2_senate | |
content | 649: Dota2 Senate |
parents | leetcode/data_structures/queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/dota2-senate |
location | knowledge/leetcode/leetcode.dz:759 |
2095_delete_middle_node | |
content | 2095 Delete the middle of a node in linked list |
parents | leetcode/data_structures/linked_list, leetcode/references/floyds_algorithm, leetcode/data_structures/linked_list/fast_slow_pointer, 141_linked_list_cycle, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list |
location | knowledge/leetcode/leetcode.dz:765 |
328_odd_even_linked_list | |
content | 328: Odd/even linked list |
parents | leetcode/data_structures/linked_list, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/odd-even-linked-list |
location | knowledge/leetcode/leetcode.dz:787 |
2130_max_twin_sum_linked_list | |
content | 2130: Maximum twin sum of a linked list |
children | 206_reverse_linked_list (One solution to 2130 involves reversing the second,half of a linked list) |
parents | leetcode/data_structures/linked_list, leetcode/data_structures/linked_list/fast_slow_pointer, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list |
location | knowledge/leetcode/leetcode.dz:793 |
206_reverse_linked_list | |
content | 206: reverse linked list |
parents | 2130_max_twin_sum_linked_list, leetcode/data_structures/linked_list, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/reverse-linked-list |
location | knowledge/leetcode/leetcode.dz:802 |
872_leaf_similar_trees | |
content | 872 Leaf Simlar Trees |
parents | leetcode/data_structures/binary_tree, python/docs/reference/expressions/yield, python/docs/glossary/generator_iterator, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/leaf-similar-trees |
location | knowledge/leetcode/leetcode.dz:811 |
2024-12-10 13:36 Looks like my first solution was the approach The editorial solution has something very slick with yield() syntax.
1448_count_good_nodes | |
content | 1448: Count good nodes |
parents | leetcode/data_structures/binary_tree, leetcode/paradigms/depth_first_search, python/docs/reference/simple_statements/nonlocal, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/count-good-nodes-in-binary-tree/ |
location | knowledge/leetcode/leetcode.dz:817 |
437_path_sum_iii | |
content | 432 path sum ii |
children | 560_subarray_sum_equals_k (560 helps to understand the solution in 437) |
parents | leetcode/data_structures/binary_tree, leetcode/paradigms/depth_first_search, leetcode/leetcode75, leetcode/paradigms/prefix_sum |
hyperlink | https://leetcode.com/problems/path-sum-iii |
location | knowledge/leetcode/leetcode.dz:824 |
560_subarray_sum_equals_k | |
content | 560 Subarray Sum Equals K |
parents | 437_path_sum_iii, leetcode/data_structures/hash_table, leetcode/paradigms/prefix_sum |
hyperlink | https://leetcode.com/problems/subarray-sum-equals-k |
location | knowledge/leetcode/leetcode.dz:833 |
2024-12-12 10:31 looking at 560 to understand 437 2024-12-12 11:26 currently tripped on grokking 560 The solution in this problem involves using a hashmap counter, with this sort of logic:
= #+BEGINSRC
= What is bothering me is that the counter is always updating. A situation could occur where this hashmap entry is tapped more than once, making things get counted twice. 2024-12-12 11:33 I think I grok this actually
I think this has to mean you reset to zero at some point, so all those elements can get counted again. I can't dwell on this too long, this will have to do.1372_longest_zigzag_path | |
content | 1372: Longset ZigZag path in binary tree |
parents | leetcode/data_structures/binary_tree, leetcode/paradigms/depth_first_search, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree |
location | knowledge/leetcode/leetcode.dz:841 |
1161_max_level_sum_binary_tree | |
content | 1161: Maximum level sum of a binary tree |
parents | leetcode/data_structures/binary_tree, leetcode/paradigms/breadth_first_search, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree |
location | knowledge/leetcode/leetcode.dz:848 |
700_binary_search_tree | |
content | 700 Binary Search Tree |
parents | leetcode/data_structures/binary_search_tree, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/search-in-a-binary-search-tree |
location | knowledge/leetcode/leetcode.dz:855 |
450_delete_node_BST | |
content | 450: Delete a node in a BST |
children | leetcode/references/tree_rotation (I initially approached this problem thinking I could,do a tree rotation, but this turns out to not be correct) |
parents | leetcode/data_structures/binary_search_tree, leetcode/references/binary_search_tree/deletion, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/delete-node-in-a-bst |
location | knowledge/leetcode/leetcode.dz:861 |
2024-12-12 14:20 Solution here updates node values, but not the reference to the node I was initially imagining a solution that involved moving the reference to the node itself. What this algorithm does instead is update the value of the node to be deleted with either the predecessor/successor, then delete the predecessor in the previous position. This happens recursively until leaves are found.
841_keys_and_rooms | |
content | 841 Keys and Rooms |
parents | python/docs/stdlib/functions/all, leetcode/paradigms/depth_first_search, leetcode/data_structures/graph, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/keys-and-rooms |
location | knowledge/leetcode/leetcode.dz:898 |
547_number_of_provinces | |
content | 547: number of provinces |
parents | leetcode/paradigms/depth_first_search, leetcode/data_structures/graph, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/number-of-provinces/ |
location | knowledge/leetcode/leetcode.dz:908 |
1466_reorder_routes_to_city_zero | |
content | Reorder routes to make all paths lead to the city zero |
parents | python/docs/stdlib/data_types/collections/defaultdict, leetcode/paradigms/depth_first_search, leetcode/data_structures/graph, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero |
location | knowledge/leetcode/leetcode.dz:915 |
399_evaluate_division | |
content | 399: Evaluate division |
parents | leetcode/paradigms/depth_first_search, leetcode/data_structures/graph, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/evaluate-division |
location | knowledge/leetcode/leetcode.dz:922 |
1926_nearest_exit_from_entrance_in_maze | |
content | 1926: nearest exit from entrance in maze |
parents | leetcode/paradigms/breadth_first_search, leetcode/data_structures/graph, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/nearest-exit-from-entrance-in-maze |
location | knowledge/leetcode/leetcode.dz:929 |
215_kth_largest_element | |
content | 215: kth largest element in an array |
parents | leetcode/data_structures/priority_queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/kth-largest-element-in-an-array |
location | knowledge/leetcode/leetcode.dz:936 |
2024-12-13 19:41 Forgot how to use heapq
2336_smallest_number_in_infinite_set | |
content | 2336: smallest number in infinite set |
parents | leetcode/data_structures/priority_queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/smallest-number-in-infinite-set |
location | knowledge/leetcode/leetcode.dz:945 |
2542_maximum_subsequence_score | |
content | 2542: maximum subsequence score |
parents | python/docs/stdlib/zip, leetcode/data_structures/priority_queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/maximum-subsequence-score |
location | knowledge/leetcode/leetcode.dz:951 |
2024-12-15 18:41 Do we have to sort the nums2 list?
2462_total_cost_hire_k_workers | |
content | 2462: total cost to hire k workers |
parents | leetcode/data_structures/priority_queue, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/total-cost-to-hire-k-workers |
location | knowledge/leetcode/leetcode.dz:957 |
2024-12-19 10:45 Grokking intuition for initial filling of queues I've been struggling with a bit of logic here in the editorial solution. It has to do with how to initially fill up the two queues. This is the thing that was tripping me up. There are two queues to pop from: the head and the tail. --- The head fills up the first
candidates
, but the tail uses max(candidates, len(costs) - candidates)
. This is used to prevent overlap, but my brain is having a hard time being convinced of this. --- Most of the time, the starting position of the tail will be len(costs) - candidates)
. The end position of the head will always be at the position candidates - 1
. To prevent overlap, the start of the tail needs to be at least at index candidates
, so if len(costs) - candidates
is smaller than that, go with candidates.374_guess_number_lower_higher | |
content | 374: Guess number lower or higher |
parents | leetcode/paradigms/binary_search, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/guess-number-higher-or-lower |
location | knowledge/leetcode/leetcode.dz:963 |
2300_successful_pairs_potions_spells | |
content | 2300: successful pairs of potions and spells |
parents | python/docs/stdlib/bisect/bisect_left, leetcode/paradigms/binary_search, python/docs/stdlib/bisect, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/successful-pairs-of-spells-and-potions |
location | knowledge/leetcode/leetcode.dz:969 |
162_find_peak_element | |
content | 162: find peak element |
parents | leetcode/paradigms/binary_search, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/find-peak-element/ |
location | knowledge/leetcode/leetcode.dz:975 |
216_combination_sum_iii | |
content | 216: combination sum iii |
parents | leetcode/paradigms/backtracking, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/combination-sum-iii |
location | knowledge/leetcode/leetcode.dz:981 |
1137_nth_tribonacci_number | |
content | 1137: Nth tribonacci number |
parents | leetcode/paradigms/dynamic_programming/1d, leetcode/paradigms/dynamic_programming, leetcode/explore/dynamic_programming/1_strategic_approach/2_examples, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/n-th-tribonacci-number |
location | knowledge/leetcode/leetcode.dz:987 |
2025-01-01 10:22 Onto tribbonacci, top down, bottoms up
746_min_cost_climbing_stairs | |
content | 746: minimum cost of climbing stairs |
parents | leetcode/paradigms/dynamic_programming/1d, leetcode/paradigms/dynamic_programming, leetcode/explore/dynamic_programming/1_strategic_approach/2_examples, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/min-cost-climbing-stairs |
location | knowledge/leetcode/leetcode.dz:998 |
2025-01-01 09:53 More climbing stairs again I needed to look at the solution. The recurrence relation is still a bit fuzzy for me. I'm not grokking the optimal substructure. 2025-01-01 10:15 Continued Going for both top-down and bottoms up.
790_domino_tromino_tiling | |
content | 790: domino and tromino tiling |
parents | leetcode/paradigms/dynamic_programming/1d, leetcode/paradigms/dynamic_programming, python/docs/stdlib/functools/cache, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/domino-and-tromino-tiling |
location | knowledge/leetcode/leetcode.dz:1005 |
1143_longest_common_subsequence | |
content | 1143: longest common subsequence |
children | leetcode/references/longest_common_subsequence, 1143_longest_common_subsequence/solutions |
parents | leetcode/explore/dynamic_programming/1_strategic_approach/5_examples_multidimensional, leetcode/paradigms/dynamic_programming/2d, leetcode/paradigms/dynamic_programming, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/longest-common-subsequence |
location | knowledge/leetcode/leetcode.dz:1012 |
2025-01-01 14:57 dynamic programming explore card figured out top-down solution by myself. 2025-01-01 15:19 attempt to work out bottoms up solution
714_best_time_buy_sell_stock_transaction_free | |
content | 714: Best time to buy/sell stock transaction fee |
parents | leetcode/paradigms/dynamic_programming, leetcode/paradigms/dynamic_programming/2d, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee |
location | knowledge/leetcode/leetcode.dz:1066 |
2024-12-28 11:22 How far I got with my own intution I knew it was a 2d dynamic programming problem because it told me on LC75. I did not write any code. I spent most of my time trying to get the table right. --- You can go bottoms-up to find the max profit. Start by looking between two days. It will either be 0 or the difference between the two days (minus the fee) if it's positive. From there you can build up, gradually adding days. --- The thing that's tripping me up is how you start accumulating buy/sell pairs. I'm missing that logic in my table. 2024-12-28 11:33 I need a small break from this problem I can't read the editorial will return later today?
136_single_number | |
parents | leetcode/paradigms/bit_manipulation, 137_single_number_2, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/single-number/ |
location | knowledge/leetcode/leetcode.dz:1084 |
198_house_robber | |
content | 198 house robber |
parents | leetcode/explore/dynamic_programming/1_strategic_approach/2_examples, leetcode/paradigms/dynamic_programming/1d, leetcode/leetcode75, leetcode/explore/dynamic_programming/0_intro/3_when_to_use/2_future_decisions_depend_on_earlier_ones |
hyperlink | https://leetcode.com/problems/house-robber/ |
location | knowledge/leetcode/leetcode.dz:1450 |
2025-01-01 11:08 House robber, again I'm trying to grok the pattern. Trying to grok better.
300_longest_increasing_subsequence | |
content | 300: longest increasing subsequence |
parents | leetcode/explore/dynamic_programming/0_intro/3_when_to_use/2_future_decisions_depend_on_earlier_ones |
hyperlink | https://leetcode.com/problems/longest-increasing-subsequence |
location | knowledge/leetcode/leetcode.dz:1456 |
70_climbing_stairs | |
content | 70: climbing stairs |
parents | leetcode/paradigms/dynamic_programming/1d, leetcode/paradigms/dynamic_programming, leetcode/explore/dynamic_programming/1_strategic_approach/1_framework |
hyperlink | https://leetcode.com/problems/climbing-stairs |
location | knowledge/leetcode/leetcode.dz:1466 |
740_delete_and_earn | |
content | 740 delete and earn |
parents | leetcode/explore/dynamic_programming/1_strategic_approach/2_examples, leetcode/paradigms/dynamic_programming, leetcode/paradigms/dynamic_programming/1d |
hyperlink | https://leetcode.com/problems/delete-and-earn |
location | knowledge/leetcode/leetcode.dz:1472 |
2025-01-01 10:42 Delete and earn Hints and similar problems tells me it's like house robber, so I want to do house robber again. 2025-01-01 11:22 Back to delete and earn 2025-01-01 11:35 looking at editorial
1659_maximize_grid_happiness | |
content | 1659: maximize grid happiness |
parents | leetcode/explore/dynamic_programming/1_strategic_approach/3_multidimensional, leetcode/paradigms/dynamic_programming |
hyperlink | https://leetcode.com/problems/maximize-grid-happiness/ |
location | knowledge/leetcode/leetcode.dz:1484 |
1770_max_score_multiplication_operations | |
content | 1770: maximum score for multiplication operations |
parents | python/docs/stdlib/functools/lru_cache, leetcode/explore/dynamic_programming/1_strategic_approach/5_examples_multidimensional |
hyperlink | https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations |
location | knowledge/leetcode/leetcode.dz:1491 |
2025-01-01 12:46 1770 was the case study Implemented top down and bottoms up approach using the the case study. Bottoms-up I messed up with some off-by-one errors because I turned there awkward range functions into reversed iterables using
reversed
146_LRU_cache | |
content | 146: LRU cache |
parents | python/docs/stdlib/functools/lru_cache |
hyperlink | python/docs/stdlib/functools#lru_cache |
location | knowledge/leetcode/leetcode.dz:1495 |
221_maximal_square | |
content | 221: Maximal Square |
parents | leetcode/paradigms/dynamic_programming, leetcode/paradigms/dynamic_programming/2d, leetcode/explore/dynamic_programming/1_strategic_approach/5_examples_multidimensional |
location | knowledge/leetcode/leetcode.dz:1499 |
2025-01-01 15:19 dynamic programming explore card 2025-01-01 16:25 looking at editorial 2025-01-01 17:51 an attempt to do a top-down solution It would be nice to try and get a top-down version. There's also a "better solution" 2025-01-01 18:03 close to top-down derivation 2025-01-01 18:20 got it! The trick was returning 0. I'm also noticing that I need to store the maximum globally with both. That could be a pattern to think about for some "find the max" problems 2025-01-01 18:20 studying the "better" solution in the editorial Didn't really grok it, but it's basically a space optimized bottoms-up solution.
1335_minimum_difficulty_job_schedule | |
content | 1335: minimum difficulty of a job schedule |
parents | leetcode/explore/dynamic_programming/2_common_patterns/2_examples |
hyperlink | https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule |
location | knowledge/leetcode/leetcode.dz:1504 |
2025-01-02 18:52 dynamic programming explore card I'm still grokking 1335. The problem, and the solution. Even with both spelled out for me in the dynamic programming explore card, it's still difficult.
72_edit_distance | |
content | 72: edit distance |
children | TADM/toc/08_dynamic_programming/02_approximate_string_matching (Edit distance problem is a case study in TADM) |
parents | leetcode/paradigms/dynamic_programming/2d, leetcode/paradigms/dynamic_programming, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/edit-distance/ |
location | knowledge/leetcode/leetcode.dz:1508 |
2025-01-03 08:50 Morning attempt Got some broken code. I don't think I have the intuition yet. I vaguely remember this problem from the algorithms book. I was scared of it then. I am scared of it now. I'm trying to follow the framework outlined in the dynamic programming explore card. I identified the variables (index position), and am now trying to implement the top-down version. It's not going well. 2025-01-04 10:00 another shot I'm trying to follow the framework again. Here are my thoughts on it so far. --- what are the state variables? how are we storing them? state variables can be indice substrings of both strings. the function dp(i, j) tells us: given substrings w1[0:i] and w2[0:j], what are the minimum number of operations required transform w1 to w2. our first approach will be top-down, so these will parameters to a function --- what is the recurrence relation? There are 3 operations to consider, plus 1 non-op (match) Insert a character: (ac, abc) -> (a[b]c, abc) 1 point, i + 1, j + 1 Delete a character: (adbc, abc) -> (a[]bc, abc) and vice versa? 1 point i + 1, j, or i, j + 1 (delete seems to be the edge case) Replace a character: (axc, abc) -> (a[b]c, abc) 1 point, i + 1, j + 1 --- dp(i, j) = min(insert, delete, remove) + dp(i - 1, j - 1) = min(dp(i + 1, j + 1), min(dp(i + 1, j), dp(i, j + 1))) + dp(i - 1, j - 1) --- I don't like the forward/backward of this 2025-01-05 12:18 Reading Skiena He has this as a case study 2025-01-05 12:42 Banged out a top-down solution I had to use the Skiena code for reference 2025-01-05 13:10 Bottoms-up solution is a WIP. will need to return later to it. I'm trying to mechanically copy it over from the top-down solution that works. I think I am missing something in the initialization step. I've worked too long on it today, and need to move forward.
338_counting_bits | |
content | 338: Counting bits |
parents | leetcode/paradigms/bit_manipulation, leetcode/leetcode75 |
hyperlink | https://leetcode.com/problems/counting-bits/ |
location | knowledge/leetcode/leetcode.dz:1522 |
2025-01-03 09:22 Brute force works 2025-01-03 09:39 Close to giving up on the O(n) solution My intuition so far: check the LSB. If it's a 0, you are only flipping one bit, so it's the previous 1 count plus 1. If it is a 1, then more bits get flipped. I have an inkling that you can do something with the previous zero LSB number. 2025-01-03 09:48 got linear time working I had the right line of thinking, I just needed to put more care into the code: the previous number vs the previous number of bits. If the previous number has a 1 LSB, it's not a simple +1 like if it were a 0 LSB. The LSB for the number flip to 0, so somehow I realized that you could look at the shared bits between the last 0 LSB (prev - 1), and then add 1 to that. I don't know, I wish I could explain this better. I wrote out the binary bits and looked for patterns.
677_map_sum_pairs | |
content | 677: Map Sum Pairs |
parents | leetcode/explore/trie/3_practical_application_1, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/map-sum-pairs |
location | knowledge/leetcode/leetcode.dz:1542 |
648_replace_words | |
content | 648: Replace Words |
parents | leetcode/explore/trie/3_practical_application_1, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/replace-words |
location | knowledge/leetcode/leetcode.dz:1547 |
2025-01-05 16:16 Replace Words
642_design_search_autocomplete_system | |
content | 642: Design Search Autocomplete System |
parents | leetcode/explore/trie/3_practical_application_1/autocomplete, leetcode/explore/trie/3_practical_application_1, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/design-search-autocomplete-system/description/ |
location | knowledge/leetcode/leetcode.dz:1552 |
2025-01-05 16:42 Attempting auto-complete search system It's part of the Trie explore card. It's also a "hard", which gives me pause. I'm not expecting to solve it all today, so I will document my attempts here. 2025-01-05 16:51 Hashtag usage is unclear to me At first I read it as being a sort of null terminator for every sentence. But I don't see that. I think it just a special mode for nothing. 2025-01-05 16:54 Hashtag usage is clearer to me It seems to be like it's a way to add user submitted inputs into the system. --- Wait, input is a single character from a keystroke. '#' at the end means: take the characters seen so far and find the hot sentences with that matching prefix. --- The state kept track of then would be the last node visited. For every key, update the last node visisted. Traverse this node, and find the top 3 matches 2025-01-05 16:54 Use a maxheap A maxheap of size 3 could be used to populate the top 3 matches. How it works is, for the top-level node in trie, traverse through children nodes, and add them onto the heap. --- If the nodes have a parent pointer, that can be used to backtrack and reproduce the sentence. 2025-01-05 16:54 more thoughts I wondered: is the heap persistant between calls to input()? No. Because you are refining the options. --- The '#' operation. Needs to be inserted into the root trie, and the count updated by 1. A new sentence may or may not share a prefix, so I think keyboard history needs to be stored. --- What happens after '#'? new sentence? 2025-01-05 16:54 initial logic close Trie structure and heap logic works. but, I forgot that I can't push nodes themselves becaues heaps don't have a built in comparison (and I need it to sort alphabetically). So, the heap needs to push the actual sentences as strings. --- In theory, I could figure out a way to enumerate each full path of the Trie using DFS. I will return to this, after dinner. 2025-01-05 18:14 continuing the attempt 2025-01-05 18:14 heapq isn't behaving as expected It seems to be doing reverse ascii order 2025-01-05 18:40 initial test passes, but it is incomplete Turns out, I need to use a maxheap, and I need to store all the values in the heap and not pop to keep a minimum size. This is because the insertion order can accidentally remove the wrong thing with the same count. --- I have not done anything with '#' yet, so I imagine this system will fail. 2025-01-05 18:55 got it accepted! concluding thoughts The bug that caught up to me was related to the logic involved with sentences being made that aren't in the Trie. Once there isn't a match, there needs to be a way to ensure that the system doesn't continue matching. --- My approach keeps track of the last visted node in the Trie. What I needed to was set this to be None so that it subsequent inputs wouldn't try searching the node. --- In retrospect, was keeping track of the last node such a great move? I wonder if it would just be better to cache the sentence, and then do a full prefix search to check. This could also make the sentence query logic easier too. Prefix search could return the last node, which could the be traversed.
211_design_add_and_search_words_data_structure | |
content | 211: Design add and search words data structur |
parents | leetcode/explore/trie/3_practical_application_1/spell_checker, leetcode/explore/trie/3_practical_application_1, leetcode/grind75, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/design-add-and-search-words-data-structure/ |
location | knowledge/leetcode/leetcode.dz:1557 |
2025-01-05 19:38 Trying 211 I did this one before, and recall having a bit of a time with it. 2025-01-05 20:21 Breaking at edge cases I think my logic is write: build a trie, and use a stack with tuple(position, node) for DFS. When it's a letter, you're pushing and popping evenly. When a '.' appears, all children are candidates. Some edge cases with very long inputs break it. 2025-01-05 20:28 Figured it out My approach, was correct, but I messed up the control flow. There was a point where I was breaking out too early by returning false, when it should have been a continue. "True" happens on the first node with a terminal whose path is the length of the word; any valid path can work, so this can break early on the first. False only happens when the stack is emptied and there are no more nodes to traverse, or the path length exceeds the word length.
208_implement_trie | |
content | 208: implement trie |
parents | leetcode/explore/trie/2_basic_operations, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/implement-trie-prefix-tree |
location | knowledge/leetcode/leetcode.dz:1563 |
421_max_XOR_two_numbers | |
content | 421: Maximum XOR of two numbers in an array |
parents | leetcode/explore/trie/4_practical_application_2, leetcode/explore/trie/4_practical_application_2/store_other_data_type, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array |
location | knowledge/leetcode/leetcode.dz:1574 |
2025-01-06 11:15 Maximum XOR of two numbers 2025-01-06 11:18 Might as well do brute force first 2025-01-06 11:24 Actually attempting the problem now They say it's a trie data structure problem, so I'm assuming you put bits in the trie. Not sure where to go from there because XORs keep falling out of my head. Going to pen and paper. 2025-01-06 11:40 Drew the tree for first example It turns into some kind of DFS tree traversal problem 2025-01-06 11:56 Intuition Building This turns into a DFS prefix tree (trie) problem. Put the numbers in the tree, LSB to MSB, and then traverse to find maximum XOR pair. --- For any two numbers with a shared prefix, the total output is zero. When the node has two children, that's a XOR with a value of
1 << L
= where L is the level. --- How do we make this a recursive problem? I have some vague intuition that at the start of the tree (None), you traverse the children and figure out which one has the greater XOR. 2025-01-06 12:22 Stopping for now
Still grokking the traversal logic, I shall return. 2025-01-06 13:26 Continuing progress
2025-01-06 13:38 Building the Trie and then doing some kind of search is still linear
I've had it set that the problem must be a traversal problem, but maybe it's just a matter of somehow building the Trie, then XORing each number with the Trie? 2025-01-06 13:38 Xoring on the tree... is it actually better than brute force?
You still need to check every path. 2025-01-06 14:10 Okay enough struggle. Looking at editorial now.
2025-01-06 14:27 Stopping for now. Brain is not grokking the editorial.
Potentially a good candidate for a mini codestudy? I want to make it painless to set up new mini code studies, so this could be a good start. 2025-01-06 16:28 codestudy scaffolding, and initial words
This ended up taking more time because I'm still setting up infrastructure for this codestudy stuff.79_word_search | |
content | 79: Word Search |
parents | leetcode/explore/trie/4_practical_application_2, leetcode/explore/trie/4_practical_application_2/accelerate_dfs, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/word-search |
location | knowledge/leetcode/leetcode.dz:1606 |
2025-01-06 12:27 79 Word Search DFS approach It appears I did this one back in novemeber. I vaguely recall struggling. 2025-01-06 12:40 How to backtrack? There needs to be a way to backtrack if you find a close candidate, how do those get returned? --- I'm using an explicit stack, but it might be easier to solve with recursion. You can use substrings. 2025-01-06 12:57 Feeling close with this recursive solution, but edgecases are killing me It's the single-row edge cases that are failing 2025-01-06 13:14 Visited set is local, but now another edge case 2025-01-06 13:21 My traversal logic appears to be broken I'm not keeping track of visited nodes correctly. When a new attempt is started, all the other nodes should be visible. At the same time, there also needs to be a way to mark progress so that the graph has been fully traveresed. --- I will need to think on this. Will return later. 2025-01-07 14:56 back to wordsearch 2025-01-07 15:03 I have reset the code, thinking again about this problem 2025-01-07 15:10 new approach: multiple DFS instead of just one
This is how I'm thinking about it: --- iterate through grid, and find top-node candidates --- For each top-node, perform DFS to try and find path --- return true on first successful path --- return false otherwise 2025-01-07 15:29 traversal logic broken again
This time, on a different edge case. I think my "visited" tracking is broken. I'm marking things as visited whenever they are traversed, but this causes problems if they need to be traversed later. It's the same problem as before. --- visited shold only contain nodes in the currently traversed path. once it's no longer being considered in the current position of the current path, it should be returned somehow. 2025-01-07 15:34 Incredible, the edge cases keep piling up. This problem is frustrating because you can make small tweaks to solve one edge case, only to run into another. I just moved my "visited" logic a few lines down. It solved one edge case, found another. 2025-01-07 15:47 Try recursion instead of using a stack I think it will be easier to implement. I don't think I'm getting the stack logic correct. 2025-01-07 15:54 My recursive DFS approach works now! 2025-01-07 15:59 Now, we try for trie. 2025-01-07 16:14 Trie thoughts so far Okay, they probably want me to build a trie, then see if the word is in the Trie --- But, that can't be right. Building a Trie for all the possibilities seems enormously expensive --- Trie is about prefixes, so maybe one gets dynamically built. So, prefixes of the word. --- The hint here is that this is used to speed up DFS. So maybe this is a way to keep track of paths found? --- I don't know how the trie would be able to keep track of previously visited. 2025-01-07 16:30 Use Trie as a cache? If you ignore position, you could absolutely build up a tree that indicates for each letter, what all the directional possibilities are. 2025-01-07 16:48 I think I might have an idea The Trie structure here has depth of the length of the word, with each level i corresponding to the letter at index i of word. Begin by populating the root node of the Trie. The children will be the positions of all the nodes with the letter at index 0. Iterate through the children of those nodes, and see which of those positions can connect to the next letter (repeats are okay for now). This happens until there are no more letters or children. From there, attempt to find a match in the Trie, and check to ensure there are no repeats. 2025-01-07 17:03 And this is where I'll leave it for now. Will implement some other time Ran out of time. But I'll let the idea sit with me for a bit. The nice thing about this logging system is that it's easier for things to "carry over" into other days.212_word_search_2 | |
content | 212: Word Search 2 |
parents | leetcode/explore/trie/4_practical_application_2, leetcode/explore/trie/4_practical_application_2/accelerate_dfs, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/word-search-ii |
location | knowledge/leetcode/leetcode.dz:1612 |
336_palindrome_pairs | |
content | 336: Palindrome Pairs |
parents | leetcode/explore/trie/4_practical_application_2, leetcode/data_structures/trie |
hyperlink | https://leetcode.com/problems/palindrome-pairs |
location | knowledge/leetcode/leetcode.dz:1618 |