From e213fa5151f85b453d3fbde4fb0d45bef8f5da72 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Mon, 10 Feb 2025 20:25:14 +0200 Subject: [PATCH] Improved racket --- .../g0001_0100/s0001_two_sum/Solution.rkt | 2 +- .../s0002_add_two_numbers/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../s0006_zigzag_conversion/Solution.rkt | 2 +- .../s0007_reverse_integer/Solution.rkt | 2 +- .../s0008_string_to_integer_atoi/Solution.rkt | 3 +- .../s0009_palindrome_number/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../racket/g0001_0100/s0015_3sum/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../s0020_valid_parentheses/Solution.rkt | 2 +- .../s0021_merge_two_sorted_lists/Solution.rkt | 2 +- .../s0022_generate_parentheses/Solution.rkt | 2 +- .../s0023_merge_k_sorted_lists/Solution.rkt | 3 +- .../s0024_swap_nodes_in_pairs/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../s0035_search_insert_position/Solution.rkt | 2 +- .../s0039_combination_sum/Solution.rkt | 2 +- .../s0041_first_missing_positive/Solution.rkt | 2 +- .../s0042_trapping_rain_water/Solution.rkt | 2 +- .../s0045_jump_game_ii/Solution.rkt | 2 +- .../s0046_permutations/Solution.rkt | 2 +- .../s0049_group_anagrams/Solution.rkt | 2 +- .../g0001_0100/s0051_n_queens/Solution.rkt | 2 +- .../s0053_maximum_subarray/Solution.rkt | 2 +- .../g0001_0100/s0055_jump_game/Solution.rkt | 2 +- .../s0056_merge_intervals/Solution.rkt | 2 +- .../s0062_unique_paths/Solution.rkt | 2 +- .../s0064_minimum_path_sum/Solution.rkt | 2 +- .../s0070_climbing_stairs/Solution.rkt | 2 +- .../s0072_edit_distance/Solution.rkt | 2 +- .../s0074_search_a_2d_matrix/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../g0001_0100/s0078_subsets/Solution.rkt | 2 +- .../g0001_0100/s0079_word_search/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../s0101_symmetric_tree/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../s0136_single_number/Solution.rkt | 2 +- .../g0101_0200/s0139_word_break/Solution.rkt | 3 +- .../g0101_0200/s0146_lru_cache/LRUCache.rkt | 2 +- .../g0101_0200/s0148_sort_list/Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../Solution.rkt | 2 +- .../g0101_0200/s0155_min_stack/MinStack.rkt | 2 +- .../s0169_majority_element/Solution.rkt | 2 +- .../s0198_house_robber/Solution.rkt | 2 +- .../s0200_number_of_islands/Solution.rkt | 2 +- .../s0206_reverse_linked_list/Solution.rkt | 2 +- .../s0207_course_schedule/Solution.rkt | 23 ++++++++ .../s0207_course_schedule/readme.md | 33 +++++++++++ .../s0208_implement_trie_prefix_tree/Trie.rkt | 56 +++++++++++++++++++ .../readme.md | 40 +++++++++++++ .../Solution.rkt | 10 ++++ .../readme.md | 26 +++++++++ .../s0221_maximal_square/Solution.rkt | 24 ++++++++ .../g0201_0300/s0221_maximal_square/readme.md | 34 +++++++++++ .../s0226_invert_binary_tree/Solution.rkt | 28 ++++++++++ .../s0226_invert_binary_tree/readme.md | 32 +++++++++++ .../Solution.rkt | 30 ++++++++++ .../readme.md | 29 ++++++++++ .../s0234_palindrome_linked_list/Solution.rkt | 28 ++++++++++ .../s0234_palindrome_linked_list/readme.md | 28 ++++++++++ .../Solution.rkt | 23 ++++++++ .../readme.md | 29 ++++++++++ .../Solution.rkt | 19 +++++++ .../s0287_find_the_duplicate_number/readme.md | 33 +++++++++++ .../Solution.rkt | 39 +++++++++++++ .../readme.md | 34 +++++++++++ 85 files changed, 666 insertions(+), 65 deletions(-) create mode 100644 src/main/racket/g0201_0300/s0207_course_schedule/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0207_course_schedule/readme.md create mode 100644 src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/Trie.rkt create mode 100644 src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/readme.md create mode 100644 src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md create mode 100644 src/main/racket/g0201_0300/s0221_maximal_square/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0221_maximal_square/readme.md create mode 100644 src/main/racket/g0201_0300/s0226_invert_binary_tree/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0226_invert_binary_tree/readme.md create mode 100644 src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/readme.md create mode 100644 src/main/racket/g0201_0300/s0234_palindrome_linked_list/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0234_palindrome_linked_list/readme.md create mode 100644 src/main/racket/g0201_0300/s0238_product_of_array_except_self/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0238_product_of_array_except_self/readme.md create mode 100644 src/main/racket/g0201_0300/s0287_find_the_duplicate_number/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0287_find_the_duplicate_number/readme.md create mode 100644 src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/Solution.rkt create mode 100644 src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/readme.md diff --git a/src/main/racket/g0001_0100/s0001_two_sum/Solution.rkt b/src/main/racket/g0001_0100/s0001_two_sum/Solution.rkt index 8217229..ed59639 100644 --- a/src/main/racket/g0001_0100/s0001_two_sum/Solution.rkt +++ b/src/main/racket/g0001_0100/s0001_two_sum/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table ; #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Top_Interview_150_Hashmap ; #Big_O_Time_O(n)_Space_O(n) #AI_can_be_used_to_solve_the_task -; #2025_02_05_Time_0_(100.00%)_Space_102.04_(40.82%) +; #2025_02_05_Time_0_ms_(100.00%)_Space_102.04_MB_(40.82%) (define (two-sum-iter nums target hash index) (cond diff --git a/src/main/racket/g0001_0100/s0002_add_two_numbers/Solution.rkt b/src/main/racket/g0001_0100/s0002_add_two_numbers/Solution.rkt index d165f02..4cafe53 100644 --- a/src/main/racket/g0001_0100/s0002_add_two_numbers/Solution.rkt +++ b/src/main/racket/g0001_0100/s0002_add_two_numbers/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion ; #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15 ; #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) -; #AI_can_be_used_to_solve_the_task #2025_02_05_Time_0_(100.00%)_Space_128.08_(72.73%) +; #AI_can_be_used_to_solve_the_task #2025_02_05_Time_0_ms_(100.00%)_Space_128.08_MB_(72.73%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.rkt b/src/main/racket/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.rkt index 6e1c5a9..031b36d 100644 --- a/src/main/racket/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.rkt +++ b/src/main/racket/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window ; #Algorithm_I_Day_6_Sliding_Window #Level_2_Day_14_Sliding_Window/Two_Pointer #Udemy_Strings ; #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task -; #2025_02_06_Time_119_(71.43%)_Space_131.37_(28.57%) +; #2025_02_06_Time_119_ms_(71.43%)_Space_131.37_MB_(28.57%) ; Helper function to get the sublist up to 'v' excluded. (define (take-till q v) diff --git a/src/main/racket/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.rkt b/src/main/racket/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.rkt index a51e410..8b03348 100644 --- a/src/main/racket/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.rkt +++ b/src/main/racket/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.rkt @@ -1,6 +1,6 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer ; #Top_Interview_150_Binary_Search #Big_O_Time_O(log(min(N,M)))_Space_O(1) -; #AI_can_be_used_to_solve_the_task #2025_02_06_Time_0_(100.00%)_Space_128.80_(25.00%) +; #AI_can_be_used_to_solve_the_task #2025_02_06_Time_0_ms_(100.00%)_Space_128.80_MB_(25.00%) (define/contract (find-median-sorted-arrays nums1 nums2) (-> (listof exact-integer?) (listof exact-integer?) flonum?) diff --git a/src/main/racket/g0001_0100/s0005_longest_palindromic_substring/Solution.rkt b/src/main/racket/g0001_0100/s0005_longest_palindromic_substring/Solution.rkt index 472fa58..21a1904 100644 --- a/src/main/racket/g0001_0100/s0005_longest_palindromic_substring/Solution.rkt +++ b/src/main/racket/g0001_0100/s0005_longest_palindromic_substring/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming ; #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming ; #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP -; #Big_O_Time_O(n)_Space_O(n) #2025_02_06_Time_4_(100.00%)_Space_101.40_(85.71%) +; #Big_O_Time_O(n)_Space_O(n) #2025_02_06_Time_4_ms_(100.00%)_Space_101.40_MB_(85.71%) (define (longest-palindrome s) (define (expand-around-center s left right) diff --git a/src/main/racket/g0001_0100/s0006_zigzag_conversion/Solution.rkt b/src/main/racket/g0001_0100/s0006_zigzag_conversion/Solution.rkt index 64725eb..d8db552 100644 --- a/src/main/racket/g0001_0100/s0006_zigzag_conversion/Solution.rkt +++ b/src/main/racket/g0001_0100/s0006_zigzag_conversion/Solution.rkt @@ -1,5 +1,5 @@ ; #Medium #String #Top_Interview_150_Array/String -; #2025_02_03_Time_57_(100.00%)_Space_130.82_(60.00%) +; #2025_02_03_Time_57_ms_(100.00%)_Space_130.82_MB_(60.00%) (define/contract (convert s numRows) (-> string? exact-integer? string?) diff --git a/src/main/racket/g0001_0100/s0007_reverse_integer/Solution.rkt b/src/main/racket/g0001_0100/s0007_reverse_integer/Solution.rkt index 150d3b4..9392b66 100644 --- a/src/main/racket/g0001_0100/s0007_reverse_integer/Solution.rkt +++ b/src/main/racket/g0001_0100/s0007_reverse_integer/Solution.rkt @@ -1,5 +1,5 @@ ; #Medium #Top_Interview_Questions #Math #Udemy_Integers -; #2025_02_03_Time_204_(100.00%)_Space_101.45_(100.00%) +; #2025_02_03_Time_204_ms_(100.00%)_Space_101.45_MB_(100.00%) (define/contract (reverse x) (-> exact-integer? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0008_string_to_integer_atoi/Solution.rkt b/src/main/racket/g0001_0100/s0008_string_to_integer_atoi/Solution.rkt index ab83bca..10ebcd6 100644 --- a/src/main/racket/g0001_0100/s0008_string_to_integer_atoi/Solution.rkt +++ b/src/main/racket/g0001_0100/s0008_string_to_integer_atoi/Solution.rkt @@ -1,4 +1,5 @@ -; #Medium #Top_Interview_Questions #String #2025_02_03_Time_3_(100.00%)_Space_101.64_(100.00%) +; #Medium #Top_Interview_Questions #String +; #2025_02_03_Time_3_ms_(100.00%)_Space_101.64_MB_(100.00%) (define/contract (my-atoi s) (-> string? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0009_palindrome_number/Solution.rkt b/src/main/racket/g0001_0100/s0009_palindrome_number/Solution.rkt index dd224bd..8378b69 100644 --- a/src/main/racket/g0001_0100/s0009_palindrome_number/Solution.rkt +++ b/src/main/racket/g0001_0100/s0009_palindrome_number/Solution.rkt @@ -1,5 +1,5 @@ ; #Easy #Math #Udemy_Integers #Top_Interview_150_Math -; #2025_02_03_Time_8_(100.00%)_Space_129.01_(88.24%) +; #2025_02_03_Time_8_ms_(100.00%)_Space_129.01_MB_(88.24%) (define/contract (is-palindrome x) (-> exact-integer? boolean?) diff --git a/src/main/racket/g0001_0100/s0010_regular_expression_matching/Solution.rkt b/src/main/racket/g0001_0100/s0010_regular_expression_matching/Solution.rkt index 3a5f525..b24cddd 100644 --- a/src/main/racket/g0001_0100/s0010_regular_expression_matching/Solution.rkt +++ b/src/main/racket/g0001_0100/s0010_regular_expression_matching/Solution.rkt @@ -1,5 +1,5 @@ ; #Hard #Top_Interview_Questions #String #Dynamic_Programming #Recursion #Udemy_Dynamic_Programming -; #Big_O_Time_O(m*n)_Space_O(m*n) #2025_02_03_Time_11_(100.00%)_Space_101.36_(100.00%) +; #Big_O_Time_O(m*n)_Space_O(m*n) #2025_02_03_Time_11_ms_(100.00%)_Space_101.36_MB_(100.00%) (define (regex-state s is-star) (list s (if is-star '* '1))) diff --git a/src/main/racket/g0001_0100/s0011_container_with_most_water/Solution.rkt b/src/main/racket/g0001_0100/s0011_container_with_most_water/Solution.rkt index c24b9da..c0a1213 100644 --- a/src/main/racket/g0001_0100/s0011_container_with_most_water/Solution.rkt +++ b/src/main/racket/g0001_0100/s0011_container_with_most_water/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers ; #Algorithm_II_Day_4_Two_Pointers #Top_Interview_150_Two_Pointers #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_32_(100.00%)_Space_130.58_(100.00%) +; #2025_02_03_Time_32_ms_(100.00%)_Space_130.58_MB_(100.00%) (define/contract (max-area height) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0001_0100/s0015_3sum/Solution.rkt b/src/main/racket/g0001_0100/s0015_3sum/Solution.rkt index 620ecf3..09a97cd 100644 --- a/src/main/racket/g0001_0100/s0015_3sum/Solution.rkt +++ b/src/main/racket/g0001_0100/s0015_3sum/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers ; #Data_Structure_II_Day_1_Array #Algorithm_II_Day_3_Two_Pointers #Udemy_Two_Pointers ; #Top_Interview_150_Two_Pointers #Big_O_Time_O(n*log(n))_Space_O(n^2) -; #2025_02_03_Time_999_(100.00%)_Space_130.90_(100.00%) +; #2025_02_03_Time_999_ms_(100.00%)_Space_130.90_MB_(100.00%) (define (bin-search val left right items) (cond [(> left right) #f] diff --git a/src/main/racket/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.rkt b/src/main/racket/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.rkt index 0ea857d..16dbe73 100644 --- a/src/main/racket/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.rkt +++ b/src/main/racket/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking ; #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion ; #Top_Interview_150_Backtracking #Big_O_Time_O(4^n)_Space_O(n) -; #2025_02_03_Time_0_(100.00%)_Space_102.48_(_%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_102.48_MB_(_%) (define (letter-combinations digits) (let* ((letters (vector "" "" "abc" "def" "ghi" "jkl" "mno" "pqrs" "tuv" "wxyz")) diff --git a/src/main/racket/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.rkt b/src/main/racket/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.rkt index 1247837..14f9a72 100644 --- a/src/main/racket/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.rkt +++ b/src/main/racket/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Linked_List ; #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Top_Interview_150_Linked_List -; #Big_O_Time_O(L)_Space_O(L) #2025_02_03_Time_0_(100.00%)_Space_101.91_(_%) +; #Big_O_Time_O(L)_Space_O(L) #2025_02_03_Time_0_ms_(100.00%)_Space_101.91_MB_(_%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0020_valid_parentheses/Solution.rkt b/src/main/racket/g0001_0100/s0020_valid_parentheses/Solution.rkt index 48edd86..711fa26 100644 --- a/src/main/racket/g0001_0100/s0020_valid_parentheses/Solution.rkt +++ b/src/main/racket/g0001_0100/s0020_valid_parentheses/Solution.rkt @@ -1,6 +1,6 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack ; #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Top_Interview_150_Stack -; #Big_O_Time_O(n)_Space_O(n) #2025_02_03_Time_98_(100.00%)_Space_130.80_(100.00%) +; #Big_O_Time_O(n)_Space_O(n) #2025_02_03_Time_98_ms_(100.00%)_Space_130.80_MB_(100.00%) (define (is-left-paren c) (or (eq? c #\u28) diff --git a/src/main/racket/g0001_0100/s0021_merge_two_sorted_lists/Solution.rkt b/src/main/racket/g0001_0100/s0021_merge_two_sorted_lists/Solution.rkt index 9e81fb2..6d8df3c 100644 --- a/src/main/racket/g0001_0100/s0021_merge_two_sorted_lists/Solution.rkt +++ b/src/main/racket/g0001_0100/s0021_merge_two_sorted_lists/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion ; #Data_Structure_I_Day_7_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking ; #Level_1_Day_3_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List -; #Big_O_Time_O(m+n)_Space_O(m+n) #2025_02_03_Time_0_(100.00%)_Space_102.38_(66.67%) +; #Big_O_Time_O(m+n)_Space_O(m+n) #2025_02_03_Time_0_ms_(100.00%)_Space_102.38_MB_(66.67%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0022_generate_parentheses/Solution.rkt b/src/main/racket/g0001_0100/s0022_generate_parentheses/Solution.rkt index 5033f42..63b152a 100644 --- a/src/main/racket/g0001_0100/s0022_generate_parentheses/Solution.rkt +++ b/src/main/racket/g0001_0100/s0022_generate_parentheses/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming ; #Backtracking #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion ; #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n) -; #2025_02_03_Time_3_(100.00%)_Space_101.96_(100.00%) +; #2025_02_03_Time_3_ms_(100.00%)_Space_101.96_MB_(100.00%) (define (generate-parenthesis n) (let ([res '()]) diff --git a/src/main/racket/g0001_0100/s0023_merge_k_sorted_lists/Solution.rkt b/src/main/racket/g0001_0100/s0023_merge_k_sorted_lists/Solution.rkt index 81b0ecc..2908e87 100644 --- a/src/main/racket/g0001_0100/s0023_merge_k_sorted_lists/Solution.rkt +++ b/src/main/racket/g0001_0100/s0023_merge_k_sorted_lists/Solution.rkt @@ -1,6 +1,7 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List ; #Divide_and_Conquer #Merge_Sort #Top_Interview_150_Divide_and_Conquer -; #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) #2025_02_03_Time_306_(100.00%)_Space_130.68_(100.00%) +; #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) +; #2025_02_03_Time_306_ms_(100.00%)_Space_130.68_MB_(100.00%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0024_swap_nodes_in_pairs/Solution.rkt b/src/main/racket/g0001_0100/s0024_swap_nodes_in_pairs/Solution.rkt index 72d9107..2bb9458 100644 --- a/src/main/racket/g0001_0100/s0024_swap_nodes_in_pairs/Solution.rkt +++ b/src/main/racket/g0001_0100/s0024_swap_nodes_in_pairs/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_12_Linked_List ; #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_0_(100.00%)_Space_101.59_(100.00%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_101.59_MB_(100.00%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.rkt b/src/main/racket/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.rkt index 515677b..cc8b2dc 100644 --- a/src/main/racket/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.rkt +++ b/src/main/racket/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.rkt @@ -1,6 +1,6 @@ ; #Hard #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_13_Linked_List ; #Udemy_Linked_List #Top_Interview_150_Linked_List #Big_O_Time_O(n)_Space_O(k) -; #2025_02_03_Time_0_(100.00%)_Space_101.65_(100.00%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_101.65_MB_(100.00%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0001_0100/s0032_longest_valid_parentheses/Solution.rkt b/src/main/racket/g0001_0100/s0032_longest_valid_parentheses/Solution.rkt index 8948187..f5cf886 100644 --- a/src/main/racket/g0001_0100/s0032_longest_valid_parentheses/Solution.rkt +++ b/src/main/racket/g0001_0100/s0032_longest_valid_parentheses/Solution.rkt @@ -1,5 +1,5 @@ ; #Hard #Top_100_Liked_Questions #String #Dynamic_Programming #Stack #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_3_(100.00%)_Space_101.36_(100.00%) +; #2025_02_03_Time_3_ms_(100.00%)_Space_101.36_MB_(100.00%) (define/contract (longest-valid-parentheses s) (-> string? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.rkt b/src/main/racket/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.rkt index 9666729..c7631e6 100644 --- a/src/main/racket/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.rkt +++ b/src/main/racket/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search ; #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_11 #Level_2_Day_8_Binary_Search ; #Udemy_Binary_Search #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) -; #2025_02_03_Time_0_(100.00%)_Space_101.54_(100.00%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_101.54_MB_(100.00%) (define/contract (search nums target [index 0]) (-> (listof exact-integer?) exact-integer? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.rkt b/src/main/racket/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.rkt index 9455575..466a06d 100644 --- a/src/main/racket/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.rkt +++ b/src/main/racket/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search ; #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Top_Interview_150_Binary_Search -; #Big_O_Time_O(log_n)_Space_O(1) #2025_02_03_Time_0_(100.00%)_Space_101.71_(66.67%) +; #Big_O_Time_O(log_n)_Space_O(1) #2025_02_03_Time_0_ms_(100.00%)_Space_101.71_MB_(66.67%) (define (find-bound vec target first-val) (define (ptr-narrow left right) diff --git a/src/main/racket/g0001_0100/s0035_search_insert_position/Solution.rkt b/src/main/racket/g0001_0100/s0035_search_insert_position/Solution.rkt index 6d7aeb5..6fe3fb7 100644 --- a/src/main/racket/g0001_0100/s0035_search_insert_position/Solution.rkt +++ b/src/main/racket/g0001_0100/s0035_search_insert_position/Solution.rkt @@ -1,6 +1,6 @@ ; #Easy #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_I_Day_1_Binary_Search ; #Binary_Search_I_Day_2 #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) -; #2025_02_03_Time_0_(100.00%)_Space_102.38_(_%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_102.38_MB_(_%) (define (search-insert nums target [low 0] [high (sub1 (length nums))]) (if (< high low) diff --git a/src/main/racket/g0001_0100/s0039_combination_sum/Solution.rkt b/src/main/racket/g0001_0100/s0039_combination_sum/Solution.rkt index 64d13b5..60e5f8a 100644 --- a/src/main/racket/g0001_0100/s0039_combination_sum/Solution.rkt +++ b/src/main/racket/g0001_0100/s0039_combination_sum/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking ; #Level_2_Day_20_Brute_Force/Backtracking #Udemy_Backtracking/Recursion ; #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n+2^n) -; #2025_02_03_Time_7_(100.00%)_Space_101.91_(50.00%) +; #2025_02_03_Time_7_ms_(100.00%)_Space_101.91_MB_(50.00%) (define (create-task-rec elems target next-list result) (if (= 0 (length next-list)) result diff --git a/src/main/racket/g0001_0100/s0041_first_missing_positive/Solution.rkt b/src/main/racket/g0001_0100/s0041_first_missing_positive/Solution.rkt index 7745f37..44fbe57 100644 --- a/src/main/racket/g0001_0100/s0041_first_missing_positive/Solution.rkt +++ b/src/main/racket/g0001_0100/s0041_first_missing_positive/Solution.rkt @@ -1,5 +1,5 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays -; #Big_O_Time_O(n)_Space_O(n) #2025_02_03_Time_11_(100.00%)_Space_132.67_(100.00%) +; #Big_O_Time_O(n)_Space_O(n) #2025_02_03_Time_11_ms_(100.00%)_Space_132.67_MB_(100.00%) (define/contract (first-missing-positive nums) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0001_0100/s0042_trapping_rain_water/Solution.rkt b/src/main/racket/g0001_0100/s0042_trapping_rain_water/Solution.rkt index 5f19678..41ee61f 100644 --- a/src/main/racket/g0001_0100/s0042_trapping_rain_water/Solution.rkt +++ b/src/main/racket/g0001_0100/s0042_trapping_rain_water/Solution.rkt @@ -1,7 +1,7 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Two_Pointers ; #Stack #Monotonic_Stack #Dynamic_Programming_I_Day_9 #Udemy_Two_Pointers ; #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_0_(100.00%)_Space_129.13_(100.00%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_129.13_MB_(100.00%) (define (trap height) (define H (list->vector height)) diff --git a/src/main/racket/g0001_0100/s0045_jump_game_ii/Solution.rkt b/src/main/racket/g0001_0100/s0045_jump_game_ii/Solution.rkt index b60650c..c73badf 100644 --- a/src/main/racket/g0001_0100/s0045_jump_game_ii/Solution.rkt +++ b/src/main/racket/g0001_0100/s0045_jump_game_ii/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Greedy ; #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4 ; #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_631_(100.00%)_Space_132.16_(100.00%) +; #2025_02_03_Time_631_ms_(100.00%)_Space_132.16_MB_(100.00%) (define (init-vec len) (let ([prepare-vec (make-vector len 99999)]) diff --git a/src/main/racket/g0001_0100/s0046_permutations/Solution.rkt b/src/main/racket/g0001_0100/s0046_permutations/Solution.rkt index f181c1a..8b3536f 100644 --- a/src/main/racket/g0001_0100/s0046_permutations/Solution.rkt +++ b/src/main/racket/g0001_0100/s0046_permutations/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Backtracking ; #Algorithm_I_Day_11_Recursion_Backtracking #Level_2_Day_20_Brute_Force/Backtracking ; #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(n*n!)_Space_O(n+n!) -; #2025_02_03_Time_0_(100.00%)_Space_101.43_(66.67%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_101.43_MB_(66.67%) (define/contract (permute nums) (-> (listof exact-integer?) (listof (listof exact-integer?))) diff --git a/src/main/racket/g0001_0100/s0049_group_anagrams/Solution.rkt b/src/main/racket/g0001_0100/s0049_group_anagrams/Solution.rkt index 4e2cb55..201ede9 100644 --- a/src/main/racket/g0001_0100/s0049_group_anagrams/Solution.rkt +++ b/src/main/racket/g0001_0100/s0049_group_anagrams/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #String #Hash_Table #Sorting ; #Data_Structure_II_Day_8_String #Programming_Skills_II_Day_11 #Udemy_Strings ; #Top_Interview_150_Hashmap #Big_O_Time_O(n*k_log_k)_Space_O(n) -; #2025_02_03_Time_72_(100.00%)_Space_131.77_(100.00%) +; #2025_02_03_Time_72_ms_(100.00%)_Space_131.77_MB_(100.00%) (define (group-anagrams strs) (group-by (compose1 (curryr sort charlist) strs)) diff --git a/src/main/racket/g0001_0100/s0051_n_queens/Solution.rkt b/src/main/racket/g0001_0100/s0051_n_queens/Solution.rkt index 4702800..c35c6ad 100644 --- a/src/main/racket/g0001_0100/s0051_n_queens/Solution.rkt +++ b/src/main/racket/g0001_0100/s0051_n_queens/Solution.rkt @@ -1,5 +1,5 @@ ; #Hard #Top_100_Liked_Questions #Array #Backtracking #Big_O_Time_O(N!)_Space_O(N) -; #2025_02_03_Time_123_(100.00%)_Space_129.70_(100.00%) +; #2025_02_03_Time_123_ms_(100.00%)_Space_129.70_MB_(100.00%) (define (reverse sequence) (foldr (lambda (x y) (append y (list x))) `() sequence)) diff --git a/src/main/racket/g0001_0100/s0053_maximum_subarray/Solution.rkt b/src/main/racket/g0001_0100/s0053_maximum_subarray/Solution.rkt index 9c4e224..5b3d718 100644 --- a/src/main/racket/g0001_0100/s0053_maximum_subarray/Solution.rkt +++ b/src/main/racket/g0001_0100/s0053_maximum_subarray/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming ; #Divide_and_Conquer #Data_Structure_I_Day_1_Array #Dynamic_Programming_I_Day_5 ; #Udemy_Famous_Algorithm #Top_Interview_150_Kadane's_Algorithm #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_51_(100.00%)_Space_140.95_(100.00%) +; #2025_02_03_Time_51_ms_(100.00%)_Space_140.95_MB_(100.00%) (define/contract (recur nums) (-> (listof exact-integer?) pair?) diff --git a/src/main/racket/g0001_0100/s0055_jump_game/Solution.rkt b/src/main/racket/g0001_0100/s0055_jump_game/Solution.rkt index 78b027f..79155f4 100644 --- a/src/main/racket/g0001_0100/s0055_jump_game/Solution.rkt +++ b/src/main/racket/g0001_0100/s0055_jump_game/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Greedy ; #Algorithm_II_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_4 #Udemy_Arrays ; #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) -; #2025_02_03_Time_0_(100.00%)_Space_132.04_(_%) +; #2025_02_03_Time_0_ms_(100.00%)_Space_132.04_MB_(_%) (define (can-jump L) (let loop ([i 0] [arr L] [best 0] [N (length L)]) diff --git a/src/main/racket/g0001_0100/s0056_merge_intervals/Solution.rkt b/src/main/racket/g0001_0100/s0056_merge_intervals/Solution.rkt index f9c8862..722ed7e 100644 --- a/src/main/racket/g0001_0100/s0056_merge_intervals/Solution.rkt +++ b/src/main/racket/g0001_0100/s0056_merge_intervals/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting ; #Data_Structure_II_Day_2_Array #Level_2_Day_17_Interval #Udemy_2D_Arrays/Matrix ; #Top_Interview_150_Intervals #Big_O_Time_O(n_log_n)_Space_O(n) -; #2025_02_03_Time_474_(100.00%)_Space_131.06_(_%) +; #2025_02_03_Time_474_ms_(100.00%)_Space_131.06_MB_(_%) (define/contract (merge intervals) (-> (listof (listof exact-integer?)) (listof (listof exact-integer?))) diff --git a/src/main/racket/g0001_0100/s0062_unique_paths/Solution.rkt b/src/main/racket/g0001_0100/s0062_unique_paths/Solution.rkt index a3f2f95..c6ce88f 100644 --- a/src/main/racket/g0001_0100/s0062_unique_paths/Solution.rkt +++ b/src/main/racket/g0001_0100/s0062_unique_paths/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math ; #Combinatorics #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_15 ; #Level_1_Day_11_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n) -; #2025_02_03_Time_6_(100.00%)_Space_102.66_(100.00%) +; #2025_02_03_Time_6_ms_(100.00%)_Space_102.66_MB_(100.00%) (define (calc-path! start end direction cache other-p) (begin (if (string=? direction "v") diff --git a/src/main/racket/g0001_0100/s0064_minimum_path_sum/Solution.rkt b/src/main/racket/g0001_0100/s0064_minimum_path_sum/Solution.rkt index fb132e7..044408e 100644 --- a/src/main/racket/g0001_0100/s0064_minimum_path_sum/Solution.rkt +++ b/src/main/racket/g0001_0100/s0064_minimum_path_sum/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix ; #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP -; #Big_O_Time_O(m*n)_Space_O(m*n) #2025_02_04_Time_92_(100.00%)_Space_133.91_(100.00%) +; #Big_O_Time_O(m*n)_Space_O(m*n) #2025_02_04_Time_92_ms_(100.00%)_Space_133.91_MB_(100.00%) ; dynamic programming helper function (define (mpsAux grid curpos dpTable ub) diff --git a/src/main/racket/g0001_0100/s0070_climbing_stairs/Solution.rkt b/src/main/racket/g0001_0100/s0070_climbing_stairs/Solution.rkt index 0765109..fc03de0 100644 --- a/src/main/racket/g0001_0100/s0070_climbing_stairs/Solution.rkt +++ b/src/main/racket/g0001_0100/s0070_climbing_stairs/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math #Memoization ; #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_2 ; #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP -; #Big_O_Time_O(n)_Space_O(n) #2025_02_04_Time_0_(100.00%)_Space_101.51_(100.00%) +; #Big_O_Time_O(n)_Space_O(n) #2025_02_04_Time_0_ms_(100.00%)_Space_101.51_MB_(100.00%) (define (clmHelp n hTable) (cond diff --git a/src/main/racket/g0001_0100/s0072_edit_distance/Solution.rkt b/src/main/racket/g0001_0100/s0072_edit_distance/Solution.rkt index 4954593..e7e9b99 100644 --- a/src/main/racket/g0001_0100/s0072_edit_distance/Solution.rkt +++ b/src/main/racket/g0001_0100/s0072_edit_distance/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #String #Dynamic_Programming ; #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_19 ; #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(n^2)_Space_O(n2) -; #2025_02_04_Time_4_(100.00%)_Space_102.31_(100.00%) +; #2025_02_04_Time_4_ms_(100.00%)_Space_102.31_MB_(100.00%) (define/contract (min-distance word1 word2) (-> string? string? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0074_search_a_2d_matrix/Solution.rkt b/src/main/racket/g0001_0100/s0074_search_a_2d_matrix/Solution.rkt index e9f480e..258534f 100644 --- a/src/main/racket/g0001_0100/s0074_search_a_2d_matrix/Solution.rkt +++ b/src/main/racket/g0001_0100/s0074_search_a_2d_matrix/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Data_Structure_I_Day_5_Array ; #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_8 #Level_2_Day_8_Binary_Search ; #Udemy_2D_Arrays/Matrix #Top_Interview_150_Binary_Search #Big_O_Time_O(endRow+endCol)_Space_O(1) -; #2025_02_04_Time_0_(100.00%)_Space_101.20_(100.00%) +; #2025_02_04_Time_0_ms_(100.00%)_Space_101.20_MB_(100.00%) (define/contract (search-matrix matrix target) (-> (listof (listof exact-integer?)) exact-integer? boolean?) diff --git a/src/main/racket/g0001_0100/s0076_minimum_window_substring/Solution.rkt b/src/main/racket/g0001_0100/s0076_minimum_window_substring/Solution.rkt index 3986d88..94e8dad 100644 --- a/src/main/racket/g0001_0100/s0076_minimum_window_substring/Solution.rkt +++ b/src/main/racket/g0001_0100/s0076_minimum_window_substring/Solution.rkt @@ -1,6 +1,6 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window ; #Level_2_Day_14_Sliding_Window/Two_Pointer #Top_Interview_150_Sliding_Window -; #Big_O_Time_O(s.length())_Space_O(1) #2025_02_04_Time_151_(100.00%)_Space_130.75_(100.00%) +; #Big_O_Time_O(s.length())_Space_O(1) #2025_02_04_Time_151_ms_(100.00%)_Space_130.75_MB_(100.00%) (define (zip lst1 lst2) (map cons lst1 lst2)) diff --git a/src/main/racket/g0001_0100/s0078_subsets/Solution.rkt b/src/main/racket/g0001_0100/s0078_subsets/Solution.rkt index 4b1ae15..d098f92 100644 --- a/src/main/racket/g0001_0100/s0078_subsets/Solution.rkt +++ b/src/main/racket/g0001_0100/s0078_subsets/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation #Backtracking ; #Algorithm_II_Day_9_Recursion_Backtracking #Udemy_Backtracking/Recursion -; #Big_O_Time_O(2^n)_Space_O(n*2^n) #2025_02_04_Time_0_(100.00%)_Space_101.30_(100.00%) +; #Big_O_Time_O(2^n)_Space_O(n*2^n) #2025_02_04_Time_0_ms_(100.00%)_Space_101.30_MB_(100.00%) (define/contract (subset-recur nums ans) (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof (listof exact-integer?))) diff --git a/src/main/racket/g0001_0100/s0079_word_search/Solution.rkt b/src/main/racket/g0001_0100/s0079_word_search/Solution.rkt index a4893de..a97de39 100644 --- a/src/main/racket/g0001_0100/s0079_word_search/Solution.rkt +++ b/src/main/racket/g0001_0100/s0079_word_search/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Backtracking ; #Algorithm_II_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking -; #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2025_02_07_Time_2517_(100.00%)_Space_130.64_(_%) +; #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2025_02_07_Time_2517_ms_(100.00%)_Space_130.64_MB_(_%) (define/contract (exist board word) (-> (listof (listof char?)) string? boolean?) diff --git a/src/main/racket/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rkt b/src/main/racket/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rkt index a52ad1a..f43770d 100644 --- a/src/main/racket/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rkt +++ b/src/main/racket/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rkt @@ -1,6 +1,6 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree ; #Stack #Data_Structure_I_Day_10_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n) -; #2025_02_04_Time_0_(100.00%)_Space_101.40_(100.00%) +; #2025_02_04_Time_0_ms_(100.00%)_Space_101.40_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0001_0100/s0096_unique_binary_search_trees/Solution.rkt b/src/main/racket/g0001_0100/s0096_unique_binary_search_trees/Solution.rkt index 30fb46c..4735d99 100644 --- a/src/main/racket/g0001_0100/s0096_unique_binary_search_trees/Solution.rkt +++ b/src/main/racket/g0001_0100/s0096_unique_binary_search_trees/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Dynamic_Programming #Math #Tree #Binary_Tree #Binary_Search_Tree ; #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1) -; #2025_02_04_Time_0_(100.00%)_Space_101.40_(100.00%) +; #2025_02_04_Time_0_ms_(100.00%)_Space_101.40_MB_(100.00%) (define/contract (num-trees n) (-> exact-integer? exact-integer?) diff --git a/src/main/racket/g0001_0100/s0098_validate_binary_search_tree/Solution.rkt b/src/main/racket/g0001_0100/s0098_validate_binary_search_tree/Solution.rkt index 8d683f6..aeb1651 100644 --- a/src/main/racket/g0001_0100/s0098_validate_binary_search_tree/Solution.rkt +++ b/src/main/racket/g0001_0100/s0098_validate_binary_search_tree/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree ; #Binary_Search_Tree #Data_Structure_I_Day_14_Tree #Level_1_Day_8_Binary_Search_Tree ; #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(N)_Space_O(log(N)) -; #2025_02_04_Time_0_(100.00%)_Space_101.52_(100.00%) +; #2025_02_04_Time_0_ms_(100.00%)_Space_101.52_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0101_symmetric_tree/Solution.rkt b/src/main/racket/g0101_0200/s0101_symmetric_tree/Solution.rkt index 3a196fc..d10fea7 100644 --- a/src/main/racket/g0101_0200/s0101_symmetric_tree/Solution.rkt +++ b/src/main/racket/g0101_0200/s0101_symmetric_tree/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search ; #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree #Level_2_Day_15_Tree ; #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(log(N)) -; #2025_02_05_Time_0_(100.00%)_Space_102.16_(_%) +; #2025_02_05_Time_0_ms_(100.00%)_Space_102.16_MB_(_%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rkt b/src/main/racket/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rkt index 44ec4ce..9b55c7b 100644 --- a/src/main/racket/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rkt +++ b/src/main/racket/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Breadth_First_Search #Tree ; #Binary_Tree #Data_Structure_I_Day_11_Tree #Level_1_Day_6_Tree #Udemy_Tree_Stack_Queue ; #Top_Interview_150_Binary_Tree_BFS #Big_O_Time_O(N)_Space_O(N) -; #2025_02_05_Time_0_(100.00%)_Space_102.22_(40.00%) +; #2025_02_05_Time_0_ms_(100.00%)_Space_102.22_MB_(40.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rkt b/src/main/racket/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rkt index 689dd01..8902a99 100644 --- a/src/main/racket/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rkt +++ b/src/main/racket/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rkt @@ -2,7 +2,7 @@ ; #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree ; #Programming_Skills_I_Day_10_Linked_List_and_Tree #Udemy_Tree_Stack_Queue ; #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(H) -; #2025_02_05_Time_0_(100.00%)_Space_101.36_(100.00%) +; #2025_02_05_Time_0_ms_(100.00%)_Space_101.36_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rkt b/src/main/racket/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rkt index cf842fc..f60089e 100644 --- a/src/main/racket/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rkt +++ b/src/main/racket/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Tree #Binary_Tree ; #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Top_Interview_150_Binary_Tree_General -; #Big_O_Time_O(N)_Space_O(N) #2025_02_05_Time_23_(100.00%)_Space_101.43_(100.00%) +; #Big_O_Time_O(N)_Space_O(N) #2025_02_05_Time_23_ms_(100.00%)_Space_101.43_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rkt b/src/main/racket/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rkt index 8854884..71c7f0e 100644 --- a/src/main/racket/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rkt +++ b/src/main/racket/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List ; #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N) -; #2025_02_07_Time_0_(100.00%)_Space_101.49_(100.00%) +; #2025_02_07_Time_0_ms_(100.00%)_Space_101.49_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.rkt b/src/main/racket/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.rkt index 560cd19..dbf9f19 100644 --- a/src/main/racket/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.rkt +++ b/src/main/racket/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming ; #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays ; #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1) -; #2025_02_05_Time_7_(100.00%)_Space_131.60_(50.00%) +; #2025_02_05_Time_7_ms_(100.00%)_Space_131.60_MB_(50.00%) (define/contract (max-profit prices) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.rkt b/src/main/racket/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.rkt index fd1f126..69d9d51 100644 --- a/src/main/racket/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.rkt +++ b/src/main/racket/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.rkt @@ -1,6 +1,6 @@ ; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search ; #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General -; #Big_O_Time_O(N)_Space_O(N) #2025_02_07_Time_0_(100.00%)_Space_131.06_(100.00%) +; #Big_O_Time_O(N)_Space_O(N) #2025_02_07_Time_0_ms_(100.00%)_Space_131.06_MB_(100.00%) ; Definition for a binary tree node. #| diff --git a/src/main/racket/g0101_0200/s0128_longest_consecutive_sequence/Solution.rkt b/src/main/racket/g0101_0200/s0128_longest_consecutive_sequence/Solution.rkt index b40d2f8..2911b8f 100644 --- a/src/main/racket/g0101_0200/s0128_longest_consecutive_sequence/Solution.rkt +++ b/src/main/racket/g0101_0200/s0128_longest_consecutive_sequence/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find ; #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1) -; #2025_02_05_Time_182_(100.00%)_Space_144.85_(100.00%) +; #2025_02_05_Time_182_ms_(100.00%)_Space_144.85_MB_(100.00%) (define (longest-consecutive nums) (define uniq (list->set nums)) diff --git a/src/main/racket/g0101_0200/s0131_palindrome_partitioning/Solution.rkt b/src/main/racket/g0101_0200/s0131_palindrome_partitioning/Solution.rkt index d626ab5..d80d12f 100644 --- a/src/main/racket/g0101_0200/s0131_palindrome_partitioning/Solution.rkt +++ b/src/main/racket/g0101_0200/s0131_palindrome_partitioning/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming ; #Backtracking #Big_O_Time_O(N*2^N)_Space_O(2^N*N) -; #2025_02_05_Time_43_(100.00%)_Space_142.17_(100.00%) +; #2025_02_05_Time_43_ms_(100.00%)_Space_142.17_MB_(100.00%) (define/contract (partition s) (-> string? (listof (listof string?))) diff --git a/src/main/racket/g0101_0200/s0136_single_number/Solution.rkt b/src/main/racket/g0101_0200/s0136_single_number/Solution.rkt index 6715c35..20389a7 100644 --- a/src/main/racket/g0101_0200/s0136_single_number/Solution.rkt +++ b/src/main/racket/g0101_0200/s0136_single_number/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation ; #Data_Structure_II_Day_1_Array #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers ; #Top_Interview_150_Bit_Manipulation #Big_O_Time_O(N)_Space_O(1) -; #2025_02_07_Time_0_(100.00%)_Space_129.05_(100.00%) +; #2025_02_07_Time_0_ms_(100.00%)_Space_129.05_MB_(100.00%) (define (single-number nums) (apply bitwise-xor nums) diff --git a/src/main/racket/g0101_0200/s0139_word_break/Solution.rkt b/src/main/racket/g0101_0200/s0139_word_break/Solution.rkt index 7bad30c..b836a8b 100644 --- a/src/main/racket/g0101_0200/s0139_word_break/Solution.rkt +++ b/src/main/racket/g0101_0200/s0139_word_break/Solution.rkt @@ -1,7 +1,8 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table ; #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming ; #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP -; #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2025_02_06_Time_4_(100.00%)_Space_102.55_(100.00%) +; #Big_O_Time_O(M+max*N)_Space_O(M+N+max) +; #2025_02_06_Time_4_ms_(100.00%)_Space_102.55_MB_(100.00%) (define/contract (word-break s wordDict) (-> string? (listof string?) boolean?) diff --git a/src/main/racket/g0101_0200/s0146_lru_cache/LRUCache.rkt b/src/main/racket/g0101_0200/s0146_lru_cache/LRUCache.rkt index 2f3922d..c3a2eea 100644 --- a/src/main/racket/g0101_0200/s0146_lru_cache/LRUCache.rkt +++ b/src/main/racket/g0101_0200/s0146_lru_cache/LRUCache.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List ; #Doubly_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List -; #Big_O_Time_O(1)_Space_O(capacity) #2025_02_06_Time_471_(100.00%)_Space_163.64_(100.00%) +; #Big_O_Time_O(1)_Space_O(capacity) #2025_02_06_Time_471_ms_(100.00%)_Space_163.64_MB_(100.00%) (define lru-cache% (class object% diff --git a/src/main/racket/g0101_0200/s0148_sort_list/Solution.rkt b/src/main/racket/g0101_0200/s0148_sort_list/Solution.rkt index 38d1346..60eea0a 100644 --- a/src/main/racket/g0101_0200/s0148_sort_list/Solution.rkt +++ b/src/main/racket/g0101_0200/s0148_sort_list/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List ; #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Top_Interview_150_Divide_and_Conquer -; #Big_O_Time_O(log(N))_Space_O(log(N)) #2025_02_08_Time_31_(100.00%)_Space_132.15_(100.00%) +; #Big_O_Time_O(log(N))_Space_O(log(N)) #2025_02_08_Time_31_ms_(100.00%)_Space_132.15_MB_(100.00%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0101_0200/s0152_maximum_product_subarray/Solution.rkt b/src/main/racket/g0101_0200/s0152_maximum_product_subarray/Solution.rkt index 648f1f4..384d513 100644 --- a/src/main/racket/g0101_0200/s0152_maximum_product_subarray/Solution.rkt +++ b/src/main/racket/g0101_0200/s0152_maximum_product_subarray/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming ; #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming -; #Big_O_Time_O(N)_Space_O(1) #2025_02_08_Time_731_(100.00%)_Space_102.15_(_%) +; #Big_O_Time_O(N)_Space_O(1) #2025_02_08_Time_731_ms_(100.00%)_Space_102.15_MB_(_%) (define/contract (max-product nums) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.rkt b/src/main/racket/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.rkt index 374490d..e68fefa 100644 --- a/src/main/racket/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.rkt +++ b/src/main/racket/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.rkt @@ -1,6 +1,6 @@ ; #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search ; #Binary_Search_I_Day_12 #Udemy_Binary_Search #Top_Interview_150_Binary_Search -; #Big_O_Time_O(log_N)_Space_O(log_N) #2025_02_08_Time_0_(100.00%)_Space_101.65_(100.00%) +; #Big_O_Time_O(log_N)_Space_O(log_N) #2025_02_08_Time_0_ms_(100.00%)_Space_101.65_MB_(100.00%) (define/contract (find-min nums) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0101_0200/s0155_min_stack/MinStack.rkt b/src/main/racket/g0101_0200/s0155_min_stack/MinStack.rkt index 2234776..f655612 100644 --- a/src/main/racket/g0101_0200/s0155_min_stack/MinStack.rkt +++ b/src/main/racket/g0101_0200/s0155_min_stack/MinStack.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design ; #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design ; #Udemy_Design #Top_Interview_150_Stack #Big_O_Time_O(1)_Space_O(N) -; #2025_02_08_Time_32_(100.00%)_Space_130.81_(100.00%) +; #2025_02_08_Time_32_ms_(100.00%)_Space_130.81_MB_(100.00%) (define min-stack% (class object% diff --git a/src/main/racket/g0101_0200/s0169_majority_element/Solution.rkt b/src/main/racket/g0101_0200/s0169_majority_element/Solution.rkt index 0678d42..bfca38a 100644 --- a/src/main/racket/g0101_0200/s0169_majority_element/Solution.rkt +++ b/src/main/racket/g0101_0200/s0169_majority_element/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting #Counting ; #Divide_and_Conquer #Data_Structure_II_Day_1_Array #Udemy_Famous_Algorithm ; #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) -; #2025_02_08_Time_0_(100.00%)_Space_131.10_(80.00%) +; #2025_02_08_Time_0_ms_(100.00%)_Space_131.10_MB_(80.00%) (define/contract (majority-element nums) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0101_0200/s0198_house_robber/Solution.rkt b/src/main/racket/g0101_0200/s0198_house_robber/Solution.rkt index 1c80a3e..c0c7d80 100644 --- a/src/main/racket/g0101_0200/s0198_house_robber/Solution.rkt +++ b/src/main/racket/g0101_0200/s0198_house_robber/Solution.rkt @@ -1,7 +1,7 @@ ; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming ; #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3 ; #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP -; #Big_O_Time_O(n)_Space_O(n) #2025_02_08_Time_0_(100.00%)_Space_101.46_(100.00%) +; #Big_O_Time_O(n)_Space_O(n) #2025_02_08_Time_0_ms_(100.00%)_Space_101.46_MB_(100.00%) (define/contract (rob nums) (-> (listof exact-integer?) exact-integer?) diff --git a/src/main/racket/g0101_0200/s0200_number_of_islands/Solution.rkt b/src/main/racket/g0101_0200/s0200_number_of_islands/Solution.rkt index f29fd7d..fef6e65 100644 --- a/src/main/racket/g0101_0200/s0200_number_of_islands/Solution.rkt +++ b/src/main/racket/g0101_0200/s0200_number_of_islands/Solution.rkt @@ -3,7 +3,7 @@ ; #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search ; #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #Udemy_Graph ; #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N) -; #2025_02_08_Time_349_(100.00%)_Space_134.52_(100.00%) +; #2025_02_08_Time_349_ms_(100.00%)_Space_134.52_MB_(100.00%) (define-syntax vref (syntax-rules () diff --git a/src/main/racket/g0201_0300/s0206_reverse_linked_list/Solution.rkt b/src/main/racket/g0201_0300/s0206_reverse_linked_list/Solution.rkt index d009e31..20547d9 100644 --- a/src/main/racket/g0201_0300/s0206_reverse_linked_list/Solution.rkt +++ b/src/main/racket/g0201_0300/s0206_reverse_linked_list/Solution.rkt @@ -1,7 +1,7 @@ ; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion ; #Data_Structure_I_Day_8_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking ; #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1) -; #2025_02_08_Time_0_(100.00%)_Space_102.22_(100.00%) +; #2025_02_08_Time_0_ms_(100.00%)_Space_102.22_MB_(100.00%) ; Definition for singly-linked list: #| diff --git a/src/main/racket/g0201_0300/s0207_course_schedule/Solution.rkt b/src/main/racket/g0201_0300/s0207_course_schedule/Solution.rkt new file mode 100644 index 0000000..7953d1b --- /dev/null +++ b/src/main/racket/g0201_0300/s0207_course_schedule/Solution.rkt @@ -0,0 +1,23 @@ +; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search +; #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General +; #Big_O_Time_O(N)_Space_O(N) #2025_02_10_Time_4_ms_(100.00%)_Space_101.62_MB_(100.00%) + +(define (can-finish num-courses prereqs) + (let ([adj (make-hash)] + [seen (make-vector num-courses 0)]) + (for ([x prereqs]) + (hash-set! adj (first x) + (cons (second x) (hash-ref adj (first x) '())))) + + (define (dfs node) + (cond ((= 1 (vector-ref seen node)) #f) + ((= 2 (vector-ref seen node)) #t) + (else + (vector-set! seen node 1) + (if (andmap dfs (hash-ref adj node '())) + (begin + (vector-set! seen node 2) + #t) + #f)))) + + (andmap dfs (hash-keys adj)))) diff --git a/src/main/racket/g0201_0300/s0207_course_schedule/readme.md b/src/main/racket/g0201_0300/s0207_course_schedule/readme.md new file mode 100644 index 0000000..fa1d34b --- /dev/null +++ b/src/main/racket/g0201_0300/s0207_course_schedule/readme.md @@ -0,0 +1,33 @@ +207\. Course Schedule + +Medium + +There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where prerequisites[i] = [ai, bi] indicates that you **must** take course bi first if you want to take course ai. + +* For example, the pair `[0, 1]`, indicates that to take course `0` you have to first take course `1`. + +Return `true` if you can finish all courses. Otherwise, return `false`. + +**Example 1:** + +**Input:** numCourses = 2, prerequisites = [[1,0]] + +**Output:** true + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible. + +**Example 2:** + +**Input:** numCourses = 2, prerequisites = [[1,0],[0,1]] + +**Output:** false + +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible. + +**Constraints:** + +* `1 <= numCourses <= 2000` +* `0 <= prerequisites.length <= 5000` +* `prerequisites[i].length == 2` +* 0 <= ai, bi < numCourses +* All the pairs prerequisites[i] are **unique**. diff --git a/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/Trie.rkt b/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/Trie.rkt new file mode 100644 index 0000000..f9b1295 --- /dev/null +++ b/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/Trie.rkt @@ -0,0 +1,56 @@ +; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie +; #Level_2_Day_16_Design #Udemy_Trie_and_Heap #Top_Interview_150_Trie +; #Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) +; #2025_02_10_Time_102_ms_(100.00%)_Space_134.45_MB_(100.00%) + +(define trie% + (class object% + (super-new) + + ;; Define TrieNode struct + (struct trie-node (children is-word?) #:mutable) + + ;; Root node of the Trie + (init-field) + (define root (trie-node (make-hash) #f)) + (define start-with? #f) + + ;; Inserts a word into the trie. + (define/public (insert word) + (define (insert-helper node word idx) + (if (= idx (string-length word)) + (set-trie-node-is-word?! node #t) + (let* ([ch (string-ref word idx)] + [children (trie-node-children node)] + [next-node (hash-ref children ch (lambda () (trie-node (make-hash) #f)))]) + (hash-set! children ch next-node) + (insert-helper next-node word (+ idx 1))))) + (insert-helper root word 0)) + + ;; Searches for a word in the trie. + (define/public (search word) + (define (search-helper node word idx) + (if (= idx (string-length word)) + (begin + (set! start-with? #t) + (trie-node-is-word? node)) + (let* ([ch (string-ref word idx)] + [children (trie-node-children node)] + [next-node (hash-ref children ch #f)]) + (if next-node + (search-helper next-node word (+ idx 1)) + (begin + (set! start-with? #f) + #f))))) + (search-helper root word 0)) + + ;; Checks if any word in the trie starts with the given prefix. + (define/public (starts-with prefix) + (send this search prefix) + start-with?))) + +;; Your trie% object will be instantiated and called as such: +;; (define obj (new trie%)) +;; (send obj insert word) +;; (define param_2 (send obj search word)) +;; (define param_3 (send obj starts-with prefix)) diff --git a/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/readme.md b/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/readme.md new file mode 100644 index 0000000..e9d3909 --- /dev/null +++ b/src/main/racket/g0201_0300/s0208_implement_trie_prefix_tree/readme.md @@ -0,0 +1,40 @@ +208\. Implement Trie (Prefix Tree) + +Medium + +A [**trie**](https://en.wikipedia.org/wiki/Trie) (pronounced as "try") or **prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. + +Implement the Trie class: + +* `Trie()` Initializes the trie object. +* `void insert(String word)` Inserts the string `word` into the trie. +* `boolean search(String word)` Returns `true` if the string `word` is in the trie (i.e., was inserted before), and `false` otherwise. +* `boolean startsWith(String prefix)` Returns `true` if there is a previously inserted string `word` that has the prefix `prefix`, and `false` otherwise. + +**Example 1:** + +**Input** ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] + +**Output:** [null, null, true, false, true, null, true] + +**Explanation:** + +Trie trie = new Trie(); + +trie.insert("apple"); + +trie.search("apple"); // return True + +trie.search("app"); // return False + +trie.startsWith("app"); // return True + +trie.insert("app"); + +trie.search("app"); // return True + +**Constraints:** + +* `1 <= word.length, prefix.length <= 2000` +* `word` and `prefix` consist only of lowercase English letters. +* At most 3 * 104 calls **in total** will be made to `insert`, `search`, and `startsWith`. diff --git a/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.rkt b/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.rkt new file mode 100644 index 0000000..379f45f --- /dev/null +++ b/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.rkt @@ -0,0 +1,10 @@ +; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Heap_Priority_Queue +; #Divide_and_Conquer #Quickselect #Data_Structure_II_Day_20_Heap_Priority_Queue +; #Top_Interview_150_Heap #Big_O_Time_O(n*log(n))_Space_O(log(n)) +; #2025_02_10_Time_79_ms_(100.00%)_Space_135.10_MB_(100.00%) + +(define/contract (find-kth-largest nums k) + (-> (listof exact-integer?) exact-integer? exact-integer?) + (let* ([sorted-nums (sort nums >)] ; Sort in descending order + [index (- k 1)]) ; Convert 1-based to 0-based index + (list-ref sorted-nums index))) ; Return the k-th largest element diff --git a/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md b/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md new file mode 100644 index 0000000..e6b9072 --- /dev/null +++ b/src/main/racket/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md @@ -0,0 +1,26 @@ +215\. Kth Largest Element in an Array + +Medium + +Given an integer array `nums` and an integer `k`, return _the_ kth _largest element in the array_. + +Note that it is the kth largest element in the sorted order, not the kth distinct element. + +You must solve it in `O(n)` time complexity. + +**Example 1:** + +**Input:** nums = [3,2,1,5,6,4], k = 2 + +**Output:** 5 + +**Example 2:** + +**Input:** nums = [3,2,3,1,2,4,5,5,6], k = 4 + +**Output:** 4 + +**Constraints:** + +* 1 <= k <= nums.length <= 105 +* -104 <= nums[i] <= 104 diff --git a/src/main/racket/g0201_0300/s0221_maximal_square/Solution.rkt b/src/main/racket/g0201_0300/s0221_maximal_square/Solution.rkt new file mode 100644 index 0000000..38f1a30 --- /dev/null +++ b/src/main/racket/g0201_0300/s0221_maximal_square/Solution.rkt @@ -0,0 +1,24 @@ +; #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_16 +; #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(m*n)_Space_O(m*n) +; #2025_02_10_Time_426_ms_(100.00%)_Space_130.80_MB_(100.00%) + +(define/contract (maximal-square matrix) + (-> (listof (listof char?)) exact-integer?) + (let* ([m (length matrix)] + [n (if (zero? m) 0 (length (first matrix)))] + [dp (make-hash)] ; Hash table to simulate a 2D array + [max-size 0]) + + (define (get-dp i j) + (hash-ref dp (cons i j) 0)) ; Default to 0 if not found + + ;; Iterate over the matrix + (for ([i (in-range m)]) + (for ([j (in-range n)]) + (when (char=? (list-ref (list-ref matrix i) j) #\1) + (let* ([min-neighbor (min (get-dp i j) (get-dp (+ i 1) j) (get-dp i (+ j 1)))] + [size (+ 1 min-neighbor)]) + (hash-set! dp (cons (+ i 1) (+ j 1)) size) + (set! max-size (max max-size size)))))) + + (* max-size max-size))) ; Return area of the largest square diff --git a/src/main/racket/g0201_0300/s0221_maximal_square/readme.md b/src/main/racket/g0201_0300/s0221_maximal_square/readme.md new file mode 100644 index 0000000..7a2658a --- /dev/null +++ b/src/main/racket/g0201_0300/s0221_maximal_square/readme.md @@ -0,0 +1,34 @@ +221\. Maximal Square + +Medium + +Given an `m x n` binary `matrix` filled with `0`'s and `1`'s, _find the largest square containing only_ `1`'s _and return its area_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max1grid.jpg) + +**Input:** matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] + +**Output:** 4 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/26/max2grid.jpg) + +**Input:** matrix = [["0","1"],["1","0"]] + +**Output:** 1 + +**Example 3:** + +**Input:** matrix = [["0"]] + +**Output:** 0 + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 300` +* `matrix[i][j]` is `'0'` or `'1'`. diff --git a/src/main/racket/g0201_0300/s0226_invert_binary_tree/Solution.rkt b/src/main/racket/g0201_0300/s0226_invert_binary_tree/Solution.rkt new file mode 100644 index 0000000..b857322 --- /dev/null +++ b/src/main/racket/g0201_0300/s0226_invert_binary_tree/Solution.rkt @@ -0,0 +1,28 @@ +; #Easy #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree +; #Data_Structure_I_Day_12_Tree #Level_2_Day_6_Tree #Udemy_Tree_Stack_Queue +; #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n) +; #2025_02_10_Time_0_ms_(100.00%)_Space_102.41_MB_(0.00%) + +; Definition for a binary tree node. +#| +; val : integer? +; left : (or/c tree-node? #f) +; right : (or/c tree-node? #f) +(struct tree-node + (val left right) #:mutable #:transparent) + +; Helper function to create a tree node. +|# +(define (make-tree-node val [left #f] [right #f]) + (tree-node val left right)) + +; Function to invert a binary tree. +(define/contract (invert-tree root) + (-> (or/c tree-node? #f) (or/c tree-node? #f)) + (cond + [(not root) #f] ; Base case: empty tree. + [else + (make-tree-node + (tree-node-val root) + (invert-tree (tree-node-right root)) + (invert-tree (tree-node-left root)))])) diff --git a/src/main/racket/g0201_0300/s0226_invert_binary_tree/readme.md b/src/main/racket/g0201_0300/s0226_invert_binary_tree/readme.md new file mode 100644 index 0000000..40ccaaa --- /dev/null +++ b/src/main/racket/g0201_0300/s0226_invert_binary_tree/readme.md @@ -0,0 +1,32 @@ +226\. Invert Binary Tree + +Easy + +Given the `root` of a binary tree, invert the tree, and return _its root_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg) + +**Input:** root = [4,2,7,1,3,6,9] + +**Output:** [4,7,2,9,6,3,1] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/14/invert2-tree.jpg) + +**Input:** root = [2,1,3] + +**Output:** [2,3,1] + +**Example 3:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 100]`. +* `-100 <= Node.val <= 100` diff --git a/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.rkt b/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.rkt new file mode 100644 index 0000000..fce038b --- /dev/null +++ b/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.rkt @@ -0,0 +1,30 @@ +; #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree +; #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree +; #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(n)_Space_O(n) +; #2025_02_10_Time_27_ms_(100.00%)_Space_130.16_MB_(100.00%) + +; Definition for a binary tree node. +#| + +; val : integer? +; left : (or/c tree-node? #f) +; right : (or/c tree-node? #f) +(struct tree-node + (val left right) #:mutable #:transparent) + +; constructor +(define (make-tree-node [val 0]) + (tree-node val #f #f)) + +|# + +(define (inorder-traversal tree) + (if (not tree) + '() + (append (inorder-traversal (tree-node-left tree)) + (list (tree-node-val tree)) + (inorder-traversal (tree-node-right tree))))) + +(define (kth-smallest root k) + (let ([inorder (inorder-traversal root)]) + (list-ref inorder (sub1 k)))) diff --git a/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/readme.md b/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/readme.md new file mode 100644 index 0000000..21be903 --- /dev/null +++ b/src/main/racket/g0201_0300/s0230_kth_smallest_element_in_a_bst/readme.md @@ -0,0 +1,29 @@ +230\. Kth Smallest Element in a BST + +Medium + +Given the `root` of a binary search tree, and an integer `k`, return _the_ kth _smallest value (**1-indexed**) of all the values of the nodes in the tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/28/kthtree1.jpg) + +**Input:** root = [3,1,4,null,2], k = 1 + +**Output:** 1 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/28/kthtree2.jpg) + +**Input:** root = [5,3,6,2,4,null,null,1], k = 3 + +**Output:** 3 + +**Constraints:** + +* The number of nodes in the tree is `n`. +* 1 <= k <= n <= 104 +* 0 <= Node.val <= 104 + +**Follow up:** If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize? diff --git a/src/main/racket/g0201_0300/s0234_palindrome_linked_list/Solution.rkt b/src/main/racket/g0201_0300/s0234_palindrome_linked_list/Solution.rkt new file mode 100644 index 0000000..5b24ace --- /dev/null +++ b/src/main/racket/g0201_0300/s0234_palindrome_linked_list/Solution.rkt @@ -0,0 +1,28 @@ +; #Easy #Top_100_Liked_Questions #Two_Pointers #Stack #Linked_List #Recursion +; #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1) +; #2025_02_10_Time_69_ms_(100.00%)_Space_130.91_MB_(100.00%) + +; Definition for singly-linked list: +#| + +; val : integer? +; next : (or/c list-node? #f) +(struct list-node + (val next) #:mutable #:transparent) + +; constructor +(define (make-list-node [val 0]) + (list-node val #f)) + +|# + +(define (linked-list->numbers ll) + (if (not (list-node? ll)) + '() + (append (list (list-node-val ll)) + (linked-list->numbers (list-node-next ll))))) + + +(define (is-palindrome head) + (let ([numls (linked-list->numbers head)]) + (equal? numls (reverse numls)))) diff --git a/src/main/racket/g0201_0300/s0234_palindrome_linked_list/readme.md b/src/main/racket/g0201_0300/s0234_palindrome_linked_list/readme.md new file mode 100644 index 0000000..9ee1dce --- /dev/null +++ b/src/main/racket/g0201_0300/s0234_palindrome_linked_list/readme.md @@ -0,0 +1,28 @@ +234\. Palindrome Linked List + +Easy + +Given the `head` of a singly linked list, return `true` _if it is a palindrome or_ `false` _otherwise_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg) + +**Input:** head = [1,2,2,1] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg) + +**Input:** head = [1,2] + +**Output:** false + +**Constraints:** + +* The number of nodes in the list is in the range [1, 105]. +* `0 <= Node.val <= 9` + +**Follow up:** Could you do it in `O(n)` time and `O(1)` space? diff --git a/src/main/racket/g0201_0300/s0238_product_of_array_except_self/Solution.rkt b/src/main/racket/g0201_0300/s0238_product_of_array_except_self/Solution.rkt new file mode 100644 index 0000000..2affae3 --- /dev/null +++ b/src/main/racket/g0201_0300/s0238_product_of_array_except_self/Solution.rkt @@ -0,0 +1,23 @@ +; #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #Data_Structure_II_Day_5_Array #Udemy_Arrays +; #Top_Interview_150_Array/String #Big_O_Time_O(n^2)_Space_O(n) +; #2025_02_10_Time_10_ms_(100.00%)_Space_132.25_MB_(100.00%) + +(define/contract (product-except-self nums) + (-> (listof exact-integer?) (listof exact-integer?)) + (let* ((first-pass (foldl mult-w-track-zero '(1 0) nums)) + (prod (car first-pass)) + (zero-count (second first-pass))) + (map (lambda (x) + (cond + [(zero? zero-count) + (/ prod x)] + [(= 1 zero-count) + (if (zero? x) prod 0)] + [else 0])) nums))) + +(define (mult-w-track-zero x acc) + (let* ((prod (car acc)) + (zero-count (second acc)) + (new-count (if (zero? x) (add1 zero-count) zero-count))) + (list (if (= 0 x) prod (* prod x)) + new-count))) diff --git a/src/main/racket/g0201_0300/s0238_product_of_array_except_self/readme.md b/src/main/racket/g0201_0300/s0238_product_of_array_except_self/readme.md new file mode 100644 index 0000000..48289c8 --- /dev/null +++ b/src/main/racket/g0201_0300/s0238_product_of_array_except_self/readme.md @@ -0,0 +1,29 @@ +238\. Product of Array Except Self + +Medium + +Given an integer array `nums`, return _an array_ `answer` _such that_ `answer[i]` _is equal to the product of all the elements of_ `nums` _except_ `nums[i]`. + +The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. + +You must write an algorithm that runs in `O(n)` time and without using the division operation. + +**Example 1:** + +**Input:** nums = [1,2,3,4] + +**Output:** [24,12,8,6] + +**Example 2:** + +**Input:** nums = [-1,1,0,-3,3] + +**Output:** [0,0,9,0,0] + +**Constraints:** + +* 2 <= nums.length <= 105 +* `-30 <= nums[i] <= 30` +* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. + +**Follow up:** Can you solve the problem in `O(1) `extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) diff --git a/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/Solution.rkt b/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/Solution.rkt new file mode 100644 index 0000000..9f4189d --- /dev/null +++ b/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/Solution.rkt @@ -0,0 +1,19 @@ +; #Medium #Top_100_Liked_Questions #Array #Binary_Search #Two_Pointers #Bit_Manipulation +; #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n) +; #2025_02_10_Time_327_ms_(100.00%)_Space_132.76_MB_(100.00%) + +(require racket/hash) + +(define/contract (find-duplicate nums) + (-> (listof exact-integer?) exact-integer?) + (letrec + ([find-recurse + (lambda (ns seen) + (cond [(null? ns) -1] + [(hash-has-key? seen (car ns)) (car ns)] + [else (find-recurse + (cdr ns) + (hash-union + seen + (make-immutable-hash (list (cons (car ns) #t)))))]))]) + (find-recurse nums (make-immutable-hash)))) diff --git a/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/readme.md b/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/readme.md new file mode 100644 index 0000000..b2a7021 --- /dev/null +++ b/src/main/racket/g0201_0300/s0287_find_the_duplicate_number/readme.md @@ -0,0 +1,33 @@ +287\. Find the Duplicate Number + +Medium + +Given an array of integers `nums` containing `n + 1` integers where each integer is in the range `[1, n]` inclusive. + +There is only **one repeated number** in `nums`, return _this repeated number_. + +You must solve the problem **without** modifying the array `nums` and uses only constant extra space. + +**Example 1:** + +**Input:** nums = [1,3,4,2,2] + +**Output:** 2 + +**Example 2:** + +**Input:** nums = [3,1,3,4,2] + +**Output:** 3 + +**Constraints:** + +* 1 <= n <= 105 +* `nums.length == n + 1` +* `1 <= nums[i] <= n` +* All the integers in `nums` appear only **once** except for **precisely one integer** which appears **two or more** times. + +**Follow up:** + +* How can we prove that at least one duplicate number must exist in `nums`? +* Can you solve the problem in linear runtime complexity? diff --git a/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/Solution.rkt b/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/Solution.rkt new file mode 100644 index 0000000..384e67d --- /dev/null +++ b/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/Solution.rkt @@ -0,0 +1,39 @@ +; #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Binary_Search +; #Algorithm_II_Day_16_Dynamic_Programming #Binary_Search_II_Day_3 #Dynamic_Programming_I_Day_18 +; #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(n*log_n)_Space_O(n) +; #2025_02_10_Time_3_ms_(100.00%)_Space_101.78_MB_(100.00%) + +(require racket/list) + +(define/contract (length-of-lis nums) + (-> (listof exact-integer?) exact-integer?) + (if (null? nums) + 0 + (let* ([dp (make-vector (+ (length nums) 1) +inf.0)] + [left 1] + [right 1]) + + (for ([curr nums]) + (let ([start left] + [end right]) + ;; Binary search for position in dp array + (let loop () + (when (< (+ start 1) end) + (let ([mid (quotient (+ start end) 2)]) + (if (< curr (vector-ref dp mid)) + (set! end mid) + (set! start mid))) + (loop))) + + ;; Update dp array + (cond + [(< curr (vector-ref dp start)) + (vector-set! dp start curr)] + [(and (> curr (vector-ref dp start)) + (< curr (vector-ref dp end))) + (vector-set! dp end curr)] + [(> curr (vector-ref dp end)) + (vector-set! dp (add1 end) curr) + (set! right (add1 right))]))) + + right))) diff --git a/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/readme.md b/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/readme.md new file mode 100644 index 0000000..e37cf43 --- /dev/null +++ b/src/main/racket/g0201_0300/s0300_longest_increasing_subsequence/readme.md @@ -0,0 +1,34 @@ +300\. Longest Increasing Subsequence + +Medium + +Given an integer array `nums`, return the length of the longest strictly increasing subsequence. + +A **subsequence** is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, `[3,6,2,7]` is a subsequence of the array `[0,3,1,6,2,2,7]`. + +**Example 1:** + +**Input:** nums = [10,9,2,5,3,7,101,18] + +**Output:** 4 + +**Explanation:** The longest increasing subsequence is [2,3,7,101], therefore the length is 4. + +**Example 2:** + +**Input:** nums = [0,1,0,3,2,3] + +**Output:** 4 + +**Example 3:** + +**Input:** nums = [7,7,7,7,7,7,7] + +**Output:** 1 + +**Constraints:** + +* `1 <= nums.length <= 2500` +* -104 <= nums[i] <= 104 + +**Follow up:** Can you come up with an algorithm that runs in `O(n log(n))` time complexity?