diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 4267b85..ff1bfe1 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -10,17 +10,17 @@ jobs: unitTest: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: '16.x' + node-version: '20.x' - name: Setup pnpm - uses: pnpm/action-setup@v2.4.0 + uses: pnpm/action-setup@v4.0.0 with: version: 8.8.0 @@ -34,7 +34,7 @@ jobs: ls -al coverage - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: sonarsource/sonarqube-scan-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: 1ebdc4b127391a8acbc3420eb585961e4e0846de diff --git a/LICENSE b/LICENSE index 04ac570..bcf7a79 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Valentyn Kolesnikov +Copyright (c) 2023-2025 Valentyn Kolesnikov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 097fc5c..9d47fa4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. > ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) ## -* [Algorithm II](#algorithm-ii) * [Binary Search I](#binary-search-i) * [Binary Search II](#binary-search-ii) * [Dynamic Programming I](#dynamic-programming-i) @@ -23,138 +22,11 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. * [Level 1](#level-1) * [Level 2](#level-2) * [Udemy](#udemy) +* [Top Interview 150](#top-interview-150) * [Data Structure I](#data-structure-i) * [Data Structure II](#data-structure-ii) * [Algorithm I](#algorithm-i) - -### Algorithm II - -#### Day 1 Binary Search - -| | | | | | -|-|-|-|-|-|- -| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 45 | 98.05 -| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54 -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 - -#### Day 2 Binary Search - -| | | | | | -|-|-|-|-|-|- -| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 42 | 98.87 - -#### Day 3 Two Pointers - -| | | | | | -|-|-|-|-|-|- -| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 148 | 92.62 - -#### Day 4 Two Pointers - -| | | | | | -|-|-|-|-|-|- -| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 57 | 98.23 - -#### Day 5 Sliding Window - -| | | | | | -|-|-|-|-|-|- -| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 69 | 96.69 - -#### Day 6 Breadth First Search Depth First Search - -| | | | | | -|-|-|-|-|-|- -| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 61 | 96.71 - -#### Day 7 Breadth First Search Depth First Search - -| | | | | | -|-|-|-|-|-|- - -#### Day 8 Breadth First Search Depth First Search - -| | | | | | -|-|-|-|-|-|- - -#### Day 9 Recursion Backtracking - -| | | | | | -|-|-|-|-|-|- -| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 50 | 94.61 - -#### Day 10 Recursion Backtracking - -| | | | | | -|-|-|-|-|-|- -| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 65 | 86.86 - -#### Day 11 Recursion Backtracking - -| | | | | | -|-|-|-|-|-|- -| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 52 | 79.11 -| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 60 | 62.03 -| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 327 | 95.78 - -#### Day 12 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 58 | 91.95 - -#### Day 13 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 50 | 95.93 -| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 40 | 98.97 - -#### Day 14 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 68 | 95.34 - -#### Day 15 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 56 | 88.44 - -#### Day 16 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 57 | 93.75 - -#### Day 17 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 94 | 80.56 - -#### Day 18 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 68 | 95.20 -| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 85 | 86.14 - -#### Day 19 Bit Manipulation - -| | | | | | -|-|-|-|-|-|- - -#### Day 20 Others - -| | | | | | -|-|-|-|-|-|- - -#### Day 21 Others - -| | | | | | -|-|-|-|-|-|- +* [Algorithm II](#algorithm-ii) ### Binary Search I @@ -167,7 +39,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 51 | 80.95 +| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 3 @@ -178,12 +50,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Easy | Top_Interview_Questions, Math, Binary_Search | 1 | 74.84 #### Day 5 | | | | | | |-|-|-|-|-|- -| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 45 | 98.05 +| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 6 @@ -194,12 +67,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0167 |[Two Sum II - Input Array Is Sorted](src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts)| Medium | Array, Binary_Search, Two_Pointers | 0 | 100.00 #### Day 8 | | | | | | |-|-|-|-|-|- -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 #### Day 9 @@ -215,13 +89,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 12 | | | | | | |-|-|-|-|-|- -| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 42 | 98.87 +| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00 ### Binary Search II @@ -229,6 +103,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11 #### Day 2 @@ -239,7 +114,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 57 | 93.75 +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68 #### Day 4 @@ -250,7 +125,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0287 |[Find the Duplicate Number](src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 60 | 98.11 +| 0287 |[Find the Duplicate Number](src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 5 | 88.65 #### Day 6 @@ -266,7 +141,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 58 | 64.44 +| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 42 | 94.61 #### Day 9 @@ -277,6 +152,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0222 |[Count Complete Tree Nodes](src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree | 0 | 100.00 #### Day 11 @@ -287,6 +163,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0162 |[Find Peak Element](src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00 #### Day 13 @@ -339,38 +216,40 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58 +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 3 | | | | | | |-|-|-|-|-|- -| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 51 | 77.29 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 4 | | | | | | |-|-|-|-|-|- -| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 58 | 91.95 -| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 50 | 95.93 +| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 84.27 #### Day 5 | | | | | | |-|-|-|-|-|- -| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 66 | 90.36 +| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0918 |[Maximum Sum Circular Subarray](src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 91.04 #### Day 6 | | | | | | |-|-|-|-|-|- -| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 53 | 87.50 +| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 7 | | | | | | |-|-|-|-|-|- -| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 56 | 99.56 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44 +| 0122 |[Best Time to Buy and Sell Stock II](src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 0 | 100.00 #### Day 8 @@ -381,8 +260,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 56 | 88.44 -| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 46 | 99.52 +| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 4 | 76.41 +| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 10 @@ -393,7 +272,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 45 | 96.00 +| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 12 @@ -404,6 +283,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0120 |[Triangle](src/main/ts/g0101_0200/s0120_triangle/solution.ts)| Medium | Array, Dynamic_Programming | 0 | 100.00 #### Day 14 @@ -414,39 +294,41 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 40 | 98.97 +| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00 +| 0063 |[Unique Paths II](src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts)| Medium | Array, Dynamic_Programming, Matrix | 0 | 100.00 #### Day 16 | | | | | | |-|-|-|-|-|- -| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 48 | 99.67 -| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 83 | 79.70 +| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 4 | 70.73 +| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 18 | 59.02 #### Day 17 | | | | | | |-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 68 | 95.34 +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14 #### Day 18 | | | | | | |-|-|-|-|-|- -| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 57 | 93.75 +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68 #### Day 19 | | | | | | |-|-|-|-|-|- -| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 94 | 80.56 -| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 68 | 95.20 +| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 +| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 50 | 69.40 +| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 6 | 93.83 #### Day 20 | | | | | | |-|-|-|-|-|- -| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 85 | 86.14 +| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42 #### Day 21 @@ -464,6 +346,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00 #### Day 3 Conditional Statements @@ -474,6 +357,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00 #### Day 5 Function @@ -484,7 +368,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 71 | 91.63 +| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86 #### Day 7 Array @@ -505,12 +389,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 51 | 97.14 +| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00 #### Day 11 Containers and Libraries | | | | | | |-|-|-|-|-|- +| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99 #### Day 12 Class and Object @@ -523,6 +408,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 #### Day 2 @@ -533,6 +419,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0150 |[Evaluate Reverse Polish Notation](src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts)| Medium | Top_Interview_Questions, Array, Math, Stack | 1 | 97.48 +| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00 #### Day 4 @@ -543,23 +431,26 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation | 0 | 100.00 #### Day 6 | | | | | | |-|-|-|-|-|- -| 0739 |[Daily Temperatures](src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 194 | 97.36 +| 0739 |[Daily Temperatures](src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 18 | 80.57 +| 0058 |[Length of Last Word](src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts)| Easy | String | 0 | 100.00 #### Day 7 | | | | | | |-|-|-|-|-|- -| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 45 | 95.31 +| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00 #### Day 8 | | | | | | |-|-|-|-|-|- +| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00 #### Day 9 @@ -575,13 +466,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 93 | 97.29 +| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 78.99 #### Day 12 | | | | | | |-|-|-|-|-|- -| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 69 | 96.69 +| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80 #### Day 13 @@ -592,18 +483,20 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 52 | 88.27 +| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 49 | 72.42 #### Day 15 | | | | | | |-|-|-|-|-|- -| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 92 | 77.86 +| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 95.82 #### Day 16 | | | | | | |-|-|-|-|-|- +| 0061 |[Rotate List](src/main/ts/g0001_0100/s0061_rotate_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0173 |[Binary Search Tree Iterator](src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 6 | 98.16 #### Day 17 @@ -614,7 +507,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 84 | 92.72 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10 #### Day 19 @@ -625,6 +518,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized | 73 | 82.52 ### Graph Theory I @@ -632,7 +526,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 61 | 96.71 +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94 #### Day 2 Matrix Related Problems @@ -688,6 +582,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0433 |[Minimum Genetic Mutation](src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts)| Medium | String, Hash_Table, Breadth_First_Search | 0 | 100.00 +| 0127 |[Word Ladder](src/main/ts/g0101_0200/s0127_word_ladder/solution.ts)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 41 | 95.63 #### Day 13 Graph Theory @@ -762,31 +658,33 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table | 3 | 96.02 +| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 #### Day 3 Linked List | | | | | | |-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 59 | 86.77 -| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 51 | 92.87 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21 +| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 4 Linked List | | | | | | |-|-|-|-|-|- -| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 94.39 +| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 51 | 76.99 #### Day 5 Greedy | | | | | | |-|-|-|-|-|- -| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 56 | 99.56 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44 #### Day 6 Tree | | | | | | |-|-|-|-|-|- -| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 60 | 97.47 +| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 #### Day 7 Binary Search @@ -797,43 +695,43 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 51 | 98.35 +| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 #### Day 9 Graph/BFS/DFS | | | | | | |-|-|-|-|-|- -| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 61 | 96.71 +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94 #### Day 10 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58 +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 11 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 40 | 98.97 +| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00 #### Day 12 Sliding Window/Two Pointer | | | | | | |-|-|-|-|-|- -| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 69 | 96.69 +| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80 #### Day 13 Hashmap | | | | | | |-|-|-|-|-|- -| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 54 | 91.72 +| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70 #### Day 14 Stack | | | | | | |-|-|-|-|-|- -| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 51 | 81.02 +| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 15 Heap @@ -846,24 +744,27 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00 +| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00 #### Day 2 String | | | | | | |-|-|-|-|-|- +| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00 #### Day 3 Linked List | | | | | | |-|-|-|-|-|- -| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 54 | 87.87 -| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 96 | 95.67 +| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 +| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 3 | 92.85 #### Day 4 Linked List | | | | | | |-|-|-|-|-|- -| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 141 | 97.14 +| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 36 | 44.94 #### Day 5 Greedy @@ -874,27 +775,29 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 52 | 81.65 +| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 7 Tree | | | | | | |-|-|-|-|-|- -| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 61 | 80.89 -| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 68 | 86.71 +| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 87.16 +| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts)| Medium | Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 3 | 86.41 #### Day 8 Binary Search | | | | | | |-|-|-|-|-|- -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 -| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 9 Binary Search Tree | | | | | | |-|-|-|-|-|- -| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 54 | 97.22 +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00 +| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0173 |[Binary Search Tree Iterator](src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 6 | 98.16 #### Day 10 Graph/BFS/DFS @@ -905,46 +808,50 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- +| 0210 |[Course Schedule II](src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 2 | 99.76 #### Day 12 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 51 | 77.29 -| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 85 | 86.14 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42 #### Day 13 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 91 | 74.38 -| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 53 | 87.50 +| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 33 | 93.24 +| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 14 Sliding Window/Two Pointer | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 65 | 90.77 -| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 82 | 82.17 +| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.91 +| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 20 | 90.35 #### Day 15 Tree | | | | | | |-|-|-|-|-|- -| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 49 | 98.54 +| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 +| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00 #### Day 16 Design | | | | | | |-|-|-|-|-|- -| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 84 | 92.72 -| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 168 | 80.99 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10 +| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 48 | 63.95 #### Day 17 Interval | | | | | | |-|-|-|-|-|- -| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06 +| 0057 |[Insert Interval](src/main/ts/g0001_0100/s0057_insert_interval/solution.ts)| Medium | Array | 0 | 100.00 +| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 87.99 #### Day 18 Stack @@ -960,8 +867,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 65 | 86.86 -| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 56 | 96.26 +| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.17 +| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44 ### Udemy @@ -969,54 +876,66 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 56 | 85.48 -| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts)| Medium | Top_Interview_Questions, Math | 56 | 95.68 -| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math | 137 | 88.64 +| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27 +| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts)| Medium | Top_Interview_Questions, Math | 53 | 83.14 +| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math | 3 | 99.14 +| 0172 |[Factorial Trailing Zeroes](src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts)| Medium | Top_Interview_Questions, Math | 0 | 100.00 +| 0050 |[Pow(x, n)](src/main/ts/g0001_0100/s0050_powx_n/solution.ts)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00 #### Udemy Strings | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 65 | 90.77 -| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 50 | 95.90 -| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 68 | 95.34 -| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 51 | 81.02 -| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 93 | 97.29 +| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00 +| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.91 +| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 1 | 86.85 +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14 +| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99 +| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 78.99 +| 0151 |[Reverse Words in a String](src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts)| Medium | String, Two_Pointers, LeetCode_75_Array/String | 0 | 100.00 #### Udemy Binary Search | | | | | | |-|-|-|-|-|- -| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54 -| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 42 | 98.87 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00 #### Udemy Arrays | | | | | | |-|-|-|-|-|- -| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 56 | 99.56 -| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 71 | 91.63 -| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 54 | 91.72 -| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 75 | 97.25 -| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 58 | 91.95 -| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41 -| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 89 | 64.48 -| 0041 |[First Missing Positive](src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 55 | 98.51 -| 0239 |[Sliding Window Maximum](src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Big_O_Time_O(n\*k)_Space_O(n+k) | 216 | 99.50 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44 +| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86 +| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70 +| 0058 |[Length of Last Word](src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts)| Easy | String | 0 | 100.00 +| 0122 |[Best Time to Buy and Sell Stock II](src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 0 | 100.00 +| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers | 40 | 99.63 +| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17 +| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00 +| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81 +| 0041 |[First Missing Positive](src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 99.11 +| 0239 |[Sliding Window Maximum](src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts)| Hard | Top_100_Liked_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Big_O_Time_O(n\*k)_Space_O(n+k) | 26 | 99.07 #### Udemy Two Pointers | | | | | | |-|-|-|-|-|- -| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 46 | 99.52 -| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 148 | 92.62 +| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 +| 0125 |[Valid Palindrome](src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers | 0 | 100.00 +| 0026 |[Remove Duplicates from Sorted Array](src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00 +| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56 #### Udemy Famous Algorithm | | | | | | |-|-|-|-|-|- -| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 66 | 90.36 -| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 50 | 96.16 +| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Udemy Sorting Algorithms @@ -1027,87 +946,363 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 -| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 45 | 95.31 -| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 61 | 97.66 -| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 +| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00 +| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00 +| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 4 | 50.63 +| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 87.99 #### Udemy Linked List | | | | | | |-|-|-|-|-|- -| 0114 |[Flatten Binary Tree to Linked List](src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 55 | 90.66 -| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 62.67 -| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 94.39 -| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 93.37 -| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 51 | 92.87 -| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 59 | 86.77 -| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 67 | 93.58 -| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 96 | 95.67 -| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 52 | 88.27 -| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 74 | 66.83 -| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 473 | 94.72 +| 0114 |[Flatten Binary Tree to Linked List](src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 +| 0061 |[Rotate List](src/main/ts/g0001_0100/s0061_rotate_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 51 | 76.99 +| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 47 | 89.37 +| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21 +| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 65 | 72.36 +| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 3 | 92.85 +| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 49 | 72.42 +| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 +| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 97 | 81.52 #### Udemy Tree Stack Queue | | | | | | |-|-|-|-|-|- -| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 45 | 97.30 -| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 60 | 97.47 -| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 61 | 80.89 -| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 52 | 81.65 -| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 51 | 97.14 -| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 61 | 96.73 -| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 51 | 98.35 -| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 59 | 96.11 +| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 +| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00 +| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 87.16 +| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00 +| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 2 | 71.11 +| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 +| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 61 | 75.97 #### Udemy Trie and Heap | | | | | | |-|-|-|-|-|- -| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 168 | 80.99 +| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 48 | 63.95 #### Udemy Graph | | | | | | |-|-|-|-|-|- -| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 61 | 96.71 +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94 +| 0133 |[Clone Graph](src/main/ts/g0101_0200/s0133_clone_graph/solution.ts)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 48 | 82.94 #### Udemy Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 56 | 88.44 -| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 53 | 87.50 -| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 51 | 77.29 -| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58 -| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 48 | 99.67 -| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 57 | 93.75 -| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 94 | 80.56 -| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 68 | 95.20 -| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 69 | 92.65 +| 0120 |[Triangle](src/main/ts/g0101_0200/s0120_triangle/solution.ts)| Medium | Array, Dynamic_Programming | 0 | 100.00 +| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 4 | 76.41 +| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 4 | 70.73 +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68 +| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 50 | 69.40 +| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 6 | 93.83 +| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 5 | 90.44 #### Udemy Backtracking/Recursion | | | | | | |-|-|-|-|-|- -| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 60 | 62.03 -| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 65 | 86.86 -| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 50 | 94.61 -| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 52 | 79.11 -| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 56 | 96.26 +| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 1 | 72.82 +| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.17 +| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00 +| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44 #### Udemy Bit Manipulation | | | | | | |-|-|-|-|-|- -| 0338 |[Counting Bits](src/main/ts/g0301_0400/s0338_counting_bits/solution.ts)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 69 | 86.81 +| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00 +| 0190 |[Reverse Bits](src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 34 | 99.74 +| 0338 |[Counting Bits](src/main/ts/g0301_0400/s0338_counting_bits/solution.ts)| Easy | Dynamic_Programming, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 1 | 89.22 #### Udemy Design | | | | | | |-|-|-|-|-|- -| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 84 | 92.72 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10 + +### Top Interview 150 + +#### Top Interview 150 Array/String + +| | | | | | +|-|-|-|-|-|- +| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00 +| 0027 |[Remove Element](src/main/ts/g0001_0100/s0027_remove_element/solution.ts)| Easy | Array, Two_Pointers | 0 | 100.00 +| 0026 |[Remove Duplicates from Sorted Array](src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00 +| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers | 40 | 99.63 +| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44 +| 0122 |[Best Time to Buy and Sell Stock II](src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 0 | 100.00 +| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 84.27 +| 0274 |[H-Index](src/main/ts/g0201_0300/s0274_h_index/solution.ts)| Medium | Array, Sorting, Counting_Sort | 0 | 100.00 +| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized | 73 | 82.52 +| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81 +| 0134 |[Gas Station](src/main/ts/g0101_0200/s0134_gas_station/solution.ts)| Medium | Top_Interview_Questions, Array, Greedy | 0 | 100.00 +| 0135 |[Candy](src/main/ts/g0101_0200/s0135_candy/solution.ts)| Hard | Array, Greedy | 2 | 96.15 +| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0013 |[Roman to Integer](src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Math | 3 | 94.58 +| 0012 |[Integer to Roman](src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts)| Medium | String, Hash_Table, Math | 3 | 93.02 +| 0058 |[Length of Last Word](src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts)| Easy | String | 0 | 100.00 +| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00 +| 0151 |[Reverse Words in a String](src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts)| Medium | String, Two_Pointers, LeetCode_75_Array/String | 0 | 100.00 +| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts)| Medium | String | 2 | 99.08 +| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 +| 0068 |[Text Justification](src/main/ts/g0001_0100/s0068_text_justification/solution.ts)| Hard | Array, String, Simulation | 0 | 100.00 + +#### Top Interview 150 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0125 |[Valid Palindrome](src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers | 0 | 100.00 +| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 0 | 100.00 +| 0167 |[Two Sum II - Input Array Is Sorted](src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts)| Medium | Array, Binary_Search, Two_Pointers | 0 | 100.00 +| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 80.13 +| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56 + +#### Top Interview 150 Sliding Window + +| | | | | | +|-|-|-|-|-|- +| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11 +| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.91 +| 0030 |[Substring with Concatenation of All Words](src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts)| Hard | String, Hash_Table, Sliding_Window | 13 | 97.44 +| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 20 | 90.35 + +#### Top Interview 150 Matrix + +| | | | | | +|-|-|-|-|-|- +| 0036 |[Valid Sudoku](src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix | 1 | 99.60 +| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00 +| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00 +| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 4 | 50.63 +| 0289 |[Game of Life](src/main/ts/g0201_0300/s0289_game_of_life/solution.ts)| Medium | Array, Matrix, Simulation | 0 | 100.00 + +#### Top Interview 150 Hashmap + +| | | | | | +|-|-|-|-|-|- +| 0383 |[Ransom Note](src/main/ts/g0301_0400/s0383_ransom_note/solution.ts)| Easy | String, Hash_Table, Counting | 4 | 97.40 +| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table | 3 | 96.02 +| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table | 0 | 100.00 +| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99 +| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 78.99 +| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70 +| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00 +| 0219 |[Contains Duplicate II](src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts)| Easy | Array, Hash_Table, Sliding_Window | 17 | 79.29 +| 0128 |[Longest Consecutive Sequence](src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 34 | 90.07 + +#### Top Interview 150 Intervals + +| | | | | | +|-|-|-|-|-|- +| 0228 |[Summary Ranges](src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts)| Easy | Array | 0 | 100.00 +| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 87.99 +| 0057 |[Insert Interval](src/main/ts/g0001_0100/s0057_insert_interval/solution.ts)| Medium | Array | 0 | 100.00 +| 0452 |[Minimum Number of Arrows to Burst Balloons](src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.ts)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals | 75 | 98.54 + +#### Top Interview 150 Stack + +| | | | | | +|-|-|-|-|-|- +| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 1 | 86.85 +| 0071 |[Simplify Path](src/main/ts/g0001_0100/s0071_simplify_path/solution.ts)| Medium | String, Stack | 0 | 100.00 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10 +| 0150 |[Evaluate Reverse Polish Notation](src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts)| Medium | Top_Interview_Questions, Array, Math, Stack | 1 | 97.48 +| 0224 |[Basic Calculator](src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts)| Hard | String, Math, Stack, Recursion | 6 | 96.62 + +#### Top Interview 150 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 47 | 89.37 +| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 95.82 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21 +| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 49 | 72.42 +| 0092 |[Reverse Linked List II](src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts)| Medium | Linked_List | 0 | 100.00 +| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 +| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 +| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0061 |[Rotate List](src/main/ts/g0001_0100/s0061_rotate_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0086 |[Partition List](src/main/ts/g0001_0100/s0086_partition_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 97 | 81.52 + +#### Top Interview 150 Binary Tree General + +| | | | | | +|-|-|-|-|-|- +| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00 +| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 2 | 93.38 +| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.ts)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer | 1 | 98.78 +| 0117 |[Populating Next Right Pointers in Each Node II](src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 47 | 97.74 +| 0114 |[Flatten Binary Tree to Linked List](src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 +| 0112 |[Path Sum](src/main/ts/g0101_0200/s0112_path_sum/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0129 |[Sum Root to Leaf Numbers](src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.ts)| Medium | Depth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 2 | 71.11 +| 0173 |[Binary Search Tree Iterator](src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 6 | 98.16 +| 0222 |[Count Complete Tree Nodes](src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree | 0 | 100.00 +| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 61 | 75.97 + +#### Top Interview 150 Binary Tree BFS + +| | | | | | +|-|-|-|-|-|- +| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00 +| 0637 |[Average of Levels in Binary Tree](src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 +| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 +| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 + +#### Top Interview 150 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- +| 0530 |[Minimum Absolute Difference in BST](src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00 +| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 + +#### Top Interview 150 Graph General + +| | | | | | +|-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94 +| 0130 |[Surrounded Regions](src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 1 | 99.18 +| 0133 |[Clone Graph](src/main/ts/g0101_0200/s0133_clone_graph/solution.ts)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 48 | 82.94 +| 0399 |[Evaluate Division](src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 0 | 100.00 +| 0207 |[Course Schedule](src/main/ts/g0201_0300/s0207_course_schedule/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 11 | 81.08 +| 0210 |[Course Schedule II](src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 2 | 99.76 + +#### Top Interview 150 Graph BFS + +| | | | | | +|-|-|-|-|-|- +| 0909 |[Snakes and Ladders](src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution.ts)| Medium | Array, Breadth_First_Search, Matrix | 5 | 98.27 +| 0433 |[Minimum Genetic Mutation](src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts)| Medium | String, Hash_Table, Breadth_First_Search | 0 | 100.00 +| 0127 |[Word Ladder](src/main/ts/g0101_0200/s0127_word_ladder/solution.ts)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 41 | 95.63 + +#### Top Interview 150 Trie + +| | | | | | +|-|-|-|-|-|- +| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 48 | 63.95 +| 0211 |[Design Add and Search Words Data Structure](src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts)| Medium | String, Depth_First_Search, Design, Trie | 450 | 92.88 +| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie | 62 | 99.46 + +#### Top Interview 150 Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking | 46 | 96.14 +| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44 +| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.17 +| 0052 |[N-Queens II](src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts)| Hard | Backtracking | 1 | 96.89 +| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 1 | 72.82 +| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 243 | 85.30 + +#### Top Interview 150 Divide and Conquer + +| | | | | | +|-|-|-|-|-|- +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00 +| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 36 | 44.94 +| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer | 51 | 96.23 +| 0023 |[Merge k Sorted Lists](src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 4 | 97.65 + +#### Top Interview 150 Kadane's Algorithm + +| | | | | | +|-|-|-|-|-|- +| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0918 |[Maximum Sum Circular Subarray](src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 91.04 + +#### Top Interview 150 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 +| 0162 |[Find Peak Element](src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00 +| 0004 |[Median of Two Sorted Arrays](src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 82.74 + +#### Top Interview 150 Heap + +| | | | | | +|-|-|-|-|-|- +| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 4 | 99.64 +| 0502 |[IPO](src/main/ts/g0501_0600/s0502_ipo/solution.ts)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue | 193 | 89.19 +| 0373 |[Find K Pairs with Smallest Sums](src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts)| Medium | Array, Heap_Priority_Queue | 42 | 85.15 +| 0295 |[Find Median from Data Stream](src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 106 | 92.31 + +#### Top Interview 150 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- +| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation | 0 | 100.00 +| 0190 |[Reverse Bits](src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 34 | 99.74 +| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00 +| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27 +| 0137 |[Single Number II](src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts)| Medium | Array, Bit_Manipulation | 0 | 100.00 +| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation | 2 | 99.12 + +#### Top Interview 150 Math + +| | | | | | +|-|-|-|-|-|- +| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math | 3 | 99.14 +| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00 +| 0172 |[Factorial Trailing Zeroes](src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts)| Medium | Top_Interview_Questions, Math | 0 | 100.00 +| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Easy | Top_Interview_Questions, Math, Binary_Search | 1 | 74.84 +| 0050 |[Pow(x, n)](src/main/ts/g0001_0100/s0050_powx_n/solution.ts)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00 +| 0149 |[Max Points on a Line](src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 9 | 97.18 + +#### Top Interview 150 1D DP + +| | | | | | +|-|-|-|-|-|- +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 4 | 76.41 +| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42 +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68 + +#### Top Interview 150 Multidimensional DP + +| | | | | | +|-|-|-|-|-|- +| 0120 |[Triangle](src/main/ts/g0101_0200/s0120_triangle/solution.ts)| Medium | Array, Dynamic_Programming | 0 | 100.00 +| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 4 | 70.73 +| 0063 |[Unique Paths II](src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts)| Medium | Array, Dynamic_Programming, Matrix | 0 | 100.00 +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14 +| 0097 |[Interleaving String](src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts)| Medium | String, Dynamic_Programming | 43 | 97.65 +| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 6 | 93.83 +| 0123 |[Best Time to Buy and Sell Stock III](src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.ts)| Hard | Array, Dynamic_Programming | 5 | 85.07 +| 0188 |[Best Time to Buy and Sell Stock IV](src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.ts)| Hard | Array, Dynamic_Programming | 0 | 100.00 +| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 18 | 59.02 ### Data Structure I @@ -1115,19 +1310,20 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 66 | 90.36 +| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 2 Array | | | | | | |-|-|-|-|-|- -| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 54 | 91.72 +| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70 +| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00 #### Day 3 Array | | | | | | |-|-|-|-|-|- -| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 56 | 99.56 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44 #### Day 4 Array @@ -1138,51 +1334,55 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 +| 0036 |[Valid Sudoku](src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix | 1 | 99.60 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 #### Day 6 String | | | | | | |-|-|-|-|-|- +| 0383 |[Ransom Note](src/main/ts/g0301_0400/s0383_ransom_note/solution.ts)| Easy | String, Hash_Table, Counting | 4 | 97.40 +| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99 #### Day 7 Linked List | | | | | | |-|-|-|-|-|- -| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 93.37 -| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 59 | 86.77 +| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 47 | 89.37 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21 #### Day 8 Linked List | | | | | | |-|-|-|-|-|- -| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 51 | 92.87 +| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 9 Stack Queue | | | | | | |-|-|-|-|-|- -| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 50 | 95.90 +| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 1 | 86.85 #### Day 10 Tree | | | | | | |-|-|-|-|-|- -| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 45 | 97.30 +| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 #### Day 11 Tree | | | | | | |-|-|-|-|-|- -| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 60 | 97.47 -| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 51 | 97.14 -| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 49 | 98.54 +| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00 +| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00 +| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 #### Day 12 Tree | | | | | | |-|-|-|-|-|- -| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 52 | 81.65 +| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0112 |[Path Sum](src/main/ts/g0101_0200/s0112_path_sum/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 #### Day 13 Tree @@ -1193,7 +1393,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 51 | 98.35 +| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00 ### Data Structure II @@ -1201,35 +1401,35 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 56 | 85.48 -| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 50 | 96.16 -| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 148 | 92.62 +| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27 +| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56 #### Day 2 Array | | | | | | |-|-|-|-|-|- -| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41 -| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06 +| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 87.99 #### Day 3 Array | | | | | | |-|-|-|-|-|- -| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 45 | 95.31 +| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00 #### Day 4 Array | | | | | | |-|-|-|-|-|- -| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 58 | 64.44 +| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 42 | 94.61 #### Day 5 Array | | | | | | |-|-|-|-|-|- -| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 89 | 64.48 -| 0560 |[Subarray Sum Equals K](src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 70 | 92.45 +| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81 +| 0560 |[Subarray Sum Equals K](src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 14 | 87.34 #### Day 6 String @@ -1240,73 +1440,79 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0763 |[Partition Labels](src/main/ts/g0701_0800/s0763_partition_labels/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 54 | 94.74 +| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table | 0 | 100.00 +| 0763 |[Partition Labels](src/main/ts/g0701_0800/s0763_partition_labels/solution.ts)| Medium | String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 4 | 86.89 #### Day 8 String | | | | | | |-|-|-|-|-|- -| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 93 | 97.29 +| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 78.99 #### Day 9 String | | | | | | |-|-|-|-|-|- -| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 68 | 95.34 +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14 #### Day 10 Linked List | | | | | | |-|-|-|-|-|- -| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 92 | 77.86 -| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 94.39 +| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 95.82 +| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 51 | 76.99 #### Day 11 Linked List | | | | | | |-|-|-|-|-|- -| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 67 | 93.58 +| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 65 | 72.36 +| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 #### Day 12 Linked List | | | | | | |-|-|-|-|-|- -| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 62.67 +| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 #### Day 13 Linked List | | | | | | |-|-|-|-|-|- -| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 74 | 66.83 +| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00 #### Day 14 Stack Queue | | | | | | |-|-|-|-|-|- -| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 84 | 92.72 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10 #### Day 15 Tree | | | | | | |-|-|-|-|-|- -| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 65 | 96.47 +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00 +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 2 | 93.38 +| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00 #### Day 16 Tree | | | | | | |-|-|-|-|-|- +| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00 #### Day 17 Tree | | | | | | |-|-|-|-|-|- -| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 54 | 97.22 +| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0173 |[Binary Search Tree Iterator](src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 6 | 98.16 #### Day 18 Tree | | | | | | |-|-|-|-|-|- -| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 59 | 96.11 +| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 61 | 75.97 #### Day 19 Graph @@ -1317,8 +1523,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 148 | 54.45 -| 0347 |[Top K Frequent Elements](src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 62 | 87.48 +| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 4 | 99.64 +| 0347 |[Top K Frequent Elements](src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 7 | 87.13 #### Day 21 Heap Priority Queue @@ -1331,19 +1537,20 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 51 | 80.95 +| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 #### Day 2 Two Pointers | | | | | | |-|-|-|-|-|- -| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 75 | 97.25 +| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17 #### Day 3 Two Pointers | | | | | | |-|-|-|-|-|- -| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 71 | 91.63 +| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86 +| 0167 |[Two Sum II - Input Array Is Sorted](src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts)| Medium | Array, Binary_Search, Two_Pointers | 0 | 100.00 #### Day 4 Two Pointers @@ -1354,13 +1561,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 54 | 87.87 +| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00 #### Day 6 Sliding Window | | | | | | |-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 65 | 90.77 +| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.91 #### Day 7 Breadth First Search Depth First Search @@ -1381,141 +1588,365 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated. | | | | | | |-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 59 | 86.77 -| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 51 | 92.87 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21 +| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00 #### Day 11 Recursion Backtracking | | | | | | |-|-|-|-|-|- -| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 56 | 96.26 +| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking | 46 | 96.14 +| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44 #### Day 12 Dynamic Programming | | | | | | |-|-|-|-|-|- -| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58 -| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 51 | 77.29 +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0120 |[Triangle](src/main/ts/g0101_0200/s0120_triangle/solution.ts)| Medium | Array, Dynamic_Programming | 0 | 100.00 #### Day 13 Bit Manipulation | | | | | | |-|-|-|-|-|- +| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00 #### Day 14 Bit Manipulation | | | | | | |-|-|-|-|-|- -| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 56 | 85.48 +| 0190 |[Reverse Bits](src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 34 | 99.74 +| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27 + +### Algorithm II + +#### Day 1 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00 + +#### Day 2 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00 +| 0162 |[Find Peak Element](src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00 + +#### Day 3 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00 +| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56 + +#### Day 4 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 80.13 + +#### Day 5 Sliding Window + +| | | | | | +|-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80 +| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11 + +#### Day 6 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94 + +#### Day 7 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- +| 0117 |[Populating Next Right Pointers in Each Node II](src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 47 | 97.74 + +#### Day 8 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- +| 0130 |[Surrounded Regions](src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 1 | 99.18 + +#### Day 9 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00 + +#### Day 10 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.17 + +#### Day 11 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 1 | 72.82 +| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 243 | 85.30 + +#### Day 12 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 + +#### Day 13 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 84.27 +| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00 + +#### Day 14 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14 + +#### Day 15 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 4 | 76.41 + +#### Day 16 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68 + +#### Day 17 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 50 | 69.40 + +#### Day 18 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 6 | 93.83 +| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42 + +#### Day 19 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- +| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation | 2 | 99.12 + +#### Day 20 Others + +| | | | | | +|-|-|-|-|-|- + +#### Day 21 Others + +| | | | | | +|-|-|-|-|-|- +| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00 +| 0149 |[Max Points on a Line](src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 9 | 97.18 ## Algorithms | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|--------- -| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 94 | 80.56 -| 0763 |[Partition Labels](src/main/ts/g0701_0800/s0763_partition_labels/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 54 | 94.74 -| 0739 |[Daily Temperatures](src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Programming_Skills_II_Day_6, Big_O_Time_O(n)_Space_O(n) | 194 | 97.36 -| 0647 |[Palindromic Substrings](src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 60 | 89.76 -| 0560 |[Subarray Sum Equals K](src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Data_Structure_II_Day_5_Array, Big_O_Time_O(n)_Space_O(n) | 70 | 92.45 -| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 61 | 80.89 -| 0494 |[Target Sum](src/main/ts/g0401_0500/s0494_target_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Backtracking, Big_O_Time_O(n\*(sum+s))_Space_O(n\*(sum+s)) | 77 | 81.99 -| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 69 | 96.69 -| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 68 | 86.71 -| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 91 | 74.38 -| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Level_1_Day_14_Stack, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 51 | 81.02 -| 0347 |[Top K Frequent Elements](src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(k) | 62 | 87.48 -| 0338 |[Counting Bits](src/main/ts/g0301_0400/s0338_counting_bits/solution.ts)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Udemy_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 69 | 86.81 -| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(amount) | 85 | 86.14 -| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_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, Big_O_Time_O(n\*log_n)_Space_O(n) | 57 | 93.75 -| 0295 |[Find Median from Data Stream](src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 335 | 99.44 -| 0287 |[Find the Duplicate Number](src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Binary_Search_II_Day_5, Big_O_Time_O(n)_Space_O(n) | 60 | 98.11 -| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 71 | 91.63 -| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8, Big_O_Time_O(n+m)_Space_O(1) | 58 | 64.44 -| 0239 |[Sliding Window Maximum](src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Udemy_Arrays, Big_O_Time_O(n\*k)_Space_O(n+k) | 216 | 99.50 -| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Data_Structure_II_Day_5_Array, Udemy_Arrays, Big_O_Time_O(n^2)_Space_O(n) | 89 | 64.48 -| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_18_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 59 | 96.11 -| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion, Level_2_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 96 | 95.67 -| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_II_Day_17_Tree, Level_2_Day_9_Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 54 | 97.22 -| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| 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, Big_O_Time_O(n)_Space_O(n) | 52 | 81.65 -| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Big_O_Time_O(m\*n)_Space_O(m\*n) | 83 | 79.70 -| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| 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, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 148 | 54.45 -| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Level_2_Day_16_Design, Udemy_Trie_and_Heap, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 168 | 80.99 -| 0207 |[Course Schedule](src/main/ts/g0201_0300/s0207_course_schedule/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 68 | 70.14 -| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| 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) | 51 | 92.87 -| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, 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, Big_O_Time_O(M\*N)_Space_O(M\*N) | 61 | 96.71 -| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| 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, Big_O_Time_O(n)_Space_O(n) | 51 | 77.29 -| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 75 | 97.25 -| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| 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, Big_O_Time_O(n)_Space_O(1) | 50 | 96.16 -| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Udemy_Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 67 | 93.58 -| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Easy | 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, Big_O_Time_O(1)_Space_O(N) | 84 | 92.72 -| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_II_Day_2_Binary_Search, Binary_Search_I_Day_12, Udemy_Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 42 | 98.87 -| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| 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) | 53 | 87.50 -| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Level_2_Day_4_Linked_List, Big_O_Time_O(log(N))_Space_O(log(N)) | 141 | 97.14 -| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Udemy_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 473 | 94.72 -| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_10_Linked_List, Level_1_Day_4_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 94.39 -| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_I_Day_7_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 59 | 93.37 -| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| 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, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 56 | 88.44 -| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Programming_Skills_II_Day_14, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(N) | 52 | 88.27 -| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| 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, Big_O_Time_O(N)_Space_O(1) | 56 | 85.48 -| 0131 |[Palindrome Partitioning](src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(N\*2^N)_Space_O(2^N\*N) | 203 | 99.22 -| 0128 |[Longest Consecutive Sequence](src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 92 | 93.69 -| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(N)_Space_O(N) | 61 | 96.73 -| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| 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, Big_O_Time_O(N)_Space_O(1) | 56 | 99.56 -| 0114 |[Flatten Binary Tree to Linked List](src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(N) | 55 | 90.66 -| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Big_O_Time_O(N)_Space_O(N) | 65 | 96.47 -| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Programming_Skills_I_Day_10_Linked_List_and_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(N)_Space_O(H) | 51 | 97.14 -| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| 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, Big_O_Time_O(N)_Space_O(N) | 60 | 97.47 -| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| 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, Big_O_Time_O(N)_Space_O(log(N)) | 49 | 98.54 -| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| 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, Big_O_Time_O(N)_Space_O(log(N)) | 51 | 98.35 -| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 45 | 96.00 -| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| 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) | 45 | 97.30 -| 0084 |[Largest Rectangle in Histogram](src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 78 | 92.44 -| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 327 | 95.78 -| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| 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) | 50 | 94.61 -| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Big_O_Time_O(s.length())_Space_O(1) | 82 | 82.17 -| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41 -| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| 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, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82 -| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 61 | 97.66 -| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 68 | 95.20 -| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| 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, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58 -| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 48 | 99.67 -| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| 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) | 40 | 98.97 -| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| 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, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06 -| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| 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, Big_O_Time_O(n)_Space_O(1) | 58 | 91.95 -| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| Easy | 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, Big_O_Time_O(n)_Space_O(1) | 66 | 90.36 -| 0051 |[N-Queens](src/main/ts/g0001_0100/s0051_n_queens/solution.ts)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 57 | 93.84 -| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| 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, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 93 | 97.29 -| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Data_Structure_II_Day_3_Array, Programming_Skills_II_Day_7, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n^2)_Space_O(1) | 45 | 95.31 -| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| 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, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 56 | 96.26 -| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_4, Big_O_Time_O(n)_Space_O(1) | 50 | 95.93 -| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Dynamic_Programming_I_Day_9, Udemy_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 46 | 99.52 -| 0041 |[First Missing Positive](src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 55 | 98.51 -| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Algorithm_II_Day_10_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n+2^n) | 65 | 86.86 -| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_2, Big_O_Time_O(log_n)_Space_O(1) | 51 | 80.95 -| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_5, Big_O_Time_O(log_n)_Space_O(1) | 45 | 98.05 -| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| 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, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54 -| 0032 |[Longest Valid Parentheses](src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 56 | 89.31 -| 0031 |[Next Permutation](src/main/ts/g0001_0100/s0031_next_permutation/solution.ts)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 47 | 99.30 -| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(k) | 74 | 66.83 -| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| 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) | 59 | 62.67 -| 0023 |[Merge k Sorted Lists](src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 76 | 94.52 -| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n) | 60 | 62.03 -| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| 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, Big_O_Time_O(m+n)_Space_O(m+n) | 59 | 86.77 -| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 50 | 95.90 -| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Big_O_Time_O(L)_Space_O(L) | 54 | 87.87 -| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(4^n)_Space_O(n) | 52 | 79.11 -| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| 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, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 148 | 92.62 -| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 57 | 98.23 -| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 69 | 92.65 -| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math, Udemy_Integers | 137 | 88.64 -| 0008 |[String to Integer (atoi)](src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts)| Medium | Top_Interview_Questions, String | 56 | 99.01 -| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 56 | 95.68 -| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts)| Medium | String | 64 | 95.38 -| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| 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, Big_O_Time_O(n)_Space_O(n) | 68 | 95.34 -| 0004 |[Median of Two Sorted Arrays](src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 86 | 92.15 -| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| 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, Big_O_Time_O(n)_Space_O(1) | 65 | 90.77 -| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 92 | 77.86 -| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 54 | 91.72 +| 1143 |[Longest Common Subsequence](src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 50 | 69.40 +| 0918 |[Maximum Sum Circular Subarray](src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue, Dynamic_Programming_I_Day_5, Top_Interview_150_Kadane's_Algorithm | 2 | 91.04 +| 0909 |[Snakes and Ladders](src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution.ts)| Medium | Array, Breadth_First_Search, Matrix, Top_Interview_150_Graph_BFS | 5 | 98.27 +| 0763 |[Partition Labels](src/main/ts/g0701_0800/s0763_partition_labels/solution.ts)| Medium | String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 4 | 86.89 +| 0739 |[Daily Temperatures](src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Programming_Skills_II_Day_6, Big_O_Time_O(n)_Space_O(n) | 18 | 80.57 +| 0647 |[Palindromic Substrings](src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts)| Medium | String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 5 | 100.00 +| 0637 |[Average of Levels in Binary Tree](src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00 +| 0560 |[Subarray Sum Equals K](src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Data_Structure_II_Day_5_Array, Big_O_Time_O(n)_Space_O(n) | 14 | 87.34 +| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 1 | 87.16 +| 0530 |[Minimum Absolute Difference in BST](src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Top_Interview_150_Binary_Search_Tree | 0 | 100.00 +| 0502 |[IPO](src/main/ts/g0501_0600/s0502_ipo/solution.ts)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue, Top_Interview_150_Heap | 193 | 89.19 +| 0494 |[Target Sum](src/main/ts/g0401_0500/s0494_target_sum/solution.ts)| Medium | Array, Dynamic_Programming, Backtracking, Big_O_Time_O(n\*(sum+s))_Space_O(n\*(sum+s)) | 24 | 83.43 +| 0452 |[Minimum Number of Arrows to Burst Balloons](src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.ts)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals, Top_Interview_150_Intervals | 75 | 98.54 +| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80 +| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts)| Medium | Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 3 | 86.41 +| 0433 |[Minimum Genetic Mutation](src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts)| Medium | String, Hash_Table, Breadth_First_Search, Graph_Theory_I_Day_12_Breadth_First_Search, Top_Interview_150_Graph_BFS | 0 | 100.00 +| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer, Top_Interview_150_Divide_and_Conquer | 51 | 96.23 +| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 33 | 93.24 +| 0399 |[Evaluate Division](src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS, Top_Interview_150_Graph_General | 0 | 100.00 +| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Level_1_Day_14_Stack, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00 +| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers, Dynamic_Programming_I_Day_19, Level_1_Day_2_String, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers | 0 | 100.00 +| 0383 |[Ransom Note](src/main/ts/g0301_0400/s0383_ransom_note/solution.ts)| Easy | String, Hash_Table, Counting, Data_Structure_I_Day_6_String, Top_Interview_150_Hashmap | 4 | 97.40 +| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized, Programming_Skills_II_Day_20, Top_Interview_150_Array/String | 73 | 82.52 +| 0373 |[Find K Pairs with Smallest Sums](src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts)| Medium | Array, Heap_Priority_Queue, Top_Interview_150_Heap | 42 | 85.15 +| 0347 |[Top K Frequent Elements](src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(k) | 7 | 87.13 +| 0338 |[Counting Bits](src/main/ts/g0301_0400/s0338_counting_bits/solution.ts)| Easy | Dynamic_Programming, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Udemy_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 1 | 89.22 +| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42 +| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| 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) | 6 | 84.68 +| 0295 |[Find Median from Data Stream](src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Top_Interview_150_Heap, Big_O_Time_O(n\*log_n)_Space_O(n) | 106 | 92.31 +| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table, Data_Structure_II_Day_7_String, Top_Interview_150_Hashmap | 0 | 100.00 +| 0289 |[Game of Life](src/main/ts/g0201_0300/s0289_game_of_life/solution.ts)| Medium | Array, Matrix, Simulation, Top_Interview_150_Matrix | 0 | 100.00 +| 0287 |[Find the Duplicate Number](src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts)| 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) | 5 | 88.65 +| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86 +| 0274 |[H-Index](src/main/ts/g0201_0300/s0274_h_index/solution.ts)| Medium | Array, Sorting, Counting_Sort, Top_Interview_150_Array/String | 0 | 100.00 +| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting, Data_Structure_I_Day_6_String, Programming_Skills_I_Day_11_Containers_and_Libraries, Udemy_Strings, Top_Interview_150_Hashmap | 4 | 97.99 +| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8, Big_O_Time_O(n+m)_Space_O(1) | 42 | 94.61 +| 0239 |[Sliding Window Maximum](src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts)| Hard | Top_100_Liked_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Udemy_Arrays, Big_O_Time_O(n\*k)_Space_O(n+k) | 26 | 99.07 +| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Data_Structure_II_Day_5_Array, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81 +| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Data_Structure_II_Day_18_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(n)_Space_O(n) | 61 | 75.97 +| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| 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) | 3 | 92.85 +| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| 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) | 0 | 100.00 +| 0228 |[Summary Ranges](src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts)| Easy | Array, Top_Interview_150_Intervals | 0 | 100.00 +| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| 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) | 0 | 100.00 +| 0224 |[Basic Calculator](src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts)| Hard | String, Math, Stack, Recursion, Top_Interview_150_Stack | 6 | 96.62 +| 0222 |[Count Complete Tree Nodes](src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree, Binary_Search_II_Day_10, Top_Interview_150_Binary_Tree_General | 0 | 100.00 +| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| 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) | 18 | 59.02 +| 0219 |[Contains Duplicate II](src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts)| Easy | Array, Hash_Table, Sliding_Window, Top_Interview_150_Hashmap | 17 | 79.29 +| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Data_Structure_II_Day_20_Heap_Priority_Queue, Top_Interview_150_Heap, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 4 | 99.64 +| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie, Top_Interview_150_Trie | 62 | 99.46 +| 0211 |[Design Add and Search Words Data Structure](src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts)| Medium | String, Depth_First_Search, Design, Trie, Top_Interview_150_Trie | 450 | 92.88 +| 0210 |[Course Schedule II](src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Level_2_Day_11_Graph/BFS/DFS, Top_Interview_150_Graph_General | 2 | 99.76 +| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Binary_Search_II_Day_1, Top_Interview_150_Sliding_Window | 2 | 88.11 +| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_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) | 48 | 63.95 +| 0207 |[Course Schedule](src/main/ts/g0201_0300/s0207_course_schedule/solution.ts)| 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) | 11 | 81.08 +| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, 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) | 0 | 100.00 +| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table, Level_1_Day_2_String, Top_Interview_150_Hashmap | 3 | 96.02 +| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers, Algorithm_II_Day_21_Others, Programming_Skills_I_Day_4_Loop, Level_2_Day_1_Implementation/Simulation, Top_Interview_150_Hashmap | 0 | 100.00 +| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation, Algorithm_II_Day_19_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 2 | 99.12 +| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, 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) | 57 | 93.94 +| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS, Data_Structure_II_Day_16_Tree, Level_2_Day_15_Tree, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00 +| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, 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) | 0 | 100.00 +| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Algorithm_I_Day_13_Bit_Manipulation, Programming_Skills_I_Day_2_Operator, Udemy_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 0 | 100.00 +| 0190 |[Reverse Bits](src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 34 | 99.74 +| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17 +| 0188 |[Best Time to Buy and Sell Stock IV](src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.ts)| Hard | Array, Dynamic_Programming, Top_Interview_150_Multidimensional_DP | 0 | 100.00 +| 0173 |[Binary Search Tree Iterator](src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator, Data_Structure_II_Day_17_Tree, Programming_Skills_II_Day_16, Level_2_Day_9_Binary_Search_Tree, Top_Interview_150_Binary_Tree_General | 6 | 98.16 +| 0172 |[Factorial Trailing Zeroes](src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts)| Medium | Top_Interview_Questions, Math, Udemy_Integers, Top_Interview_150_Math | 0 | 100.00 +| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| 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) | 0 | 100.00 +| 0167 |[Two Sum II - Input Array Is Sorted](src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts)| Medium | Array, Binary_Search, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Binary_Search_I_Day_7, Top_Interview_150_Two_Pointers | 0 | 100.00 +| 0162 |[Find Peak Element](src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search, Algorithm_II_Day_2_Binary_Search, Binary_Search_II_Day_12, Top_Interview_150_Binary_Search | 0 | 100.00 +| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Udemy_Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 65 | 72.36 +| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| 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) | 5 | 99.10 +| 0153 |[Find Minimum in Rotated Sorted Array](src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts)| 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) | 0 | 100.00 +| 0152 |[Maximum Product Subarray](src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts)| 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) | 0 | 100.00 +| 0151 |[Reverse Words in a String](src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts)| Medium | String, Two_Pointers, LeetCode_75_Array/String, Udemy_Strings, Top_Interview_150_Array/String | 0 | 100.00 +| 0150 |[Evaluate Reverse Polish Notation](src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts)| Medium | Top_Interview_Questions, Array, Math, Stack, Programming_Skills_II_Day_3, Top_Interview_150_Stack | 1 | 97.48 +| 0149 |[Max Points on a Line](src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry, Algorithm_II_Day_21_Others, Top_Interview_150_Math | 9 | 97.18 +| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| 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)) | 36 | 44.94 +| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| 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) | 97 | 81.52 +| 0142 |[Linked List Cycle II](src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_10_Linked_List, Level_1_Day_4_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 51 | 76.99 +| 0141 |[Linked List Cycle](src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_I_Day_7_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(N)_Space_O(1) | 47 | 89.37 +| 0139 |[Word Break](src/main/ts/g0101_0200/s0139_word_break/solution.ts)| 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) | 4 | 76.41 +| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Programming_Skills_II_Day_14, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(N)_Space_O(N) | 49 | 72.42 +| 0137 |[Single Number II](src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts)| Medium | Array, Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 0 | 100.00 +| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_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) | 1 | 78.27 +| 0135 |[Candy](src/main/ts/g0101_0200/s0135_candy/solution.ts)| Hard | Array, Greedy, Top_Interview_150_Array/String | 2 | 96.15 +| 0134 |[Gas Station](src/main/ts/g0101_0200/s0134_gas_station/solution.ts)| Medium | Top_Interview_Questions, Array, Greedy, Top_Interview_150_Array/String | 0 | 100.00 +| 0133 |[Clone Graph](src/main/ts/g0101_0200/s0133_clone_graph/solution.ts)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph, Udemy_Graph, Top_Interview_150_Graph_General | 48 | 82.94 +| 0131 |[Palindrome Partitioning](src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(N\*2^N)_Space_O(2^N\*N) | 13 | 94.96 +| 0130 |[Surrounded Regions](src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Algorithm_II_Day_8_Breadth_First_Search_Depth_First_Search, Top_Interview_150_Graph_General | 1 | 99.18 +| 0129 |[Sum Root to Leaf Numbers](src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.ts)| Medium | Depth_First_Search, Tree, Binary_Tree, Top_Interview_150_Binary_Tree_General | 0 | 100.00 +| 0128 |[Longest Consecutive Sequence](src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts)| 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) | 34 | 90.07 +| 0127 |[Word Ladder](src/main/ts/g0101_0200/s0127_word_ladder/solution.ts)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search, Graph_Theory_I_Day_12_Breadth_First_Search, Top_Interview_150_Graph_BFS | 41 | 95.63 +| 0125 |[Valid Palindrome](src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers | 0 | 100.00 +| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| 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) | 2 | 71.11 +| 0123 |[Best Time to Buy and Sell Stock III](src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.ts)| Hard | Array, Dynamic_Programming, Top_Interview_150_Multidimensional_DP | 5 | 85.07 +| 0122 |[Best Time to Buy and Sell Stock II](src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Dynamic_Programming_I_Day_7, Udemy_Arrays, Top_Interview_150_Array/String | 0 | 100.00 +| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| 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) | 1 | 96.44 +| 0120 |[Triangle](src/main/ts/g0101_0200/s0120_triangle/solution.ts)| Medium | Array, Dynamic_Programming, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_13, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP | 0 | 100.00 +| 0117 |[Populating Next Right Pointers in Each Node II](src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List, Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search, Top_Interview_150_Binary_Tree_General | 47 | 97.74 +| 0114 |[Flatten Binary Tree to Linked List](src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts)| 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) | 0 | 100.00 +| 0112 |[Path Sum](src/main/ts/g0101_0200/s0112_path_sum/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_12_Tree, Top_Interview_150_Binary_Tree_General | 0 | 100.00 +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Level_2_Day_9_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Divide_and_Conquer | 0 | 100.00 +| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.ts)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Top_Interview_150_Binary_Tree_General | 1 | 98.78 +| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| 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) | 2 | 93.38 +| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, 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) | 0 | 100.00 +| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00 +| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| 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) | 0 | 100.00 +| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| 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)) | 0 | 100.00 +| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Level_2_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General | 0 | 100.00 +| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| 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)) | 0 | 100.00 +| 0097 |[Interleaving String](src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts)| Medium | String, Dynamic_Programming, Top_Interview_150_Multidimensional_DP | 43 | 97.65 +| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| 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) | 0 | 100.00 +| 0092 |[Reverse Linked List II](src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts)| Medium | Linked_List, Top_Interview_150_Linked_List | 0 | 100.00 +| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_I_Day_2_Array, Top_Interview_150_Array/String | 0 | 100.00 +| 0086 |[Partition List](src/main/ts/g0001_0100/s0086_partition_list/solution.ts)| Medium | Two_Pointers, Linked_List, Top_Interview_150_Linked_List | 0 | 100.00 +| 0084 |[Largest Rectangle in Histogram](src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 15 | 72.81 +| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Algorithm_II_Day_3_Two_Pointers, Top_Interview_150_Linked_List | 0 | 100.00 +| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers, Udemy_Arrays, Top_Interview_150_Array/String | 40 | 99.63 +| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| 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) | 243 | 85.30 +| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| 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) | 0 | 100.00 +| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking | 46 | 96.14 +| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| 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) | 20 | 90.35 +| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| 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) | 0 | 100.00 +| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 4 | 50.63 +| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, 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) | 6 | 93.83 +| 0071 |[Simplify Path](src/main/ts/g0001_0100/s0071_simplify_path/solution.ts)| Medium | String, Stack, Top_Interview_150_Stack | 0 | 100.00 +| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| 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) | 0 | 100.00 +| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Easy | Top_Interview_Questions, Math, Binary_Search, Binary_Search_I_Day_4, Top_Interview_150_Math | 1 | 74.84 +| 0068 |[Text Justification](src/main/ts/g0001_0100/s0068_text_justification/solution.ts)| Hard | Array, String, Simulation, Top_Interview_150_Array/String | 0 | 100.00 +| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation, Programming_Skills_II_Day_5, Top_Interview_150_Bit_Manipulation | 0 | 100.00 +| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math, Programming_Skills_II_Day_3, Udemy_Arrays, Top_Interview_150_Math | 0 | 100.00 +| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| 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) | 4 | 70.73 +| 0063 |[Unique Paths II](src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts)| Medium | Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_15, Top_Interview_150_Multidimensional_DP | 0 | 100.00 +| 0062 |[Unique Paths](src/main/ts/g0001_0100/s0062_unique_paths/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, 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) | 0 | 100.00 +| 0061 |[Rotate List](src/main/ts/g0001_0100/s0061_rotate_list/solution.ts)| Medium | Two_Pointers, Linked_List, Programming_Skills_II_Day_16, Udemy_Linked_List, Top_Interview_150_Linked_List | 0 | 100.00 +| 0058 |[Length of Last Word](src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts)| Easy | String, Programming_Skills_II_Day_6, Udemy_Arrays, Top_Interview_150_Array/String | 0 | 100.00 +| 0057 |[Insert Interval](src/main/ts/g0001_0100/s0057_insert_interval/solution.ts)| Medium | Array, Level_2_Day_17_Interval, Top_Interview_150_Intervals | 0 | 100.00 +| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| 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) | 7 | 87.99 +| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| 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) | 0 | 100.00 +| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation, Programming_Skills_II_Day_8, Level_2_Day_1_Implementation/Simulation, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix | 0 | 100.00 +| 0053 |[Maximum Subarray](src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts)| 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) | 0 | 100.00 +| 0052 |[N-Queens II](src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts)| Hard | Backtracking, Top_Interview_150_Backtracking | 1 | 96.89 +| 0051 |[N-Queens](src/main/ts/g0001_0100/s0051_n_queens/solution.ts)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 6 | 95.85 +| 0050 |[Pow(x, n)](src/main/ts/g0001_0100/s0050_powx_n/solution.ts)| Medium | Top_Interview_Questions, Math, Recursion, Udemy_Integers, Top_Interview_150_Math | 0 | 100.00 +| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| 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) | 27 | 78.99 +| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Data_Structure_II_Day_3_Array, Programming_Skills_II_Day_7, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00 +| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| 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!) | 1 | 84.44 +| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| 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) | 1 | 84.27 +| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| 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) | 0 | 100.00 +| 0041 |[First Missing Positive](src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 1 | 99.11 +| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| 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) | 1 | 98.17 +| 0036 |[Valid Sudoku](src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix, Data_Structure_I_Day_5_Array, Top_Interview_150_Matrix | 1 | 99.60 +| 0035 |[Search Insert Position](src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts)| 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) | 0 | 100.00 +| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts)| 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) | 0 | 100.00 +| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| 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) | 0 | 100.00 +| 0032 |[Longest Valid Parentheses](src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 3 | 71.05 +| 0031 |[Next Permutation](src/main/ts/g0001_0100/s0031_next_permutation/solution.ts)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00 +| 0030 |[Substring with Concatenation of All Words](src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts)| Hard | String, Hash_Table, Sliding_Window, Top_Interview_150_Sliding_Window | 13 | 97.44 +| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching, Programming_Skills_II_Day_1, Top_Interview_150_Array/String | 0 | 100.00 +| 0027 |[Remove Element](src/main/ts/g0001_0100/s0027_remove_element/solution.ts)| Easy | Array, Two_Pointers, Top_Interview_150_Array/String | 0 | 100.00 +| 0026 |[Remove Duplicates from Sorted Array](src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Two_Pointers, Udemy_Two_Pointers, Top_Interview_150_Array/String | 0 | 100.00 +| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| 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) | 0 | 100.00 +| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| 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) | 0 | 100.00 +| 0023 |[Merge k Sorted Lists](src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts)| 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)) | 4 | 97.65 +| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts)| 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) | 1 | 72.82 +| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| 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) | 1 | 51.21 +| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| 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) | 1 | 86.85 +| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| 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) | 0 | 100.00 +| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00 +| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| 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) | 30 | 91.56 +| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Level_2_Day_2_String, Udemy_Strings, Top_Interview_150_Array/String | 0 | 100.00 +| 0013 |[Roman to Integer](src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Math, Top_Interview_150_Array/String | 3 | 94.58 +| 0012 |[Integer to Roman](src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts)| Medium | String, Hash_Table, Math, Top_Interview_150_Array/String | 3 | 93.02 +| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Top_Interview_150_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 80.13 +| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 5 | 90.44 +| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math, Udemy_Integers, Top_Interview_150_Math | 3 | 99.14 +| 0008 |[String to Integer (atoi)](src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts)| Medium | Top_Interview_Questions, String | 1 | 90.14 +| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 53 | 83.14 +| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts)| Medium | String, Top_Interview_150_Array/String | 2 | 99.08 +| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| 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) | 8 | 99.14 +| 0004 |[Median of Two Sorted Arrays](src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts)| 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 | 3 | 82.74 +| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| 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 | 3 | 96.91 +| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| 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 | 2 | 95.82 +| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| 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 | 1 | 89.70 ## Contributing Your ideas/fixes/algorithms are more than welcome! diff --git a/package.json b/package.json index bcda721..13a3b1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@javadev/leetcode-in-typescript", - "version": "1.1.0", + "version": "1.4.0", "description": "TypeScript-based LeetCode algorithm problem solutions, regularly updated", "keywords": [ "algorithm", diff --git a/src/main/ts/com_github_leetcode/_node.ts b/src/main/ts/com_github_leetcode/_node.ts new file mode 100644 index 0000000..e3aa79d --- /dev/null +++ b/src/main/ts/com_github_leetcode/_node.ts @@ -0,0 +1,15 @@ +class _Node { + val: number + left: _Node | null + right: _Node | null + next: _Node | null + + constructor(val?: number, left?: _Node, right?: _Node, next?: _Node) { + this.val = val === undefined ? 0 : val + this.left = left === undefined ? null : left + this.right = right === undefined ? null : right + this.next = next === undefined ? null : next + } +} + +export { _Node } diff --git a/src/main/ts/g0001_0100/s0001_two_sum/solution.ts b/src/main/ts/g0001_0100/s0001_two_sum/solution.ts index 53bdeaf..e344a0d 100644 --- a/src/main/ts/g0001_0100/s0001_two_sum/solution.ts +++ b/src/main/ts/g0001_0100/s0001_two_sum/solution.ts @@ -1,6 +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 #Big_O_Time_O(n)_Space_O(n) -// #2023_09_28_Time_54_ms_(91.72%)_Space_45.5_MB_(22.26%) +// #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_03_22_Time_1_ms_(89.70%)_Space_59.39_MB_(8.75%) function twoSum(nums: number[], target: number): number[] { const indexMap: Map = new Map() diff --git a/src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts b/src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts index 3672386..ae37aea 100644 --- a/src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts +++ b/src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts @@ -1,10 +1,11 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion // #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15 -// #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) #2023_09_28_Time_92_ms_(77.86%)_Space_48_MB_(69.29%) +// #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_03_22_Time_2_ms_(95.82%)_Space_62.80_MB_(21.07%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number diff --git a/src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts b/src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts index 595d1d0..c5514eb 100644 --- a/src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts +++ b/src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n)_Space_O(1) #2023_09_28_Time_65_ms_(90.77%)_Space_44.9_MB_(95.29%) +// #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task +// #2025_03_22_Time_3_ms_(96.91%)_Space_59.12_MB_(43.55%) function lengthOfLongestSubstring(s: string): number { const lastIndices: number[] = new Array(256).fill(-1) diff --git a/src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts b/src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts index fdbf3eb..516e7f3 100644 --- a/src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts +++ b/src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays/solution.ts @@ -1,5 +1,6 @@ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer -// #Big_O_Time_O(log(min(N,M)))_Space_O(1) #2023_08_26_Time_86_ms_(92.15%)_Space_48.3_MB_(59.73%) +// #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_03_22_Time_3_ms_(82.74%)_Space_59.34_MB_(44.01%) function findMedianSortedArrays(nums1: number[], nums2: number[]): number { const nums = nums1.concat(nums2) diff --git a/src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts b/src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts index c76fac1..6b12628 100644 --- a/src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts +++ b/src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts @@ -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 #Big_O_Time_O(n)_Space_O(n) -// #2023_09_28_Time_68_ms_(95.34%)_Space_44.5_MB_(96.58%) +// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP +// #Big_O_Time_O(n)_Space_O(n) #2025_03_22_Time_8_ms_(99.14%)_Space_59.13_MB_(33.28%) function longestPalindrome(s: string): string { const newStr: string[] = new Array(s.length * 2 + 1) diff --git a/src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts b/src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts index a1aab88..8e48ed8 100644 --- a/src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts +++ b/src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts @@ -1,4 +1,5 @@ -// #Medium #String #2023_08_26_Time_64_ms_(95.38%)_Space_47.3_MB_(64.49%) +// #Medium #String #Top_Interview_150_Array/String +// #2025_03_22_Time_2_ms_(99.08%)_Space_60.88_MB_(31.04%) function convert(s: string, numRows: number): string { if (numRows < 2) { diff --git a/src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts b/src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts index 89e5463..a714b35 100644 --- a/src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts +++ b/src/main/ts/g0001_0100/s0007_reverse_integer/solution.ts @@ -1,5 +1,5 @@ // #Medium #Top_Interview_Questions #Math #Udemy_Integers -// #2023_08_25_Time_56_ms_(95.68%)_Space_43.8_MB_(99.70%) +// #2025_03_22_Time_53_ms_(83.14%)_Space_58.56_MB_(6.02%) function reverse(x: number): number { let remaining = Math.abs(x) diff --git a/src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts b/src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts index ceb4dcd..fd80851 100644 --- a/src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts +++ b/src/main/ts/g0001_0100/s0008_string_to_integer_atoi/solution.ts @@ -1,4 +1,4 @@ -// #Medium #Top_Interview_Questions #String #2023_08_25_Time_56_ms_(99.01%)_Space_44_MB_(98.27%) +// #Medium #Top_Interview_Questions #String #2025_03_22_Time_1_ms_(90.14%)_Space_58.06_MB_(42.36%) function myAtoi(s: string): number { s = s.trim() diff --git a/src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts b/src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts index 117a804..0d315e2 100644 --- a/src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts +++ b/src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts @@ -1,4 +1,5 @@ -// #Easy #Math #Udemy_Integers #2023_08_25_Time_137_ms_(88.64%)_Space_50.5_MB_(99.43%) +// #Easy #Math #Udemy_Integers #Top_Interview_150_Math +// #2025_03_22_Time_3_ms_(99.14%)_Space_64.18_MB_(50.40%) function isPalindrome(x: number): boolean { if (x < 0) { diff --git a/src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts b/src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts index fed1d99..05cfa01 100644 --- a/src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts +++ b/src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts @@ -1,6 +1,5 @@ -// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion -// #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n) -// #2023_08_25_Time_69_ms_(92.65%)_Space_45.9_MB_(50.61%) +// #Hard #Top_Interview_Questions #String #Dynamic_Programming #Recursion #Udemy_Dynamic_Programming +// #Big_O_Time_O(m*n)_Space_O(m*n) #2025_03_22_Time_5_ms_(90.44%)_Space_59.10_MB_(22.68%) function isMatch(s: string, p: string): boolean { // NOSONAR const result = new Array(s.length + 1) diff --git a/src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts b/src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts index f4c6efb..29a6a7a 100644 --- a/src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts +++ b/src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers -// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1) -// #2023_08_28_Time_57_ms_(98.23%)_Space_50.9_MB_(84.15%) +// #LeetCode_75_Two_Pointers #Algorithm_II_Day_4_Two_Pointers #Top_Interview_150_Two_Pointers +// #Big_O_Time_O(n)_Space_O(1) #2025_03_22_Time_2_ms_(80.13%)_Space_65.63_MB_(10.65%) function maxArea(height: number[]): number { let maxArea = -1 diff --git a/src/main/ts/g0001_0100/s0012_integer_to_roman/readme.md b/src/main/ts/g0001_0100/s0012_integer_to_roman/readme.md new file mode 100644 index 0000000..456e0cf --- /dev/null +++ b/src/main/ts/g0001_0100/s0012_integer_to_roman/readme.md @@ -0,0 +1,62 @@ +12\. Integer to Roman + +Medium + +Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`. + + Symbol Value + I 1 + V 5 + X 10 + L 50 + C 100 + D 500 + M 1000 + +For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`. + +Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used: + +* `I` can be placed before `V` (5) and `X` (10) to make 4 and 9. +* `X` can be placed before `L` (50) and `C` (100) to make 40 and 90. +* `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900. + +Given an integer, convert it to a roman numeral. + +**Example 1:** + +**Input:** num = 3 + +**Output:** "III" + +**Example 2:** + +**Input:** num = 4 + +**Output:** "IV" + +**Example 3:** + +**Input:** num = 9 + +**Output:** "IX" + +**Example 4:** + +**Input:** num = 58 + +**Output:** "LVIII" + +**Explanation:** L = 50, V = 5, III = 3. + +**Example 5:** + +**Input:** num = 1994 + +**Output:** "MCMXCIV" + +**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4. + +**Constraints:** + +* `1 <= num <= 3999` diff --git a/src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts b/src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts new file mode 100644 index 0000000..b6c28de --- /dev/null +++ b/src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts @@ -0,0 +1,20 @@ +// #Medium #String #Hash_Table #Math #Top_Interview_150_Array/String +// #2025_03_31_Time_3_ms_(93.02%)_Space_61.86_MB_(54.05%) + +function intToRoman(num: number): string { + const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] + const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'] + let result = '' + let i = 0 + while (num > 0) { + if (num >= values[i]) { + result += symbols[i] + num -= values[i] + } else { + i++ + } + } + return result +} + +export { intToRoman } diff --git a/src/main/ts/g0001_0100/s0013_roman_to_integer/readme.md b/src/main/ts/g0001_0100/s0013_roman_to_integer/readme.md new file mode 100644 index 0000000..14bbde8 --- /dev/null +++ b/src/main/ts/g0001_0100/s0013_roman_to_integer/readme.md @@ -0,0 +1,64 @@ +13\. Roman to Integer + +Easy + +Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`. + + Symbol Value + I 1 + V 5 + X 10 + L 50 + C 100 + D 500 + M 1000 + +For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`. + +Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used: + +* `I` can be placed before `V` (5) and `X` (10) to make 4 and 9. +* `X` can be placed before `L` (50) and `C` (100) to make 40 and 90. +* `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900. + +Given a roman numeral, convert it to an integer. + +**Example 1:** + +**Input:** s = "III" + +**Output:** 3 + +**Example 2:** + +**Input:** s = "IV" + +**Output:** 4 + +**Example 3:** + +**Input:** s = "IX" + +**Output:** 9 + +**Example 4:** + +**Input:** s = "LVIII" + +**Output:** 58 + +**Explanation:** L = 50, V= 5, III = 3. + +**Example 5:** + +**Input:** s = "MCMXCIV" + +**Output:** 1994 + +**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4. + +**Constraints:** + +* `1 <= s.length <= 15` +* `s` contains only the characters `('I', 'V', 'X', 'L', 'C', 'D', 'M')`. +* It is **guaranteed** that `s` is a valid roman numeral in the range `[1, 3999]`. diff --git a/src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts b/src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts new file mode 100644 index 0000000..827a80d --- /dev/null +++ b/src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts @@ -0,0 +1,49 @@ +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Math +// #Top_Interview_150_Array/String #2025_03_31_Time_3_ms_(94.58%)_Space_61.52_MB_(51.93%) + +function romanToInt(s: string): number { + let x = 0 + let y: string + for (let i = 0; i < s.length; i++) { + y = s.charAt(i) + switch (y) { + case 'I': + x = getX(s, x, i, 1, 'V', 'X') + break + case 'V': + x += 5 + break + case 'X': + x = getX(s, x, i, 10, 'L', 'C') + break + case 'L': + x += 50 + break + case 'C': + x = getX(s, x, i, 100, 'D', 'M') + break + case 'D': + x += 500 + break + case 'M': + x += 1000 + break + default: + break + } + } + return x +} + +function getX(s: string, x: number, i: number, i2: number, v: string, x2: string): number { + if (i + 1 === s.length) { + x += i2 + } else if (s.charAt(i + 1) === v || s.charAt(i + 1) === x2) { + x -= i2 + } else { + x += i2 + } + return x +} + +export { romanToInt } diff --git a/src/main/ts/g0001_0100/s0014_longest_common_prefix/readme.md b/src/main/ts/g0001_0100/s0014_longest_common_prefix/readme.md new file mode 100644 index 0000000..3f23b8c --- /dev/null +++ b/src/main/ts/g0001_0100/s0014_longest_common_prefix/readme.md @@ -0,0 +1,27 @@ +14\. Longest Common Prefix + +Easy + +Write a function to find the longest common prefix string amongst an array of strings. + +If there is no common prefix, return an empty string `""`. + +**Example 1:** + +**Input:** strs = ["flower","flow","flight"] + +**Output:** "fl" + +**Example 2:** + +**Input:** strs = ["dog","racecar","car"] + +**Output:** "" + +**Explanation:** There is no common prefix among the input strings. + +**Constraints:** + +* `1 <= strs.length <= 200` +* `0 <= strs[i].length <= 200` +* `strs[i]` consists of only lower-case English letters. \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts b/src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts new file mode 100644 index 0000000..4747f5b --- /dev/null +++ b/src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts @@ -0,0 +1,29 @@ +// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Level_2_Day_2_String +// #Udemy_Strings #Top_Interview_150_Array/String +// #2025_03_31_Time_0_ms_(100.00%)_Space_54.23_MB_(65.24%) + +function longestCommonPrefix(strs: string[]): string { + if (strs.length < 1) { + return '' + } + if (strs.length === 1) { + return strs[0] + } + let temp = strs[0] + let i = 1 + let cur: string + while (temp.length > 0 && i < strs.length) { + if (temp.length > strs[i].length) { + temp = temp.substring(0, strs[i].length) + } + cur = strs[i].substring(0, temp.length) + if (cur !== temp) { + temp = temp.substring(0, temp.length - 1) + } else { + i++ + } + } + return temp +} + +export { longestCommonPrefix } diff --git a/src/main/ts/g0001_0100/s0015_3sum/solution.ts b/src/main/ts/g0001_0100/s0015_3sum/solution.ts index 67fdc8b..e4ad9bd 100644 --- a/src/main/ts/g0001_0100/s0015_3sum/solution.ts +++ b/src/main/ts/g0001_0100/s0015_3sum/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n*log(n))_Space_O(n^2) #2023_08_28_Time_148_ms_(92.62%)_Space_59.1_MB_(70.24%) +// #Top_Interview_150_Two_Pointers #Big_O_Time_O(n*log(n))_Space_O(n^2) +// #2025_03_22_Time_30_ms_(91.56%)_Space_74.61_MB_(11.14%) function threeSum(nums: number[]): number[][] { //NOSONAR nums.sort((a, b) => a - b) diff --git a/src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts b/src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts index fea016e..7bf7035 100644 --- a/src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts +++ b/src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts @@ -1,6 +1,7 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking -// #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(4^n)_Space_O(n) #2023_08_28_Time_52_ms_(79.11%)_Space_43.7_MB_(37.41%) +// #LeetCode_75_Backtracking #Algorithm_II_Day_11_Recursion_Backtracking +// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(4^n)_Space_O(n) +// #2025_03_22_Time_0_ms_(100.00%)_Space_56.27_MB_(8.55%) function letterCombinations(digits: string): string[] { if (digits.length === 0) { diff --git a/src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts b/src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts index b470822..ce4f363 100644 --- a/src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts +++ b/src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts @@ -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 #Big_O_Time_O(L)_Space_O(L) -// #2023_08_28_Time_54_ms_(87.87%)_Space_44.7_MB_(49.30%) +// #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_03_22_Time_0_ms_(100.00%)_Space_58.00_MB_(13.12%) import { ListNode } from '../../com_github_leetcode/listnode' diff --git a/src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts b/src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts index 4f06406..cdf4b2a 100644 --- a/src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts +++ b/src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts @@ -1,6 +1,6 @@ // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack -// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Big_O_Time_O(n)_Space_O(n) -// #2023_08_28_Time_50_ms_(95.90%)_Space_43.5_MB_(83.27%) +// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Top_Interview_150_Stack +// #Big_O_Time_O(n)_Space_O(n) #2025_03_22_Time_1_ms_(86.85%)_Space_59.18_MB_(9.27%) function isValid(s: string): boolean { const stack: string[] = [] diff --git a/src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts b/src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts index 284ba47..d2df408 100644 --- a/src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts +++ b/src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts @@ -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 #Big_O_Time_O(m+n)_Space_O(m+n) -// #2023_08_29_Time_59_ms_(86.77%)_Space_44_MB_(98.03%) +// #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_03_22_Time_1_ms_(51.21%)_Space_59.28_MB_(6.60%) import { ListNode } from '../../com_github_leetcode/listnode' diff --git a/src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts b/src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts index 9db8687..672ffd6 100644 --- a/src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts +++ b/src/main/ts/g0001_0100/s0022_generate_parentheses/solution.ts @@ -1,6 +1,7 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming // #Backtracking #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(2^n)_Space_O(n) #2023_08_29_Time_60_ms_(62.03%)_Space_45.6_MB_(21.59%) +// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n) +// #2025_03_22_Time_1_ms_(72.82%)_Space_56.97_MB_(44.53%) function generateParenthesis(n: number): string[] { const sb: string[] = [] diff --git a/src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts b/src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts index b94cc7a..49e2d65 100644 --- a/src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts +++ b/src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts @@ -1,10 +1,10 @@ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List -// #Divide_and_Conquer #Merge_Sort #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) -// #2023_10_09_Time_76_ms_(94.52%)_Space_47.9_MB_(84.35%) +// #Divide_and_Conquer #Merge_Sort #Top_Interview_150_Divide_and_Conquer +// #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) #2025_03_22_Time_4_ms_(97.65%)_Space_64.08_MB_(30.06%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number diff --git a/src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts b/src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts index 71f3454..959f448 100644 --- a/src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts +++ b/src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts @@ -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) -// #2023_08_29_Time_59_ms_(62.67%)_Space_44.7_MB_(26.03%) +// #2025_03_22_Time_0_ms_(100.00%)_Space_56.52_MB_(6.71%) /** * Definition for singly-linked list. diff --git a/src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts b/src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts index 9f78202..79a44ad 100644 --- a/src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts +++ b/src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts @@ -1,6 +1,6 @@ // #Hard #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_13_Linked_List -// #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(k) -// #2023_08_29_Time_74_ms_(66.83%)_Space_46.1_MB_(94.47%) +// #Udemy_Linked_List #Top_Interview_150_Linked_List #Big_O_Time_O(n)_Space_O(k) +// #2025_03_22_Time_0_ms_(100.00%)_Space_60.66_MB_(27.50%) /** * Definition for singly-linked list. diff --git a/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md b/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md new file mode 100644 index 0000000..b4e776e --- /dev/null +++ b/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md @@ -0,0 +1,49 @@ +26\. Remove Duplicates from Sorted Array + +Easy + +Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears only **once**. The **relative order** of the elements should be kept the **same**. + +Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements. + +Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`. + +Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory. + +**Custom Judge:** + +The judge will test your solution with the following code: + + int[] nums = [...]; // Input array + int[] expectedNums = [...]; // The expected answer with correct length + + int k = removeDuplicates(nums); // Calls your implementation + + assert k == expectedNums.length; + for (int i = 0; i < k; i++) { + assert nums[i] == expectedNums[i]; + } + +If all assertions pass, then your solution will be **accepted**. + +**Example 1:** + +**Input:** nums = [1,1,2] + +**Output:** 2, nums = [1,2,\_] + +**Explanation:** Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Example 2:** + +**Input:** nums = [0,0,1,1,1,2,2,3,3,4] + +**Output:** 5, nums = [0,1,2,3,4,\_,\_,\_,\_,\_] + +**Explanation:** Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Constraints:** + +* 0 <= nums.length <= 3 * 104 +* `-100 <= nums[i] <= 100` +* `nums` is sorted in **non-decreasing** order. \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts b/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts new file mode 100644 index 0000000..334a8b6 --- /dev/null +++ b/src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts @@ -0,0 +1,21 @@ +// #Easy #Top_Interview_Questions #Array #Two_Pointers #Udemy_Two_Pointers +// #Top_Interview_150_Array/String #2025_03_31_Time_0_ms_(100.00%)_Space_58.42_MB_(57.44%) + +function removeDuplicates(nums: number[]): number { + let n = nums.length + let i = 0 + let j = 1 + if (n <= 1) { + return n + } + while (j <= n - 1) { + if (nums[i] !== nums[j]) { + nums[i + 1] = nums[j] + i++ + } + j++ + } + return i + 1 +} + +export { removeDuplicates } diff --git a/src/main/ts/g0001_0100/s0027_remove_element/readme.md b/src/main/ts/g0001_0100/s0027_remove_element/readme.md new file mode 100644 index 0000000..027b058 --- /dev/null +++ b/src/main/ts/g0001_0100/s0027_remove_element/readme.md @@ -0,0 +1,52 @@ +27\. Remove Element + +Easy + +Given an integer array `nums` and an integer `val`, remove all occurrences of `val` in `nums` [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm). The relative order of the elements may be changed. + +Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements. + +Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`. + +Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory. + +**Custom Judge:** + +The judge will test your solution with the following code: + + int[] nums = [...]; // Input array + int val = ...; // Value to remove + int[] expectedNums = [...]; // The expected answer with correct length. + // It is sorted with no values equaling val. + + int k = removeElement(nums, val); // Calls your implementation + + assert k == expectedNums.length; + sort(nums, 0, k); // Sort the first k elements of nums + for (int i = 0; i < actualLength; i++) { + assert nums[i] == expectedNums[i]; + } + +If all assertions pass, then your solution will be **accepted**. + +**Example 1:** + +**Input:** nums = [3,2,2,3], val = 3 + +**Output:** 2, nums = [2,2,\_,\_] + +**Explanation:** Your function should return k = 2, with the first two elements of nums being 2. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Example 2:** + +**Input:** nums = [0,1,2,2,3,0,4,2], val = 2 + +**Output:** 5, nums = [0,1,4,0,3,\_,\_,\_] + +**Explanation:** Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4. Note that the five elements can be returned in any order. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Constraints:** + +* `0 <= nums.length <= 100` +* `0 <= nums[i] <= 50` +* `0 <= val <= 100` \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0027_remove_element/solution.ts b/src/main/ts/g0001_0100/s0027_remove_element/solution.ts new file mode 100644 index 0000000..a6a348b --- /dev/null +++ b/src/main/ts/g0001_0100/s0027_remove_element/solution.ts @@ -0,0 +1,34 @@ +// #Easy #Array #Two_Pointers #Top_Interview_150_Array/String +// #2025_03_31_Time_0_ms_(100.00%)_Space_56.09_MB_(20.94%) + +function removeElement(nums: number[], val: number): number { + if (!nums || nums.length === 0) { + return 0 + } + let len = nums.length + let j = len - 1 + let occurTimes = 0 + for (let i = 0; i < len; i++) { + if (nums[i] === val) { + occurTimes++ + if (j === i) { + return len - occurTimes + } + while (nums[j] === val) { + j-- + occurTimes++ + if (j === i) { + return len - occurTimes + } + } + nums[i] = nums[j] + j-- + } + if (i === j) { + return len - occurTimes + } + } + return len - occurTimes +} + +export { removeElement } diff --git a/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md b/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md new file mode 100644 index 0000000..098bd24 --- /dev/null +++ b/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md @@ -0,0 +1,36 @@ +28\. Implement strStr() + +Easy + +Implement [strStr()](http://www.cplusplus.com/reference/cstring/strstr/). + +Return the index of the first occurrence of needle in haystack, or `-1` if `needle` is not part of `haystack`. + +**Clarification:** + +What should we return when `needle` is an empty string? This is a great question to ask during an interview. + +For the purpose of this problem, we will return 0 when `needle` is an empty string. This is consistent to C's [strstr()](http://www.cplusplus.com/reference/cstring/strstr/) and Java's [indexOf()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)). + +**Example 1:** + +**Input:** haystack = "hello", needle = "ll" + +**Output:** 2 + +**Example 2:** + +**Input:** haystack = "aaaaa", needle = "bba" + +**Output:** -1 + +**Example 3:** + +**Input:** haystack = "", needle = "" + +**Output:** 0 + +**Constraints:** + +* 0 <= haystack.length, needle.length <= 5 * 104 +* `haystack` and `needle` consist of only lower-case English characters. \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts b/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts new file mode 100644 index 0000000..83414ba --- /dev/null +++ b/src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts @@ -0,0 +1,19 @@ +// #Easy #Top_Interview_Questions #String #Two_Pointers #String_Matching +// #Programming_Skills_II_Day_1 #Top_Interview_150_Array/String +// #2025_03_31_Time_0_ms_(100.00%)_Space_55.44_MB_(48.55%) + +function strStr(haystack: string, needle: string): number { + if (needle.length === 0) { + return 0 + } + let m = haystack.length + let n = needle.length + for (let start = 0; start <= m - n; start++) { + if (haystack.substring(start, start + n) === needle) { + return start + } + } + return -1 +} + +export { strStr } diff --git a/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md b/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md new file mode 100644 index 0000000..e4075f4 --- /dev/null +++ b/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md @@ -0,0 +1,35 @@ +30\. Substring with Concatenation of All Words + +Hard + +You are given a string `s` and an array of strings `words` of **the same length**. Return all starting indices of substring(s) in `s` that is a concatenation of each word in `words` **exactly once**, **in any order**, and **without any intervening characters**. + +You can return the answer in **any order**. + +**Example 1:** + +**Input:** s = "barfoothefoobarman", words = ["foo","bar"] + +**Output:** [0,9] + +**Explanation:** Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively. The output order does not matter, returning [9,0] is fine too. + +**Example 2:** + +**Input:** s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"] + +**Output:** [] + +**Example 3:** + +**Input:** s = "barfoofoobarthefoobarman", words = ["bar","foo","the"] + +**Output:** [6,9,12] + +**Constraints:** + +* 1 <= s.length <= 104 +* `s` consists of lower-case English letters. +* `1 <= words.length <= 5000` +* `1 <= words[i].length <= 30` +* `words[i]` consists of lower-case English letters. \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts b/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts new file mode 100644 index 0000000..069a034 --- /dev/null +++ b/src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts @@ -0,0 +1,42 @@ +// #Hard #String #Hash_Table #Sliding_Window #Top_Interview_150_Sliding_Window +// #2025_04_01_Time_13_ms_(97.44%)_Space_63.70_MB_(46.03%) + +function findSubstring(s: string, words: string[]): number[] { + let ans: number[] = [] + let n1 = words[0].length + let n2 = s.length + let map1 = new Map() + for (let ch of words) { + map1.set(ch, (map1.get(ch) ?? 0) + 1) + } + for (let i = 0; i < n1; i++) { + let left = i + let j = i + let c = 0 + let map2 = new Map() + while (j + n1 <= n2) { + let word1 = s.substring(j, j + n1) + j += n1 + if (map1.has(word1)) { + map2.set(word1, (map2.get(word1) ?? 0) + 1) + c++ + while ((map2.get(word1) ?? 0) > (map1.get(word1) ?? 0)) { + let word2 = s.substring(left, left + n1) + map2.set(word2, (map2.get(word2) ?? 0) - 1) + left += n1 + c-- + } + if (c === words.length) { + ans.push(left) + } + } else { + map2.clear() + c = 0 + left = j + } + } + } + return ans +} + +export { findSubstring } diff --git a/src/main/ts/g0001_0100/s0031_next_permutation/solution.ts b/src/main/ts/g0001_0100/s0031_next_permutation/solution.ts index 966dff2..3723344 100644 --- a/src/main/ts/g0001_0100/s0031_next_permutation/solution.ts +++ b/src/main/ts/g0001_0100/s0031_next_permutation/solution.ts @@ -1,20 +1,19 @@ // #Medium #Top_100_Liked_Questions #Array #Two_Pointers #Big_O_Time_O(n)_Space_O(1) -// #2023_09_26_Time_47_ms_(99.30%)_Space_45_MB_(20.98%) +// #2025_03_22_Time_0_ms_(100.00%)_Space_58.80_MB_(7.83%) /* Do not return anything, modify nums in-place instead. */ function nextPermutation(nums: number[]): void { let swapperIndex: number | null = null - for (let ind = nums.length - 1; ind >= 0 && swapperIndex == null; ind--) { if (nums[ind] > nums[ind - 1]) { swapperIndex = ind - 1 } } - - if (swapperIndex == null) nums.sort((a, b) => a - b) - else { + if (swapperIndex == null) { + nums.sort((a, b) => a - b) + } else { nums.splice(swapperIndex + 1, nums.length, ...nums.slice(swapperIndex + 1, nums.length).sort((a, b) => a - b)) let indToBringForward = swapperIndex + 1 while (nums[indToBringForward] <= nums[swapperIndex]) ++indToBringForward diff --git a/src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts b/src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts index 69b2a24..d210153 100644 --- a/src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts +++ b/src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts @@ -1,5 +1,5 @@ // #Hard #Top_100_Liked_Questions #String #Dynamic_Programming #Stack #Big_O_Time_O(n)_Space_O(1) -// #2023_09_26_Time_56_ms_(89.31%)_Space_43.9_MB_(100.00%) +// #2025_03_22_Time_3_ms_(71.05%)_Space_58.66_MB_(24.21%) function longestValidParentheses(s: string): number { let open = 0 diff --git a/src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts b/src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts index 4ec9c9c..d2234e1 100644 --- a/src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts +++ b/src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts @@ -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 #Big_O_Time_O(log_n)_Space_O(1) -// #2023_09_27_Time_43_ms_(98.54%)_Space_44.3_MB_(31.85%) +// #Udemy_Binary_Search #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) +// #2025_03_22_Time_0_ms_(100.00%)_Space_56.20_MB_(19.74%) function search(nums: number[], target: number): number { //NOSONAR let lowEnd: number = 0 diff --git a/src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts b/src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts index 32557da..49c99a2 100644 --- a/src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts +++ b/src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.ts @@ -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 #Big_O_Time_O(log_n)_Space_O(1) -// #2023_09_27_Time_45_ms_(98.05%)_Space_44.5_MB_(54.86%) +// #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_03_22_Time_0_ms_(100.00%)_Space_57.18_MB_(12.18%) function searchRange(nums: number[], target: number): number[] { //NOSONAR let first = -1 @@ -9,7 +9,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR let left2 = left1 let right1 = nums.length - 1 let right2 = right1 - while (left1 <= right1 || left2 <= right2) { if (left1 <= right1) { let mid1 = Math.floor((left1 + right1) / 2) @@ -22,7 +21,6 @@ function searchRange(nums: number[], target: number): number[] { //NOSONAR right1 = mid1 - 1 } } - if (left2 <= right2) { let mid2 = Math.floor((left2 + right2) / 2) if (nums[mid2] == target) { diff --git a/src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts b/src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts index 7aee8a4..f1ec235 100644 --- a/src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts +++ b/src/main/ts/g0001_0100/s0035_search_insert_position/solution.ts @@ -1,6 +1,6 @@ // #Easy #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_I_Day_1_Binary_Search -// #Binary_Search_I_Day_2 #Big_O_Time_O(log_n)_Space_O(1) -// #2023_09_27_Time_51_ms_(80.95%)_Space_44.6_MB_(16.67%) +// #Binary_Search_I_Day_2 #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1) +// #2025_03_22_Time_0_ms_(100.00%)_Space_56.30_MB_(12.51%) function searchInsert(nums: number[], target: number): number { let left = 0 diff --git a/src/main/ts/g0001_0100/s0036_valid_sudoku/readme.md b/src/main/ts/g0001_0100/s0036_valid_sudoku/readme.md new file mode 100644 index 0000000..db58bb7 --- /dev/null +++ b/src/main/ts/g0001_0100/s0036_valid_sudoku/readme.md @@ -0,0 +1,58 @@ +36\. Valid Sudoku + +Medium + +Determine if a `9 x 9` Sudoku board is valid. Only the filled cells need to be validated **according to the following rules**: + +1. Each row must contain the digits `1-9` without repetition. +2. Each column must contain the digits `1-9` without repetition. +3. Each of the nine `3 x 3` sub-boxes of the grid must contain the digits `1-9` without repetition. + +**Note:** + +* A Sudoku board (partially filled) could be valid but is not necessarily solvable. +* Only the filled cells need to be validated according to the mentioned rules. + +**Example 1:** + +![](https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/250px-Sudoku-by-L2G-20050714.svg.png) + +**Input:** + + board = + [["5","3",".",".","7",".",".",".","."] + ,["6",".",".","1","9","5",".",".","."] + ,[".","9","8",".",".",".",".","6","."] + ,["8",".",".",".","6",".",".",".","3"] + ,["4",".",".","8",".","3",".",".","1"] + ,["7",".",".",".","2",".",".",".","6"] + ,[".","6",".",".",".",".","2","8","."] + ,[".",".",".","4","1","9",".",".","5"] + ,[".",".",".",".","8",".",".","7","9"]] + +**Output:** true + +**Example 2:** + +**Input:** + + board = + [["8","3",".",".","7",".",".",".","."] + ,["6",".",".","1","9","5",".",".","."] + ,[".","9","8",".",".",".",".","6","."] + ,["8",".",".",".","6",".",".",".","3"] + ,["4",".",".","8",".","3",".",".","1"] + ,["7",".",".",".","2",".",".",".","6"] + ,[".","6",".",".",".",".","2","8","."] + ,[".",".",".","4","1","9",".",".","5"] + ,[".",".",".",".","8",".",".","7","9"]] + +**Output:** false + +**Explanation:** Same as Example 1, except with the **5** in the top left corner being modified to **8**. Since there are two 8's in the top left 3x3 sub-box, it is invalid. + +**Constraints:** + +* `board.length == 9` +* `board[i].length == 9` +* `board[i][j]` is a digit `1-9` or `'.'`. \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts b/src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts new file mode 100644 index 0000000..2ca47a4 --- /dev/null +++ b/src/main/ts/g0001_0100/s0036_valid_sudoku/solution.ts @@ -0,0 +1,26 @@ +// #Medium #Top_Interview_Questions #Array #Hash_Table #Matrix #Data_Structure_I_Day_5_Array +// #Top_Interview_150_Matrix #2025_04_01_Time_1_ms_(99.60%)_Space_58.94_MB_(52.85%) + +function isValidSudoku(board: string[][]): boolean { + let rowSet: number[] = new Array(9).fill(0) + let colSet: number[] = new Array(9).fill(0) + let boxSet: number[] = new Array(9).fill(0) + for (let i = 0; i < 9; i++) { + for (let j = 0; j < 9; j++) { + if (board[i][j] === '.') { + continue + } + let val = board[i][j].charCodeAt(0) - '0'.charCodeAt(0) + let boxIndex = Math.floor(i / 3) * 3 + Math.floor(j / 3) + if (rowSet[i] & (1 << val) || colSet[j] & (1 << val) || boxSet[boxIndex] & (1 << val)) { + return false + } + rowSet[i] |= 1 << val + colSet[j] |= 1 << val + boxSet[boxIndex] |= 1 << val + } + } + return true +} + +export { isValidSudoku } diff --git a/src/main/ts/g0001_0100/s0039_combination_sum/solution.ts b/src/main/ts/g0001_0100/s0039_combination_sum/solution.ts index fab12ba..c518fdf 100644 --- a/src/main/ts/g0001_0100/s0039_combination_sum/solution.ts +++ b/src/main/ts/g0001_0100/s0039_combination_sum/solution.ts @@ -1,11 +1,11 @@ // #Medium #Top_100_Liked_Questions #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking // #Level_2_Day_20_Brute_Force/Backtracking #Udemy_Backtracking/Recursion -// #Big_O_Time_O(2^n)_Space_O(n+2^n) #2023_09_29_Time_65_ms_(86.86%)_Space_45.8_MB_(75.98%) +// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n+2^n) +// #2025_03_22_Time_1_ms_(98.17%)_Space_61.61_MB_(21.40%) function combinationSum(candidates: number[], target: number): number[][] { const result: number[][] = [] const path: number[] = [] - const comFunct = (index: number, sum: number) => { if (sum === target) { result.push([...path]) diff --git a/src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts b/src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts index c2965b2..2b742a7 100644 --- a/src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts +++ b/src/main/ts/g0001_0100/s0041_first_missing_positive/solution.ts @@ -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) #2023_09_29_Time_55_ms_(98.51%)_Space_49.8_MB_(60.20%) +// #Big_O_Time_O(n)_Space_O(n) #2025_03_23_Time_1_ms_(99.11%)_Space_65.96_MB_(40.18%) function firstMissingPositive(nums: number[]): number { let i = 0 diff --git a/src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts b/src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts index c65df74..5f5e5c0 100644 --- a/src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts +++ b/src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n)_Space_O(1) #2023_09_30_Time_46_ms_(99.52%)_Space_44.4_MB_(97.58%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_57.78_MB_(55.13%) function trap(height: number[]): number { let result = 0 diff --git a/src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts b/src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts index ca06360..ba92f55 100644 --- a/src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts +++ b/src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts @@ -1,41 +1,24 @@ // #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Greedy // #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4 -// #Big_O_Time_O(n)_Space_O(1) #2023_09_30_Time_50_ms_(95.93%)_Space_44.9_MB_(65.88%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2025_03_23_Time_1_ms_(84.27%)_Space_58.46_MB_(28.93%) -function jump(nums: number[]): number { //NOSONAR - let minJmp = new Array(nums.length) - if (nums.length === 1) return 0 - let prevIndex = 0 - minJmp[prevIndex] = 0 - while (prevIndex < nums.length - 1) { - let nextMaxJmpTo = nums[prevIndex] + prevIndex - let prevIndexJmp = minJmp[prevIndex] - - let farthestJumpVal = -1 - let farthestJumpIndex = -1 - for (let i = nextMaxJmpTo; ; i--) { - if (i >= nums.length) { - continue - } - if (i === nums.length - 1) { - return prevIndexJmp + 1 - } - if (minJmp[i] != undefined) { +function jump(nums: number[]): number { + let minJump = 0, + farthest = 0, + currentEnd = 0 + for (let i = 0; i < nums.length - 1; i++) { + farthest = Math.max(farthest, i + nums[i]) + // If we've reached the end of the current jump range + if (i === currentEnd) { + minJump++ + currentEnd = farthest + if (currentEnd >= nums.length - 1) { break } - minJmp[i] = prevIndexJmp + 1 - let curmaxTo = nums[i] + i - if (farthestJumpVal < curmaxTo) { - farthestJumpVal = curmaxTo - farthestJumpIndex = i - } - } - if (farthestJumpIndex === -1) { - return -1 } - prevIndex = farthestJumpIndex } - return minJmp[nums.length - 1] + return minJump } export { jump } diff --git a/src/main/ts/g0001_0100/s0046_permutations/solution.ts b/src/main/ts/g0001_0100/s0046_permutations/solution.ts index 2a97397..2cef51a 100644 --- a/src/main/ts/g0001_0100/s0046_permutations/solution.ts +++ b/src/main/ts/g0001_0100/s0046_permutations/solution.ts @@ -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 #Big_O_Time_O(n*n!)_Space_O(n+n!) -// #2023_09_30_Time_56_ms_(96.26%)_Space_45.7_MB_(55.35%) +// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(n*n!)_Space_O(n+n!) +// #2025_03_23_Time_1_ms_(84.44%)_Space_60.84_MB_(26.93%) function permute(nums: number[]): number[][] { const result: number[][] = [] diff --git a/src/main/ts/g0001_0100/s0048_rotate_image/solution.ts b/src/main/ts/g0001_0100/s0048_rotate_image/solution.ts index 8309b39..7f7feac 100644 --- a/src/main/ts/g0001_0100/s0048_rotate_image/solution.ts +++ b/src/main/ts/g0001_0100/s0048_rotate_image/solution.ts @@ -1,6 +1,7 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Matrix // #Data_Structure_II_Day_3_Array #Programming_Skills_II_Day_7 #Udemy_2D_Arrays/Matrix -// #Big_O_Time_O(n^2)_Space_O(1) #2023_09_30_Time_45_ms_(95.31%)_Space_44.4_MB_(48.24%) +// #Top_Interview_150_Matrix #Big_O_Time_O(n^2)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_57.37_MB_(17.79%) /* Do not return anything, modify matrix in-place instead. diff --git a/src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts b/src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts index 0e7e54d..8df43fb 100644 --- a/src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts +++ b/src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n*k_log_k)_Space_O(n) #2023_09_30_Time_93_ms_(97.29%)_Space_52_MB_(99.08%) +// #Top_Interview_150_Hashmap #Big_O_Time_O(n*k_log_k)_Space_O(n) +// #2025_03_23_Time_27_ms_(78.99%)_Space_68.93_MB_(28.40%) function groupAnagrams(strs: string[]): string[][] { if (strs.length === 1) return [strs] diff --git a/src/main/ts/g0001_0100/s0050_powx_n/readme.md b/src/main/ts/g0001_0100/s0050_powx_n/readme.md new file mode 100644 index 0000000..3e93a2f --- /dev/null +++ b/src/main/ts/g0001_0100/s0050_powx_n/readme.md @@ -0,0 +1,31 @@ +50\. Pow(x, n) + +Medium + +Implement [pow(x, n)](http://www.cplusplus.com/reference/valarray/pow/), which calculates `x` raised to the power `n` (i.e., xn). + +**Example 1:** + +**Input:** x = 2.00000, n = 10 + +**Output:** 1024.00000 + +**Example 2:** + +**Input:** x = 2.10000, n = 3 + +**Output:** 9.26100 + +**Example 3:** + +**Input:** x = 2.00000, n = -2 + +**Output:** 0.25000 + +**Explanation:** 2\-2 = 1/22 = 1/4 = 0.25 + +**Constraints:** + +* `-100.0 < x < 100.0` +* -231 <= n <= 231-1 +* -104 <= xn <= 104 \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0050_powx_n/solution.ts b/src/main/ts/g0001_0100/s0050_powx_n/solution.ts new file mode 100644 index 0000000..ec47d5f --- /dev/null +++ b/src/main/ts/g0001_0100/s0050_powx_n/solution.ts @@ -0,0 +1,22 @@ +// #Medium #Top_Interview_Questions #Math #Recursion #Udemy_Integers #Top_Interview_150_Math +// #2025_04_01_Time_0_ms_(100.00%)_Space_57.31_MB_(7.22%) + +function myPow(x: number, n: number): number { + let nn = BigInt(n) + let res = 1.0 + if (n < 0) { + nn = -nn + } + while (nn > 0) { + if (nn % 2n === 1n) { + nn-- + res *= x + } else { + x *= x + nn /= 2n + } + } + return n < 0 ? 1.0 / res : res +} + +export { myPow } diff --git a/src/main/ts/g0001_0100/s0051_n_queens/solution.ts b/src/main/ts/g0001_0100/s0051_n_queens/solution.ts index 1d423f3..e89d7fe 100644 --- a/src/main/ts/g0001_0100/s0051_n_queens/solution.ts +++ b/src/main/ts/g0001_0100/s0051_n_queens/solution.ts @@ -1,5 +1,5 @@ // #Hard #Top_100_Liked_Questions #Array #Backtracking #Big_O_Time_O(N!)_Space_O(N) -// #2023_09_30_Time_57_ms_(93.84%)_Space_45_MB_(83.56%) +// #2025_03_23_Time_6_ms_(95.85%)_Space_59.90_MB_(33.61%) function solveNQueens(n: number): string[][] { const result: string[][] = [] diff --git a/src/main/ts/g0001_0100/s0052_n_queens_ii/readme.md b/src/main/ts/g0001_0100/s0052_n_queens_ii/readme.md new file mode 100644 index 0000000..946096c --- /dev/null +++ b/src/main/ts/g0001_0100/s0052_n_queens_ii/readme.md @@ -0,0 +1,27 @@ +52\. N-Queens II + +Hard + +The **n-queens** puzzle is the problem of placing `n` queens on an `n x n` chessboard such that no two queens attack each other. + +Given an integer `n`, return _the number of distinct solutions to the **n-queens puzzle**_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/13/queens.jpg) + +**Input:** n = 4 + +**Output:** 2 + +**Explanation:** There are two distinct solutions to the 4-queens puzzle as shown. + +**Example 2:** + +**Input:** n = 1 + +**Output:** 1 + +**Constraints:** + +* `1 <= n <= 9` \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts b/src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts new file mode 100644 index 0000000..e0ff9b0 --- /dev/null +++ b/src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts @@ -0,0 +1,22 @@ +// #Hard #Backtracking #Top_Interview_150_Backtracking +// #2025_04_01_Time_1_ms_(96.89%)_Space_56.94_MB_(52.17%) + +function totalNQueens(n: number): number { + function solve(r: number, cols: boolean[], diag: boolean[], antiDiag: boolean[]): number { + if (r === n) { + return 1 + } + let count = 0 + for (let c = 0; c < n; c++) { + if (!cols[c] && !diag[r + c] && !antiDiag[r - c + n - 1]) { + cols[c] = diag[r + c] = antiDiag[r - c + n - 1] = true + count += solve(r + 1, cols, diag, antiDiag) + cols[c] = diag[r + c] = antiDiag[r - c + n - 1] = false + } + } + return count + } + return solve(0, new Array(n).fill(false), new Array(2 * n - 1).fill(false), new Array(2 * n - 1).fill(false)) +} + +export { totalNQueens } diff --git a/src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts b/src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts index 7e5d91d..1ab9566 100644 --- a/src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts +++ b/src/main/ts/g0001_0100/s0053_maximum_subarray/solution.ts @@ -1,7 +1,7 @@ -// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming +// #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 #Big_O_Time_O(n)_Space_O(1) -// #2023_09_30_Time_66_ms_(90.36%)_Space_51.9_MB_(80.92%) +// #Udemy_Famous_Algorithm #Top_Interview_150_Kadane's_Algorithm #Big_O_Time_O(n)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_65.50_MB_(44.96%) function maxSubArray(nums: number[]): number { let curSum: number = nums[0] diff --git a/src/main/ts/g0001_0100/s0054_spiral_matrix/readme.md b/src/main/ts/g0001_0100/s0054_spiral_matrix/readme.md new file mode 100644 index 0000000..75abbda --- /dev/null +++ b/src/main/ts/g0001_0100/s0054_spiral_matrix/readme.md @@ -0,0 +1,28 @@ +54\. Spiral Matrix + +Medium + +Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/13/spiral1.jpg) + +**Input:** matrix = [[1,2,3],[4,5,6],[7,8,9]] + +**Output:** [1,2,3,6,9,8,7,4,5] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/13/spiral.jpg) + +**Input:** matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] + +**Output:** [1,2,3,4,8,12,11,10,9,5,6,7] + +**Constraints:** + +* `m == matrix.length` +* `n == matrix[i].length` +* `1 <= m, n <= 10` +* `-100 <= matrix[i][j] <= 100` \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts b/src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts new file mode 100644 index 0000000..48a76ae --- /dev/null +++ b/src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts @@ -0,0 +1,32 @@ +// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Simulation +// #Programming_Skills_II_Day_8 #Level_2_Day_1_Implementation/Simulation #Udemy_2D_Arrays/Matrix +// #Top_Interview_150_Matrix #2025_04_01_Time_0_ms_(100.00%)_Space_55.71_MB_(30.13%) + +function spiralOrder(matrix: number[][]): number[] { + const result: number[] = [] + let r = 0, + c = 0 + let bigR = matrix.length - 1 + let bigC = matrix[0].length - 1 + while (r <= bigR && c <= bigC) { + for (let i = c; i <= bigC; i++) { + result.push(matrix[r][i]) + } + r++ + for (let i = r; i <= bigR; i++) { + result.push(matrix[i][bigC]) + } + bigC-- + for (let i = bigC; i >= c && r <= bigR; i--) { + result.push(matrix[bigR][i]) + } + bigR-- + for (let i = bigR; i >= r && c <= bigC; i--) { + result.push(matrix[i][c]) + } + c++ + } + return result +} + +export { spiralOrder } diff --git a/src/main/ts/g0001_0100/s0055_jump_game/solution.ts b/src/main/ts/g0001_0100/s0055_jump_game/solution.ts index 90097bb..c38b2fa 100644 --- a/src/main/ts/g0001_0100/s0055_jump_game/solution.ts +++ b/src/main/ts/g0001_0100/s0055_jump_game/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n)_Space_O(1) #2023_09_30_Time_58_ms_(91.95%)_Space_47.4_MB_(70.79%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_59.92_MB_(51.18%) function canJump(nums: number[]): boolean { let availableSteps = nums[0] diff --git a/src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts b/src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts index e67357b..7d4e91b 100644 --- a/src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts +++ b/src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n_log_n)_Space_O(n) #2023_10_01_Time_84_ms_(92.06%)_Space_49.9_MB_(69.16%) +// #Top_Interview_150_Intervals #Big_O_Time_O(n_log_n)_Space_O(n) +// #2025_03_23_Time_7_ms_(87.99%)_Space_66.00_MB_(36.16%) function merge(intervals: number[][]): number[][] { let result = [] diff --git a/src/main/ts/g0001_0100/s0057_insert_interval/readme.md b/src/main/ts/g0001_0100/s0057_insert_interval/readme.md new file mode 100644 index 0000000..2a9c2e3 --- /dev/null +++ b/src/main/ts/g0001_0100/s0057_insert_interval/readme.md @@ -0,0 +1,50 @@ +57\. Insert Interval + +Medium + +You are given an array of non-overlapping intervals `intervals` where intervals[i] = [starti, endi] represent the start and the end of the ith interval and `intervals` is sorted in ascending order by starti. You are also given an interval `newInterval = [start, end]` that represents the start and end of another interval. + +Insert `newInterval` into `intervals` such that `intervals` is still sorted in ascending order by starti and `intervals` still does not have any overlapping intervals (merge overlapping intervals if necessary). + +Return `intervals` _after the insertion_. + +**Example 1:** + +**Input:** intervals = [[1,3],[6,9]], newInterval = [2,5] + +**Output:** [[1,5],[6,9]] + +**Example 2:** + +**Input:** intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] + +**Output:** [[1,2],[3,10],[12,16]] + +**Explanation:** Because the new interval `[4,8]` overlaps with `[3,5],[6,7],[8,10]`. + +**Example 3:** + +**Input:** intervals = [], newInterval = [5,7] + +**Output:** [[5,7]] + +**Example 4:** + +**Input:** intervals = [[1,5]], newInterval = [2,3] + +**Output:** [[1,5]] + +**Example 5:** + +**Input:** intervals = [[1,5]], newInterval = [2,7] + +**Output:** [[1,7]] + +**Constraints:** + +* 0 <= intervals.length <= 104 +* `intervals[i].length == 2` +* 0 <= starti <= endi <= 105 +* `intervals` is sorted by starti in **ascending** order. +* `newInterval.length == 2` +* 0 <= start <= end <= 105 diff --git a/src/main/ts/g0001_0100/s0057_insert_interval/solution.ts b/src/main/ts/g0001_0100/s0057_insert_interval/solution.ts new file mode 100644 index 0000000..c68e94d --- /dev/null +++ b/src/main/ts/g0001_0100/s0057_insert_interval/solution.ts @@ -0,0 +1,28 @@ +// #Medium #Array #Level_2_Day_17_Interval #Top_Interview_150_Intervals +// #2025_04_02_Time_0_ms_(100.00%)_Space_58.54_MB_(66.77%) + +function insert(intervals: number[][], newInterval: number[]): number[][] { + const n = intervals.length + let l = 0 + let r = n - 1 + while (l < n && newInterval[0] > intervals[l][1]) { + l++ + } + while (r >= 0 && newInterval[1] < intervals[r][0]) { + r-- + } + const res: number[][] = new Array(l + n - r).fill(0).map(() => new Array(2)) + for (let i = 0; i < l; i++) { + res[i] = [...intervals[i]] + } + res[l] = [ + Math.min(newInterval[0], l === n ? newInterval[0] : intervals[l][0]), + Math.max(newInterval[1], r === -1 ? newInterval[1] : intervals[r][1]), + ] + for (let i = l + 1, j = r + 1; j < n; i++, j++) { + res[i] = intervals[j] + } + return res +} + +export { insert } diff --git a/src/main/ts/g0001_0100/s0058_length_of_last_word/readme.md b/src/main/ts/g0001_0100/s0058_length_of_last_word/readme.md new file mode 100644 index 0000000..8e8e6c7 --- /dev/null +++ b/src/main/ts/g0001_0100/s0058_length_of_last_word/readme.md @@ -0,0 +1,37 @@ +58\. Length of Last Word + +Easy + +Given a string `s` consisting of some words separated by some number of spaces, return _the length of the **last** word in the string._ + +A **word** is a maximal substring consisting of non-space characters only. + +**Example 1:** + +**Input:** s = "Hello World" + +**Output:** 5 + +**Explanation:** The last word is "World" with length 5. + +**Example 2:** + +**Input:** s = " fly me to the moon " + +**Output:** 4 + +**Explanation:** The last word is "moon" with length 4. + +**Example 3:** + +**Input:** s = "luffy is still joyboy" + +**Output:** 6 + +**Explanation:** The last word is "joyboy" with length 6. + +**Constraints:** + +* 1 <= s.length <= 104 +* `s` consists of only English letters and spaces `' '`. +* There will be at least one word in `s`. diff --git a/src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts b/src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts new file mode 100644 index 0000000..b3a2e81 --- /dev/null +++ b/src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts @@ -0,0 +1,17 @@ +// #Easy #String #Programming_Skills_II_Day_6 #Udemy_Arrays #Top_Interview_150_Array/String +// #2025_04_02_Time_0_ms_(100.00%)_Space_56.32_MB_(7.86%) + +function lengthOfLastWord(s: string): number { + let len = 0 + for (let i = s.length - 1; i >= 0; i--) { + const ch = s[i] + if (ch === ' ' && len > 0) { + break + } else if (ch !== ' ') { + len++ + } + } + return len +} + +export { lengthOfLastWord } diff --git a/src/main/ts/g0001_0100/s0061_rotate_list/readme.md b/src/main/ts/g0001_0100/s0061_rotate_list/readme.md new file mode 100644 index 0000000..aeb6530 --- /dev/null +++ b/src/main/ts/g0001_0100/s0061_rotate_list/readme.md @@ -0,0 +1,27 @@ +61\. Rotate List + +Medium + +Given the `head` of a linked list, rotate the list to the right by `k` places. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg) + +**Input:** head = [1,2,3,4,5], k = 2 + +**Output:** [4,5,1,2,3] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/13/roate2.jpg) + +**Input:** head = [0,1,2], k = 4 + +**Output:** [2,0,1] + +**Constraints:** + +* The number of nodes in the list is in the range `[0, 500]`. +* `-100 <= Node.val <= 100` +* 0 <= k <= 2 * 109 diff --git a/src/main/ts/g0001_0100/s0061_rotate_list/solution.ts b/src/main/ts/g0001_0100/s0061_rotate_list/solution.ts new file mode 100644 index 0000000..70b5f08 --- /dev/null +++ b/src/main/ts/g0001_0100/s0061_rotate_list/solution.ts @@ -0,0 +1,39 @@ +// #Medium #Two_Pointers #Linked_List #Programming_Skills_II_Day_16 #Udemy_Linked_List +// #Top_Interview_150_Linked_List #2025_04_02_Time_0_ms_(100.00%)_Space_58.23_MB_(55.89%) + +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ +function rotateRight(head: ListNode | null, k: number): ListNode | null { + if (!head || k === 0) { + return head + } + let tail: ListNode | null = head + let count = 1 + while (tail.next) { + count++ + tail = tail.next + } + let times = k % count + if (times === 0) { + return head + } + let temp: ListNode | null = head + for (let i = 1; i < count - times; i++) { + temp = temp!.next + } + let newHead = temp!.next + temp!.next = null + tail!.next = head + return newHead +} + +export { rotateRight } diff --git a/src/main/ts/g0001_0100/s0062_unique_paths/solution.ts b/src/main/ts/g0001_0100/s0062_unique_paths/solution.ts index 241091f..6a301dd 100644 --- a/src/main/ts/g0001_0100/s0062_unique_paths/solution.ts +++ b/src/main/ts/g0001_0100/s0062_unique_paths/solution.ts @@ -1,19 +1,18 @@ // #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) -// #2023_10_01_Time_40_ms_(98.97%)_Space_42.8_MB_(72.52%) +// #Combinatorics #LeetCode_75_DP/Multidimensional #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_03_23_Time_0_ms_(100.00%)_Space_55.15_MB_(43.54%) function uniquePaths(m: number, n: number): number { - const factorialize = (x: number) => { - if (x <= 1) return 1 - let res = x - while (x > 1) { - x-- - res *= x + let aboveRow = Array(n).fill(1) + for (let row = 1; row < m; row++) { + let currentRow = Array(n).fill(1) + for (let col = 1; col < n; col++) { + currentRow[col] = currentRow[col - 1] + aboveRow[col] } - return res + aboveRow = currentRow } - return factorialize(m + n - 2) / factorialize(m - 1) / factorialize(n - 1) + return aboveRow[n - 1] } export { uniquePaths } diff --git a/src/main/ts/g0001_0100/s0063_unique_paths_ii/readme.md b/src/main/ts/g0001_0100/s0063_unique_paths_ii/readme.md new file mode 100644 index 0000000..9009889 --- /dev/null +++ b/src/main/ts/g0001_0100/s0063_unique_paths_ii/readme.md @@ -0,0 +1,36 @@ +63\. Unique Paths II + +Medium + +A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below). + +The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). + +Now consider if some obstacles are added to the grids. How many unique paths would there be? + +An obstacle and space is marked as `1` and `0` respectively in the grid. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/04/robot1.jpg) + +**Input:** obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]] + +**Output:** 2 + +**Explanation:** There is one obstacle in the middle of the 3x3 grid above. There are two ways to reach the bottom-right corner: 1. Right -> Right -> Down -> Down 2. Down -> Down -> Right -> Right + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/04/robot2.jpg) + +**Input:** obstacleGrid = [[0,1],[0,0]] + +**Output:** 1 + +**Constraints:** + +* `m == obstacleGrid.length` +* `n == obstacleGrid[i].length` +* `1 <= m, n <= 100` +* `obstacleGrid[i][j]` is `0` or `1`. diff --git a/src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts b/src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts new file mode 100644 index 0000000..14dd49c --- /dev/null +++ b/src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts @@ -0,0 +1,37 @@ +// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_15 +// #Top_Interview_150_Multidimensional_DP #2025_04_02_Time_0_ms_(100.00%)_Space_55.75_MB_(56.77%) + +function uniquePathsWithObstacles(obstacleGrid: number[][]): number { + if (obstacleGrid[0][0] === 1) { + return 0 + } + obstacleGrid[0][0] = 1 + const m = obstacleGrid.length + const n = obstacleGrid[0].length + for (let i = 1; i < m; i++) { + if (obstacleGrid[i][0] === 1) { + obstacleGrid[i][0] = 0 + } else { + obstacleGrid[i][0] = obstacleGrid[i - 1][0] + } + } + for (let j = 1; j < n; j++) { + if (obstacleGrid[0][j] === 1) { + obstacleGrid[0][j] = 0 + } else { + obstacleGrid[0][j] = obstacleGrid[0][j - 1] + } + } + for (let i = 1; i < m; i++) { + for (let j = 1; j < n; j++) { + if (obstacleGrid[i][j] === 1) { + obstacleGrid[i][j] = 0 + } else { + obstacleGrid[i][j] = obstacleGrid[i - 1][j] + obstacleGrid[i][j - 1] + } + } + } + return obstacleGrid[m - 1][n - 1] +} + +export { uniquePathsWithObstacles } diff --git a/src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts b/src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts index 2948ef7..82b84c8 100644 --- a/src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts +++ b/src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix -// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n) -// #2023_10_01_Time_48_ms_(99.67%)_Space_44.5_MB_(90.16%) +// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #Big_O_Time_O(m*n)_Space_O(m*n) #2025_03_23_Time_4_ms_(70.73%)_Space_59.31_MB_(26.29%) function minPathSum(grid: number[][]): number { let [m, n] = [grid.length, grid[0].length] diff --git a/src/main/ts/g0001_0100/s0066_plus_one/readme.md b/src/main/ts/g0001_0100/s0066_plus_one/readme.md new file mode 100644 index 0000000..83b683f --- /dev/null +++ b/src/main/ts/g0001_0100/s0066_plus_one/readme.md @@ -0,0 +1,45 @@ +66\. Plus One + +Easy + +You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s. + +Increment the large integer by one and return _the resulting array of digits_. + +**Example 1:** + +**Input:** digits = [1,2,3] + +**Output:** [1,2,4] + +**Explanation:** The array represents the integer 123. Incrementing by one gives 123 + 1 = 124. Thus, the result should be [1,2,4]. + +**Example 2:** + +**Input:** digits = [4,3,2,1] + +**Output:** [4,3,2,2] + +**Explanation:** The array represents the integer 4321. Incrementing by one gives 4321 + 1 = 4322. Thus, the result should be [4,3,2,2]. + +**Example 3:** + +**Input:** digits = [0] + +**Output:** [1] + +**Explanation:** The array represents the integer 0. Incrementing by one gives 0 + 1 = 1. Thus, the result should be [1]. + +**Example 4:** + +**Input:** digits = [9] + +**Output:** [1,0] + +**Explanation:** The array represents the integer 9. Incrementing by one gives 9 + 1 = 10. Thus, the result should be [1,0]. + +**Constraints:** + +* `1 <= digits.length <= 100` +* `0 <= digits[i] <= 9` +* `digits` does not contain any leading `0`'s. diff --git a/src/main/ts/g0001_0100/s0066_plus_one/solution.ts b/src/main/ts/g0001_0100/s0066_plus_one/solution.ts new file mode 100644 index 0000000..45b8485 --- /dev/null +++ b/src/main/ts/g0001_0100/s0066_plus_one/solution.ts @@ -0,0 +1,23 @@ +// #Easy #Top_Interview_Questions #Array #Math #Programming_Skills_II_Day_3 #Udemy_Arrays +// #Top_Interview_150_Math #2025_04_02_Time_0_ms_(100.00%)_Space_55.60_MB_(44.68%) + +function plusOne(digits: number[]): number[] { + let num = 1 + let carry = 0 + let sum + for (let i = digits.length - 1; i >= 0; i--) { + if (i === digits.length - 1) { + sum = digits[i] + carry + num + } else { + sum = digits[i] + carry + } + carry = Math.floor(sum / 10) + digits[i] = sum % 10 + } + if (carry !== 0) { + return [carry, ...digits] + } + return digits +} + +export { plusOne } diff --git a/src/main/ts/g0001_0100/s0067_add_binary/readme.md b/src/main/ts/g0001_0100/s0067_add_binary/readme.md new file mode 100644 index 0000000..e47d02c --- /dev/null +++ b/src/main/ts/g0001_0100/s0067_add_binary/readme.md @@ -0,0 +1,23 @@ +67\. Add Binary + +Easy + +Given two binary strings `a` and `b`, return _their sum as a binary string_. + +**Example 1:** + +**Input:** a = "11", b = "1" + +**Output:** "100" + +**Example 2:** + +**Input:** a = "1010", b = "1011" + +**Output:** "10101" + +**Constraints:** + +* 1 <= a.length, b.length <= 104 +* `a` and `b` consist only of `'0'` or `'1'` characters. +* Each string does not contain leading zeros except for the zero itself. diff --git a/src/main/ts/g0001_0100/s0067_add_binary/solution.ts b/src/main/ts/g0001_0100/s0067_add_binary/solution.ts new file mode 100644 index 0000000..bfcc3ae --- /dev/null +++ b/src/main/ts/g0001_0100/s0067_add_binary/solution.ts @@ -0,0 +1,26 @@ +// #Easy #String #Math #Bit_Manipulation #Simulation #Programming_Skills_II_Day_5 +// #Top_Interview_150_Bit_Manipulation #2025_04_05_Time_0_ms_(100.00%)_Space_58.14_MB_(39.81%) + +function addBinary(a: string, b: string): string { + const aArray = a.split('') + const bArray = b.split('') + let sb: string[] = [] + let i = aArray.length - 1 + let j = bArray.length - 1 + let carry = 0 + while (i >= 0 || j >= 0) { + const digitA = i >= 0 ? parseInt(aArray[i]) : 0 + const digitB = j >= 0 ? parseInt(bArray[j]) : 0 + const sum = digitA + digitB + carry + sb.push((sum % 2).toString()) + carry = Math.floor(sum / 2) + i-- + j-- + } + if (carry !== 0) { + sb.push(carry.toString()) + } + return sb.reverse().join('') +} + +export { addBinary } diff --git a/src/main/ts/g0001_0100/s0068_text_justification/readme.md b/src/main/ts/g0001_0100/s0068_text_justification/readme.md new file mode 100644 index 0000000..1f62373 --- /dev/null +++ b/src/main/ts/g0001_0100/s0068_text_justification/readme.md @@ -0,0 +1,45 @@ +68\. Text Justification + +Hard + +Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified. + +You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that each line has exactly `maxWidth` characters. + +Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right. + +For the last line of text, it should be left-justified and no extra space is inserted between words. + +**Note:** + +* A word is defined as a character sequence consisting of non-space characters only. +* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth. +* The input array `words` contains at least one word. + +**Example 1:** + +**Input:** words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16 + +**Output:** [ "This is an", "example of text", "justification. " ] + +**Example 2:** + +**Input:** words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16 + +**Output:** [ "What must be", "acknowledgment ", "shall be " ] + +**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word. + +**Example 3:** + +**Input:** words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20 + +**Output:** [ "Science is what we", "understand well", "enough to explain to", "a computer. Art is", "everything else we", "do " ] + +**Constraints:** + +* `1 <= words.length <= 300` +* `1 <= words[i].length <= 20` +* `words[i]` consists of only English letters and symbols. +* `1 <= maxWidth <= 100` +* `words[i].length <= maxWidth` diff --git a/src/main/ts/g0001_0100/s0068_text_justification/solution.ts b/src/main/ts/g0001_0100/s0068_text_justification/solution.ts new file mode 100644 index 0000000..ed43ef6 --- /dev/null +++ b/src/main/ts/g0001_0100/s0068_text_justification/solution.ts @@ -0,0 +1,56 @@ +// #Hard #Array #String #Simulation #Top_Interview_150_Array/String +// #2025_04_05_Time_0_ms_(100.00%)_Space_55.70_MB_(38.14%) + +function fullJustify(words: string[], maxWidth: number): string[] { + const output: string[] = [] + let sb: string[] = [] + let lineTotal = 0 + let numWordsOnLine = 0 + let startWord = 0 + for (let i = 0; i < words.length - 1; i++) { + lineTotal += words[i].length + numWordsOnLine++ + if (lineTotal + numWordsOnLine + words[i + 1].length > maxWidth) { + sb = [] + if (numWordsOnLine === 1) { + sb.push(words[i]) + while (lineTotal++ < maxWidth) { + sb.push(' ') + } + } else { + const spaces = Math.floor((maxWidth - lineTotal) / (numWordsOnLine - 1)) + let extraSp = (maxWidth - lineTotal) % (numWordsOnLine - 1) + + for (let j = startWord; j < startWord + numWordsOnLine - 1; j++) { + sb.push(words[j]) + sb.push(' '.repeat(spaces + (extraSp-- > 0 ? 1 : 0))) + } + sb.push(words[startWord + numWordsOnLine - 1]) + } + output.push(sb.join('')) + startWord = i + 1 + numWordsOnLine = lineTotal = 0 + } + } + + // Handle last line + sb = [] + lineTotal = 0 + for (let i = startWord; i < words.length; i++) { + lineTotal += words[i].length + sb.push(words[i]) + if (lineTotal < maxWidth) { + sb.push(' ') + lineTotal++ + } + } + while (lineTotal < maxWidth) { + sb.push(' ') + lineTotal++ + } + output.push(sb.join('')) + + return output +} + +export { fullJustify } diff --git a/src/main/ts/g0001_0100/s0069_sqrtx/readme.md b/src/main/ts/g0001_0100/s0069_sqrtx/readme.md new file mode 100644 index 0000000..38b7950 --- /dev/null +++ b/src/main/ts/g0001_0100/s0069_sqrtx/readme.md @@ -0,0 +1,28 @@ +69\. Sqrt(x) + +Easy + +Given a non-negative integer `x`, compute and return _the square root of_ `x`. + +Since the return type is an integer, the decimal digits are **truncated**, and only **the integer part** of the result is returned. + +**Note:** You are not allowed to use any built-in exponent function or operator, such as `pow(x, 0.5)` or `x ** 0.5`. + +**Example 1:** + +**Input:** x = 4 + +**Output:** 2 + +**Example 2:** + +**Input:** x = 8 + +**Output:** 2 + +**Explanation:** The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned. + +**Constraints:** + +* 0 <= x <= 231 - 1 + diff --git a/src/main/ts/g0001_0100/s0069_sqrtx/solution.ts b/src/main/ts/g0001_0100/s0069_sqrtx/solution.ts new file mode 100644 index 0000000..fa84fd5 --- /dev/null +++ b/src/main/ts/g0001_0100/s0069_sqrtx/solution.ts @@ -0,0 +1,23 @@ +// #Easy #Top_Interview_Questions #Math #Binary_Search #Binary_Search_I_Day_4 +// #Top_Interview_150_Math #2025_04_16_Time_1_ms_(74.84%)_Space_57.85_MB_(56.21%) + +function mySqrt(x: number): number { + let low = 1 + let high = x + let lowest = 0 + while (low <= high) { + const mid = Math.floor((low + high) / 2) + const pow = mid * mid + if (pow > x) { + high = mid - 1 + } else if (pow < x) { + low = mid + 1 + lowest = mid + } else { + return mid + } + } + return lowest +} + +export { mySqrt } diff --git a/src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts b/src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts index 93347d7..305252f 100644 --- a/src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts +++ b/src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts @@ -1,12 +1,18 @@ // #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 #Big_O_Time_O(n)_Space_O(n) -// #2023_10_01_Time_44_ms_(94.58%)_Space_42.4_MB_(73.09%) +// #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP +// #Big_O_Time_O(n)_Space_O(n) #2025_03_23_Time_0_ms_(100.00%)_Space_56.23_MB_(5.15%) function climbStairs(n: number, memo: Record = {}): number { - if (n in memo) return memo[n] - if (n === 0) return 1 - if (n < 0) return 0 + if (n in memo) { + return memo[n] + } + if (n === 0) { + return 1 + } + if (n < 0) { + return 0 + } memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo) return memo[n] } diff --git a/src/main/ts/g0001_0100/s0071_simplify_path/readme.md b/src/main/ts/g0001_0100/s0071_simplify_path/readme.md new file mode 100644 index 0000000..1724575 --- /dev/null +++ b/src/main/ts/g0001_0100/s0071_simplify_path/readme.md @@ -0,0 +1,52 @@ +71\. Simplify Path + +Medium + +Given a string `path`, which is an **absolute path** (starting with a slash `'/'`) to a file or directory in a Unix-style file system, convert it to the simplified **canonical path**. + +In a Unix-style file system, a period `'.'` refers to the current directory, a double period `'..'` refers to the directory up a level, and any multiple consecutive slashes (i.e. `'//'`) are treated as a single slash `'/'`. For this problem, any other format of periods such as `'...'` are treated as file/directory names. + +The **canonical path** should have the following format: + +* The path starts with a single slash `'/'`. +* Any two directories are separated by a single slash `'/'`. +* The path does not end with a trailing `'/'`. +* The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period `'.'` or double period `'..'`) + +Return _the simplified **canonical path**_. + +**Example 1:** + +**Input:** path = "/home/" + +**Output:** "/home" + +**Explanation:** Note that there is no trailing slash after the last directory name. + +**Example 2:** + +**Input:** path = "/../" + +**Output:** "/" + +**Explanation:** Going one level up from the root directory is a no-op, as the root level is the highest level you can go. + +**Example 3:** + +**Input:** path = "/home//foo/" + +**Output:** "/home/foo" + +**Explanation:** In the canonical path, multiple consecutive slashes are replaced by a single one. + +**Example 4:** + +**Input:** path = "/a/./b/../../c/" + +**Output:** "/c" + +**Constraints:** + +* `1 <= path.length <= 3000` +* `path` consists of English letters, digits, period `'.'`, slash `'/'` or `'_'`. +* `path` is a valid absolute Unix path. diff --git a/src/main/ts/g0001_0100/s0071_simplify_path/solution.ts b/src/main/ts/g0001_0100/s0071_simplify_path/solution.ts new file mode 100644 index 0000000..60bf7fa --- /dev/null +++ b/src/main/ts/g0001_0100/s0071_simplify_path/solution.ts @@ -0,0 +1,19 @@ +// #Medium #String #Stack #Top_Interview_150_Stack +// #2025_04_05_Time_0_ms_(100.00%)_Space_58.31_MB_(30.21%) + +function simplifyPath(path: string): string { + const stack = [] + const mod = path.split('/').filter((element) => element.length) + for (const element of mod) { + if (element === '..') { + stack.pop() + } else if (element === '.') { + continue + } else { + stack.push(element) + } + } + return '/'.concat(stack.join('/')) +} + +export { simplifyPath } diff --git a/src/main/ts/g0001_0100/s0072_edit_distance/readme.md b/src/main/ts/g0001_0100/s0072_edit_distance/readme.md index fbd054c..75d48ed 100644 --- a/src/main/ts/g0001_0100/s0072_edit_distance/readme.md +++ b/src/main/ts/g0001_0100/s0072_edit_distance/readme.md @@ -1,6 +1,6 @@ 72\. Edit Distance -Hard +Medium Given two strings `word1` and `word2`, return _the minimum number of operations required to convert `word1` to `word2`_. diff --git a/src/main/ts/g0001_0100/s0072_edit_distance/solution.ts b/src/main/ts/g0001_0100/s0072_edit_distance/solution.ts index 58e4c6b..e6c7463 100644 --- a/src/main/ts/g0001_0100/s0072_edit_distance/solution.ts +++ b/src/main/ts/g0001_0100/s0072_edit_distance/solution.ts @@ -1,14 +1,16 @@ -// #Hard #Top_100_Liked_Questions #String #Dynamic_Programming +// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional // #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_19 -// #Udemy_Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n2) -// #2023_10_01_Time_68_ms_(95.20%)_Space_47.3_MB_(78.40%) +// #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(n^2)_Space_O(n2) +// #2025_03_23_Time_6_ms_(93.83%)_Space_61.09_MB_(45.68%) function minDistance(word1: string, word2: string): number { const memo: number[][] = new Array(word1.length + 1).fill(0).map((_) => []) const l1 = word1.length const l2 = word2.length const dfs = (w1: number, w2: number): number => { - if (memo[w1][w2] != undefined) return memo[w1][w2] + if (memo[w1][w2] != undefined) { + return memo[w1][w2] + } if (w1 == l1 && w2 == l2) { memo[w1][w2] = 0 return 0 diff --git a/src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts b/src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts index 1500921..dde26bb 100644 --- a/src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts +++ b/src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Matrix -// #Udemy_2D_Arrays/Matrix #Big_O_Time_O(m*n)_Space_O(1) -// #2023_10_01_Time_61_ms_(97.66%)_Space_45.9_MB_(30.73%) +// #Udemy_2D_Arrays/Matrix #Top_Interview_150_Matrix #Big_O_Time_O(m*n)_Space_O(1) +// #2025_03_23_Time_4_ms_(50.63%)_Space_61.42_MB_(6.15%) /* Do not return anything, modify matrix in-place instead. diff --git a/src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts b/src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts index f0a582f..3e684a7 100644 --- a/src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts +++ b/src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts @@ -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 #Big_O_Time_O(endRow+endCol)_Space_O(1) -// #2023_10_01_Time_45_ms_(96.82%)_Space_44.3_MB_(43.77%) +// #Udemy_2D_Arrays/Matrix #Top_Interview_150_Binary_Search #Big_O_Time_O(endRow+endCol)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_54.50_MB_(46.86%) function searchMatrix(matrix: number[][], target: number): boolean { const [m, n] = [matrix.length, matrix[0].length] diff --git a/src/main/ts/g0001_0100/s0075_sort_colors/solution.ts b/src/main/ts/g0001_0100/s0075_sort_colors/solution.ts index 5e3173e..deadd9f 100644 --- a/src/main/ts/g0001_0100/s0075_sort_colors/solution.ts +++ b/src/main/ts/g0001_0100/s0075_sort_colors/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers // #Data_Structure_II_Day_2_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1) -// #2023_10_02_Time_43_ms_(97.41%)_Space_42.5_MB_(85.34%) +// #2025_03_23_Time_0_ms_(100.00%)_Space_56.04_MB_(26.80%) const sortColors = (nums: number[]) => { let i = 0 diff --git a/src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts b/src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts index 10e234f..c069ae1 100644 --- a/src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts +++ b/src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts @@ -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 #Big_O_Time_O(s.length())_Space_O(1) -// #2023_10_02_Time_82_ms_(82.17%)_Space_46.2_MB_(81.89%) +// #Level_2_Day_14_Sliding_Window/Two_Pointer #Top_Interview_150_Sliding_Window +// #Big_O_Time_O(s.length())_Space_O(1) #2025_03_23_Time_20_ms_(90.35%)_Space_58.72_MB_(57.91%) function minWindow(s: string, t: string): string { //NOSONAR const map: Map = new Map() diff --git a/src/main/ts/g0001_0100/s0077_combinations/readme.md b/src/main/ts/g0001_0100/s0077_combinations/readme.md new file mode 100644 index 0000000..e6e38ec --- /dev/null +++ b/src/main/ts/g0001_0100/s0077_combinations/readme.md @@ -0,0 +1,24 @@ +77\. Combinations + +Medium + +Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers out of the range_ `[1, n]`. + +You may return the answer in **any order**. + +**Example 1:** + +**Input:** n = 4, k = 2 + +**Output:** [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] + +**Example 2:** + +**Input:** n = 1, k = 1 + +**Output:** [[1]] + +**Constraints:** + +* `1 <= n <= 20` +* `1 <= k <= n` diff --git a/src/main/ts/g0001_0100/s0077_combinations/solution.ts b/src/main/ts/g0001_0100/s0077_combinations/solution.ts new file mode 100644 index 0000000..1745911 --- /dev/null +++ b/src/main/ts/g0001_0100/s0077_combinations/solution.ts @@ -0,0 +1,21 @@ +// #Medium #Backtracking #Algorithm_I_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking +// #2025_04_05_Time_46_ms_(96.14%)_Space_128.25_MB_(74.09%) + +function combine(n: number, k: number): number[][] { + const ans: number[][] = [] + const backtrack = (curr: number[], j: number) => { + if (curr.length == k) { + ans.push([...curr]) + return + } + for (let i = j; i <= n; i++) { + curr.push(i) + backtrack(curr, i + 1) + curr.pop() + } + } + backtrack([], 1) + return ans +} + +export { combine } diff --git a/src/main/ts/g0001_0100/s0078_subsets/solution.ts b/src/main/ts/g0001_0100/s0078_subsets/solution.ts index 3971504..5a9c361 100644 --- a/src/main/ts/g0001_0100/s0078_subsets/solution.ts +++ b/src/main/ts/g0001_0100/s0078_subsets/solution.ts @@ -1,10 +1,12 @@ // #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) #2023_10_02_Time_50_ms_(94.61%)_Space_44.8_MB_(75.83%) +// #Big_O_Time_O(2^n)_Space_O(n*2^n) #2025_03_23_Time_0_ms_(100.00%)_Space_58.49_MB_(41.68%) -const subsets = (nums: number[]): number[][] => { +function subsets(nums: number[]): number[][] { const sets: number[][] = [[]] - for (const num of nums) sets.push(...sets.map((set) => [...set, num])) + for (const num of nums) { + sets.push(...sets.map((set) => [...set, num])) + } return sets } diff --git a/src/main/ts/g0001_0100/s0079_word_search/solution.ts b/src/main/ts/g0001_0100/s0079_word_search/solution.ts index d76d643..e6f40c4 100644 --- a/src/main/ts/g0001_0100/s0079_word_search/solution.ts +++ b/src/main/ts/g0001_0100/s0079_word_search/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Backtracking -// #Algorithm_II_Day_11_Recursion_Backtracking #Big_O_Time_O(4^(m*n))_Space_O(m*n) -// #2023_10_03_Time_327_ms_(95.78%)_Space_43.4_MB_(84.98%) +// #Algorithm_II_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking +// #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2025_03_23_Time_243_ms_(85.30%)_Space_56.58_MB_(58.26%) function exist(board: string[][], word: string): boolean { if (word.length === 0) return false @@ -12,7 +12,6 @@ function exist(board: string[][], word: string): boolean { if (loop(marks, board, i, j, word, 0)) return true } } - return ret } @@ -31,28 +30,29 @@ function loop(marks: boolean[][], board: string[][], i: number, j: number, word: if (i < 0 || j < 0 || i >= board.length || j >= board[i].length || marks[i][j]) { return false } - if (board[i][j] !== word.charAt(index)) { return false } else if (index === word.length - 1) { return true } - marks[i][j] = true index++ - let r = loop(marks, board, i - 1, j, word, index) - if (r) return true - + if (r) { + return true + } r = loop(marks, board, i + 1, j, word, index) - if (r) return true - + if (r) { + return true + } r = loop(marks, board, i, j - 1, word, index) - if (r) return true - + if (r) { + return true + } r = loop(marks, board, i, j + 1, word, index) - if (r) return true - + if (r) { + return true + } marks[i][j] = false return false } diff --git a/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md b/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md new file mode 100644 index 0000000..36e2637 --- /dev/null +++ b/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md @@ -0,0 +1,49 @@ +80\. Remove Duplicates from Sorted Array II + +Medium + +Given an integer array `nums` sorted in **non-decreasing order**, remove some duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears **at most twice**. The **relative order** of the elements should be kept the **same**. + +Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements. + +Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`. + +Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory. + +**Custom Judge:** + +The judge will test your solution with the following code: + + int[] nums = [...]; // Input array + int[] expectedNums = [...]; // The expected answer with correct length + + int k = removeDuplicates(nums); // Calls your implementation + + assert k == expectedNums.length; + for (int i = 0; i < k; i++) { + assert nums[i] == expectedNums[i]; + } + +If all assertions pass, then your solution will be **accepted**. + +**Example 1:** + +**Input:** nums = [1,1,1,2,2,3] + +**Output:** 5, nums = [1,1,2,2,3,\_] + +**Explanation:** Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Example 2:** + +**Input:** nums = [0,0,1,1,1,1,2,3,3] + +**Output:** 7, nums = [0,0,1,1,2,3,3,\_,\_] + +**Explanation:** Your function should return k = 7, with the first seven elements of nums being 0, 0, 1, 1, 2, 3 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores). + +**Constraints:** + +* 1 <= nums.length <= 3 * 104 +* -104 <= nums[i] <= 104 +* `nums` is sorted in **non-decreasing** order. diff --git a/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts b/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts new file mode 100644 index 0000000..018d236 --- /dev/null +++ b/src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts @@ -0,0 +1,25 @@ +// #Medium #Array #Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String +// #2025_04_05_Time_40_ms_(99.63%)_Space_59.84_MB_(30.62%) + +function removeDuplicates(nums: number[]): number { + let i = 0 + let k = 0 + let count = 0 + while (i < nums.length - 1) { + count++ + if (count <= 2) { + nums[k++] = nums[i] + } + if (nums[i] !== nums[i + 1]) { + count = 0 + } + i++ + } + count++ + if (count <= 2) { + nums[k++] = nums[i] + } + return k +} + +export { removeDuplicates } diff --git a/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md b/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md new file mode 100644 index 0000000..c5d55ac --- /dev/null +++ b/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md @@ -0,0 +1,27 @@ +82\. Remove Duplicates from Sorted List II + +Medium + +Given the `head` of a sorted linked list, _delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list_. Return _the linked list **sorted** as well_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/04/linkedlist1.jpg) + +**Input:** head = [1,2,3,3,4,4,5] + +**Output:** [1,2,5] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/04/linkedlist2.jpg) + +**Input:** head = [1,1,1,2,3] + +**Output:** [2,3] + +**Constraints:** + +* The number of nodes in the list is in the range `[0, 300]`. +* `-100 <= Node.val <= 100` +* The list is guaranteed to be **sorted** in ascending order. diff --git a/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts b/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts new file mode 100644 index 0000000..aac4eee --- /dev/null +++ b/src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts @@ -0,0 +1,42 @@ +// #Medium #Two_Pointers #Linked_List #Data_Structure_II_Day_11_Linked_List +// #Algorithm_II_Day_3_Two_Pointers #Top_Interview_150_Linked_List +// #2025_04_05_Time_0_ms_(100.00%)_Space_58.58_MB_(53.51%) + +import { ListNode } from '../../com_github_leetcode/listnode' + +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ +function deleteDuplicates(head: ListNode | null): ListNode | null { + if (!head || !head.next) { + return head + } + const dummy = new ListNode(0) + dummy.next = head + let prev: ListNode = dummy + let curr: ListNode | null = head + while (curr) { + let hasDuplicate = false + while (curr.next && curr.val === curr.next.val) { + hasDuplicate = true + curr = curr.next + } + if (hasDuplicate) { + prev.next = curr.next + } else { + prev = prev.next! + } + curr = curr.next + } + return dummy.next +} + +export { deleteDuplicates } diff --git a/src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts b/src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts index 9b6c671..634843d 100644 --- a/src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts +++ b/src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts @@ -1,5 +1,5 @@ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Stack #Monotonic_Stack -// #Big_O_Time_O(n_log_n)_Space_O(log_n) #2023_10_03_Time_78_ms_(92.44%)_Space_56.8_MB_(85.29%) +// #Big_O_Time_O(n_log_n)_Space_O(log_n) #2025_03_23_Time_15_ms_(72.81%)_Space_72.66_MB_(37.28%) function largestRectangleArea(heights: number[]): number { let stack = [] diff --git a/src/main/ts/g0001_0100/s0086_partition_list/readme.md b/src/main/ts/g0001_0100/s0086_partition_list/readme.md new file mode 100644 index 0000000..fd27e77 --- /dev/null +++ b/src/main/ts/g0001_0100/s0086_partition_list/readme.md @@ -0,0 +1,27 @@ +86\. Partition List + +Medium + +Given the `head` of a linked list and a value `x`, partition it such that all nodes **less than** `x` come before nodes **greater than or equal** to `x`. + +You should **preserve** the original relative order of the nodes in each of the two partitions. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/04/partition.jpg) + +**Input:** head = [1,4,3,2,5,2], x = 3 + +**Output:** [1,2,2,4,3,5] + +**Example 2:** + +**Input:** head = [2,1], x = 2 + +**Output:** [1,2] + +**Constraints:** + +* The number of nodes in the list is in the range `[0, 200]`. +* `-100 <= Node.val <= 100` +* `-200 <= x <= 200` diff --git a/src/main/ts/g0001_0100/s0086_partition_list/solution.ts b/src/main/ts/g0001_0100/s0086_partition_list/solution.ts new file mode 100644 index 0000000..cbeeff9 --- /dev/null +++ b/src/main/ts/g0001_0100/s0086_partition_list/solution.ts @@ -0,0 +1,38 @@ +// #Medium #Two_Pointers #Linked_List #Top_Interview_150_Linked_List +// #2025_04_05_Time_0_ms_(100.00%)_Space_58.16_MB_(62.07%) + +import { ListNode } from '../../com_github_leetcode/listnode' + +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ +function partition(head: ListNode | null, x: number): ListNode | null { + let beforeHead = new ListNode(0) + let afterHead = new ListNode(0) + let before = beforeHead + let after = afterHead + while (head !== null) { + const nextNode = head.next + if (head.val < x) { + before.next = head + before = before.next + } else { + after.next = head + after = after.next + } + head = nextNode + } + after.next = null + before.next = afterHead.next + return beforeHead.next +} + +export { partition } diff --git a/src/main/ts/g0001_0100/s0088_merge_sorted_array/readme.md b/src/main/ts/g0001_0100/s0088_merge_sorted_array/readme.md new file mode 100644 index 0000000..7656505 --- /dev/null +++ b/src/main/ts/g0001_0100/s0088_merge_sorted_array/readme.md @@ -0,0 +1,43 @@ +88\. Merge Sorted Array + +Easy + +You are given two integer arrays `nums1` and `nums2`, sorted in **non-decreasing order**, and two integers `m` and `n`, representing the number of elements in `nums1` and `nums2` respectively. + +**Merge** `nums1` and `nums2` into a single array sorted in **non-decreasing order**. + +The final sorted array should not be returned by the function, but instead be _stored inside the array_ `nums1`. To accommodate this, `nums1` has a length of `m + n`, where the first `m` elements denote the elements that should be merged, and the last `n` elements are set to `0` and should be ignored. `nums2` has a length of `n`. + +**Example 1:** + +**Input:** nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 + +**Output:** [1,2,2,3,5,6] + +**Explanation:** The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1. + +**Example 2:** + +**Input:** nums1 = [1], m = 1, nums2 = [], n = 0 + +**Output:** [1] + +**Explanation:** The arrays we are merging are [1] and []. The result of the merge is [1]. + +**Example 3:** + +**Input:** nums1 = [0], m = 0, nums2 = [1], n = 1 + +**Output:** [1] + +**Explanation:** The arrays we are merging are [] and [1]. The result of the merge is [1]. Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1. + +**Constraints:** + +* `nums1.length == m + n` +* `nums2.length == n` +* `0 <= m, n <= 200` +* `1 <= m + n <= 200` +* -109 <= nums1[i], nums2[j] <= 109 + +**Follow up:** Can you come up with an algorithm that runs in `O(m + n)` time? diff --git a/src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts b/src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts new file mode 100644 index 0000000..dbc8551 --- /dev/null +++ b/src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts @@ -0,0 +1,20 @@ +// #Easy #Top_Interview_Questions #Array #Sorting #Two_Pointers #Data_Structure_I_Day_2_Array +// #Top_Interview_150_Array/String #2025_04_05_Time_0_ms_(100.00%)_Space_58.16_MB_(62.07%) + +/** + * Do not return anything, modify nums1 in-place instead. + */ +function merge(nums1: number[], m: number, nums2: number[], n: number): void { + let i = m - 1 + let j = nums1.length - 1 + let p2 = n - 1 + while (p2 >= 0) { + if (i >= 0 && nums1[i] > nums2[p2]) { + nums1[j--] = nums1[i--] + } else { + nums1[j--] = nums2[p2--] + } + } +} + +export { merge } diff --git a/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/readme.md b/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/readme.md new file mode 100644 index 0000000..d7d7133 --- /dev/null +++ b/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/readme.md @@ -0,0 +1,28 @@ +92\. Reverse Linked List II + +Medium + +Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return _the reversed list_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/rev2ex2.jpg) + +**Input:** head = [1,2,3,4,5], left = 2, right = 4 + +**Output:** [1,4,3,2,5] + +**Example 2:** + +**Input:** head = [5], left = 1, right = 1 + +**Output:** [5] + +**Constraints:** + +* The number of nodes in the list is `n`. +* `1 <= n <= 500` +* `-500 <= Node.val <= 500` +* `1 <= left <= right <= n` + +**Follow up:** Could you do it in one pass? diff --git a/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts b/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts new file mode 100644 index 0000000..41c7ae8 --- /dev/null +++ b/src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts @@ -0,0 +1,49 @@ +// #Medium #Linked_List #Top_Interview_150_Linked_List +// #2025_04_05_Time_0_ms_(100.00%)_Space_55.58_MB_(58.46%) + +import { ListNode } from '../../com_github_leetcode/listnode' + +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ +function reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null { + if (left === right || head === null) { + return head + } + let prev: ListNode | null = null + let temp: ListNode | null = head + let k = left + while (temp !== null && k > 1) { + prev = temp + temp = temp.next + k-- + } + const start = temp + let prev1: ListNode | null = null + let tail: ListNode | null = temp + for (let i = 0; i <= right - left && tail !== null; i++) { + const next = tail.next + tail.next = prev1 + prev1 = tail + tail = next + } + if (prev !== null) { + prev.next = prev1 + } else { + head = prev1 + } + if (start !== null) { + start.next = tail + } + return head +} + +export { reverseBetween } diff --git a/src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts b/src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts index 6bf7b20..7f88854 100644 --- a/src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts +++ b/src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts @@ -1,10 +1,10 @@ // #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) -// #2023_10_03_Time_45_ms_(97.30%)_Space_42.9_MB_(96.73%) +// #2025_03_23_Time_0_ms_(100.00%)_Space_54.69_MB_(46.13%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number @@ -18,8 +18,12 @@ import { TreeNode } from '../../com_github_leetcode/treenode' * } */ function inorderTraversal(root: TreeNode | null): number[] { - if (!root) return [] - if (!root.val) return [] + if (!root) { + return [] + } + if (!root.val) { + return [] + } const result: number[] = [] function traverse(node: TreeNode, arr: number[]) { if (node.left) { diff --git a/src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts b/src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts index c129e65..39753dc 100644 --- a/src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts +++ b/src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts @@ -1,6 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Dynamic_Programming #Math #Tree #Binary_Tree -// #Binary_Search_Tree #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1) -// #2023_10_03_Time_45_ms_(96.00%)_Space_42.9_MB_(25.33%) +// #Medium #Dynamic_Programming #Math #Tree #Binary_Tree #Binary_Search_Tree +// #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1) +// #2025_03_23_Time_0_ms_(100.00%)_Space_55.21_MB_(33.33%) function numTrees(n: number): number { const uniqueCount = new Array(n + 1).fill(0) diff --git a/src/main/ts/g0001_0100/s0097_interleaving_string/readme.md b/src/main/ts/g0001_0100/s0097_interleaving_string/readme.md new file mode 100644 index 0000000..3ad6417 --- /dev/null +++ b/src/main/ts/g0001_0100/s0097_interleaving_string/readme.md @@ -0,0 +1,42 @@ +97\. Interleaving String + +Medium + +Given strings `s1`, `s2`, and `s3`, find whether `s3` is formed by an **interleaving** of `s1` and `s2`. + +An **interleaving** of two strings `s` and `t` is a configuration where they are divided into **non-empty** substrings such that: + +* s = s1 + s2 + ... + sn +* t = t1 + t2 + ... + tm +* `|n - m| <= 1` +* The **interleaving** is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ... + +**Note:** `a + b` is the concatenation of strings `a` and `b`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/09/02/interleave.jpg) + +**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" + +**Output:** true + +**Example 2:** + +**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc" + +**Output:** false + +**Example 3:** + +**Input:** s1 = "", s2 = "", s3 = "" + +**Output:** true + +**Constraints:** + +* `0 <= s1.length, s2.length <= 100` +* `0 <= s3.length <= 200` +* `s1`, `s2`, and `s3` consist of lowercase English letters. + +**Follow up:** Could you solve it using only `O(s2.length)` additional memory space? diff --git a/src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts b/src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts new file mode 100644 index 0000000..255f12f --- /dev/null +++ b/src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts @@ -0,0 +1,38 @@ +// #Medium #String #Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #2025_04_05_Time_43_ms_(97.65%)_Space_58.17_MB_(61.77%) + +function isInterleave(s1: string, s2: string, s3: string): boolean { + if (s3.length !== s1.length + s2.length) { + return false + } + const cache: boolean[][] = Array.from({ length: s1.length + 1 }, () => Array(s2.length + 1).fill(null)) + return isInterleaveHelper(s1, s2, s3, 0, 0, 0, cache) +} + +function isInterleaveHelper( + s1: string, + s2: string, + s3: string, + i1: number, + i2: number, + i3: number, + cache: boolean[][], +): boolean { + if (cache[i1][i2] !== null) { + return cache[i1][i2] + } + if (i1 === s1.length && i2 === s2.length && i3 === s3.length) { + return true + } + let result = false + if (i1 < s1.length && s1.charAt(i1) === s3.charAt(i3)) { + result = isInterleaveHelper(s1, s2, s3, i1 + 1, i2, i3 + 1, cache) + } + if (i2 < s2.length && s2.charAt(i2) === s3.charAt(i3)) { + result = result || isInterleaveHelper(s1, s2, s3, i1, i2 + 1, i3 + 1, cache) + } + cache[i1][i2] = result + return result +} + +export { isInterleave } diff --git a/src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts b/src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts index 3e277a4..93a58d7 100644 --- a/src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts +++ b/src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts @@ -1,14 +1,33 @@ // #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 #Big_O_Time_O(N)_Space_O(log(N)) -// #2023_10_03_Time_51_ms_(98.35%)_Space_47.3_MB_(61.68%) +// #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(N)_Space_O(log(N)) +// #2025_03_23_Time_0_ms_(100.00%)_Space_60.76_MB_(21.74%) import { TreeNode } from '../../com_github_leetcode/treenode' +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ function dfs(node: TreeNode | null, lowerBound: number, upperBound: number): boolean { - if (!node) return true - if (node.val <= lowerBound) return false - if (node.val >= upperBound) return false + if (!node) { + return true + } + if (node.val <= lowerBound) { + return false + } + if (node.val >= upperBound) { + return false + } return dfs(node.left, lowerBound, node.val) && dfs(node.right, node.val, upperBound) } diff --git a/src/main/ts/g0001_0100/s0100_same_tree/readme.md b/src/main/ts/g0001_0100/s0100_same_tree/readme.md new file mode 100644 index 0000000..0172a56 --- /dev/null +++ b/src/main/ts/g0001_0100/s0100_same_tree/readme.md @@ -0,0 +1,36 @@ +100\. Same Tree + +Easy + +Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not. + +Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg) + +**Input:** p = [1,2,3], q = [1,2,3] + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg) + +**Input:** p = [1,2], q = [1,null,2] + +**Output:** false + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2020/12/20/ex3.jpg) + +**Input:** p = [1,2,1], q = [1,1,2] + +**Output:** false + +**Constraints:** + +* The number of nodes in both trees is in the range `[0, 100]`. +* -104 <= Node.val <= 104 \ No newline at end of file diff --git a/src/main/ts/g0001_0100/s0100_same_tree/solution.ts b/src/main/ts/g0001_0100/s0100_same_tree/solution.ts new file mode 100644 index 0000000..fe8994c --- /dev/null +++ b/src/main/ts/g0001_0100/s0100_same_tree/solution.ts @@ -0,0 +1,29 @@ +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Level_2_Day_15_Tree +// #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General +// #2025_04_16_Time_0_ms_(100.00%)_Space_55.66_MB_(67.00%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { + if (p === null || q === null) { + return p === null && q === null + } + const b1 = isSameTree(p.left, q.left) + const b2 = isSameTree(p.right, q.right) + return p.val === q.val && b1 && b2 +} + +export { isSameTree } diff --git a/src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts b/src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts index 8c4b109..ebb3065 100644 --- a/src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts +++ b/src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts @@ -1,10 +1,11 @@ // #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 -// #Big_O_Time_O(N)_Space_O(log(N)) #2023_10_04_Time_49_ms_(98.54%)_Space_45_MB_(59.02%) +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(log(N)) +// #2025_03_23_Time_0_ms_(100.00%)_Space_58.35_MB_(25.66%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number @@ -18,14 +19,20 @@ import { TreeNode } from '../../com_github_leetcode/treenode' * } */ function isSymmetric(root: TreeNode | null): boolean { - if (!root.left && !root.right) return true + if (!root.left && !root.right) { + return true + } const queue: [TreeNode, TreeNode][] = [[root.left, root.right]] while (queue.length > 0) { let qLen: number = queue.length while (qLen-- > 0) { const [leftNode, rightNode] = queue.shift() - if (!leftNode && !rightNode) continue - if (!leftNode || !rightNode || leftNode.val != rightNode.val) return false + if (!leftNode && !rightNode) { + continue + } + if (!leftNode || !rightNode || leftNode.val != rightNode.val) { + return false + } queue.push([leftNode.left, rightNode.right]) queue.push([leftNode.right, rightNode.left]) } diff --git a/src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts b/src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts index c7ad922..b981158 100644 --- a/src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts +++ b/src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts @@ -1,10 +1,11 @@ // #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 -// #Big_O_Time_O(N)_Space_O(N) #2023_10_04_Time_60_ms_(97.47%)_Space_47_MB_(77.89%) +// #Top_Interview_150_Binary_Tree_BFS #Big_O_Time_O(N)_Space_O(N) +// #2025_03_23_Time_0_ms_(100.00%)_Space_59.70_MB_(51.83%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number @@ -18,7 +19,9 @@ import { TreeNode } from '../../com_github_leetcode/treenode' * } */ function levelOrder(root: TreeNode | null): number[][] { - if (root == null) return [] + if (root == null) { + return [] + } let queue = [root] let result = [] while (queue.length != 0) { @@ -27,8 +30,12 @@ function levelOrder(root: TreeNode | null): number[][] { while (length > 0) { let node = queue.shift() subResult.push(node.val) - if (node.left != null) queue.push(node.left) - if (node.right != null) queue.push(node.right) + if (node.left != null) { + queue.push(node.left) + } + if (node.right != null) { + queue.push(node.right) + } length-- } result.push(subResult) diff --git a/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/readme.md b/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/readme.md new file mode 100644 index 0000000..d403d28 --- /dev/null +++ b/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/readme.md @@ -0,0 +1,30 @@ +103\. Binary Tree Zigzag Level Order Traversal + +Medium + +Given the `root` of a binary tree, return _the zigzag level order traversal of its nodes' values_. (i.e., from left to right, then right to left for the next level and alternate between). + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg) + +**Input:** root = [3,9,20,null,null,15,7] + +**Output:** [[3],[20,9],[15,7]] + +**Example 2:** + +**Input:** root = [1] + +**Output:** [[1]] + +**Example 3:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 2000]`. +* `-100 <= Node.val <= 100` diff --git a/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts b/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts new file mode 100644 index 0000000..5f57a79 --- /dev/null +++ b/src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts @@ -0,0 +1,54 @@ +// #Medium #Top_Interview_Questions #Breadth_First_Search #Tree #Binary_Tree +// #Data_Structure_II_Day_15_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_BFS +// #2025_04_05_Time_0_ms_(100.00%)_Space_58.00_MB_(52.61%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function zigzagLevelOrder(root: TreeNode | null): number[][] { + const result: number[][] = [] + if (root === null) { + return result + } + const q: (TreeNode | null)[] = [root, null] + let zig = true + let level: number[] = [] + while (q.length > 0) { + const node = q.shift() + if (node === null) { + result.push(level) + zig = !zig + level = [] + if (q.length > 0) { + q.push(null) + } + } else { + if (zig) { + level.push(node.val) + } else { + level.unshift(node.val) + } + if (node.left !== null) { + q.push(node.left) + } + if (node.right !== null) { + q.push(node.right) + } + } + } + return result +} + +export { zigzagLevelOrder } diff --git a/src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts b/src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts index 0956744..7d59ff9 100644 --- a/src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts +++ b/src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.ts @@ -1,11 +1,12 @@ // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search -// #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree +// #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS #Data_Structure_I_Day_11_Tree // #Programming_Skills_I_Day_10_Linked_List_and_Tree #Udemy_Tree_Stack_Queue -// #Big_O_Time_O(N)_Space_O(H) #2023_10_04_Time_51_ms_(97.14%)_Space_46.1_MB_(68.29%) +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(H) +// #2025_03_26_Time_0_ms_(100.00%)_Space_59.10_MB_(43.48%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts b/src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts index 2489097..c99fb0e 100644 --- a/src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts +++ b/src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts @@ -1,10 +1,10 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Tree #Binary_Tree -// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Big_O_Time_O(N)_Space_O(N) -// #2023_10_04_Time_65_ms_(96.47%)_Space_45.9_MB_(80.00%) +// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Top_Interview_150_Binary_Tree_General +// #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_2_ms_(93.38%)_Space_60.17_MB_(76.57%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/readme.md b/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/readme.md new file mode 100644 index 0000000..65ba6b3 --- /dev/null +++ b/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/readme.md @@ -0,0 +1,29 @@ +106\. Construct Binary Tree from Inorder and Postorder Traversal + +Medium + +Given two integer arrays `inorder` and `postorder` where `inorder` is the inorder traversal of a binary tree and `postorder` is the postorder traversal of the same tree, construct and return _the binary tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg) + +**Input:** inorder = [9,3,15,20,7], postorder = [9,15,7,20,3] + +**Output:** [3,9,20,null,null,15,7] + +**Example 2:** + +**Input:** inorder = [-1], postorder = [-1] + +**Output:** [-1] + +**Constraints:** + +* `1 <= inorder.length <= 3000` +* `postorder.length == inorder.length` +* `-3000 <= inorder[i], postorder[i] <= 3000` +* `inorder` and `postorder` consist of **unique** values. +* Each value of `postorder` also appears in `inorder`. +* `inorder` is **guaranteed** to be the inorder traversal of the tree. +* `postorder` is **guaranteed** to be the postorder traversal of the tree. diff --git a/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.ts b/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.ts new file mode 100644 index 0000000..8188f36 --- /dev/null +++ b/src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.ts @@ -0,0 +1,42 @@ +// #Medium #Array #Hash_Table #Tree #Binary_Tree #Divide_and_Conquer +// #Top_Interview_150_Binary_Tree_General #2025_04_05_Time_1_ms_(98.78%)_Space_59.57_MB_(88.16%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function buildTree(inorder: number[], postorder: number[]): TreeNode | null { + const inIndex: number[] = [inorder.length - 1] + const postIndex: number[] = [postorder.length - 1] + return helper(inorder, postorder, inIndex, postIndex, Number.MAX_VALUE) +} + +function helper( + inorder: number[], + postorder: number[], + inIndex: number[], + postIndex: number[], + target: number, +): TreeNode | null { + if (inIndex[0] < 0 || inorder[inIndex[0]] === target) { + return null + } + const root = new TreeNode(postorder[postIndex[0]--]) + root.right = helper(inorder, postorder, inIndex, postIndex, root.val) + inIndex[0]-- + root.left = helper(inorder, postorder, inIndex, postIndex, target) + return root +} + +export { buildTree } diff --git a/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md b/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md new file mode 100644 index 0000000..09b5c6e --- /dev/null +++ b/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md @@ -0,0 +1,33 @@ +108\. Convert Sorted Array to Binary Search Tree + +Easy + +Given an integer array `nums` where the elements are sorted in **ascending order**, convert _it to a **height-balanced** binary search tree_. + +A **height-balanced** binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/18/btree1.jpg) + +**Input:** nums = [-10,-3,0,5,9] + +**Output:** [0,-3,9,-10,null,5] + +**Explanation:** [0,-10,5,null,-3,null,9] is also accepted: ![](https://assets.leetcode.com/uploads/2021/02/18/btree2.jpg) + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/18/btree.jpg) + +**Input:** nums = [1,3] + +**Output:** [3,1] + +**Explanation:** [1,3] and [3,1] are both a height-balanced BSTs. + +**Constraints:** + +* 1 <= nums.length <= 104 +* -104 <= nums[i] <= 104 +* `nums` is sorted in a **strictly increasing** order. diff --git a/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts b/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts new file mode 100644 index 0000000..05dcdea --- /dev/null +++ b/src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts @@ -0,0 +1,35 @@ +// #Easy #Top_Interview_Questions #Array #Tree #Binary_Tree #Binary_Search_Tree #Divide_and_Conquer +// #Data_Structure_II_Day_15_Tree #Level_2_Day_9_Binary_Search_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Divide_and_Conquer #2025_04_05_Time_0_ms_(100.00%)_Space_59.64_MB_(37.39%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function sortedArrayToBST(nums: number[]): TreeNode | null { + return makeTree(nums, 0, nums.length - 1) +} + +function makeTree(nums: number[], left: number, right: number): TreeNode | null { + if (left > right) { + return null + } + const mid = Math.floor((left + right) / 2) + const midNode = new TreeNode(nums[mid]) + midNode.left = makeTree(nums, left, mid - 1) + midNode.right = makeTree(nums, mid + 1, right) + return midNode +} + +export { sortedArrayToBST } diff --git a/src/main/ts/g0101_0200/s0112_path_sum/readme.md b/src/main/ts/g0101_0200/s0112_path_sum/readme.md new file mode 100644 index 0000000..132f5d6 --- /dev/null +++ b/src/main/ts/g0101_0200/s0112_path_sum/readme.md @@ -0,0 +1,36 @@ +112\. Path Sum + +Easy + +Given the `root` of a binary tree and an integer `targetSum`, return `true` if the tree has a **root-to-leaf** path such that adding up all the values along the path equals `targetSum`. + +A **leaf** is a node with no children. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/18/pathsum1.jpg) + +**Input:** root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22 + +**Output:** true + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg) + +**Input:** root = [1,2,3], targetSum = 5 + +**Output:** false + +**Example 3:** + +**Input:** root = [1,2], targetSum = 0 + +**Output:** false + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 5000]`. +* `-1000 <= Node.val <= 1000` +* `-1000 <= targetSum <= 1000` + \ No newline at end of file diff --git a/src/main/ts/g0101_0200/s0112_path_sum/solution.ts b/src/main/ts/g0101_0200/s0112_path_sum/solution.ts new file mode 100644 index 0000000..9a9f790 --- /dev/null +++ b/src/main/ts/g0101_0200/s0112_path_sum/solution.ts @@ -0,0 +1,29 @@ +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Data_Structure_I_Day_12_Tree +// #Top_Interview_150_Binary_Tree_General #2025_04_05_Time_0_ms_(100.00%)_Space_59.81_MB_(41.32%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function hasPathSum(root: TreeNode | null, targetSum: number): boolean { + if (root === null) { + return false + } + if (targetSum === root.val && root.left === null && root.right === null) { + return true + } + return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val) +} + +export { hasPathSum } diff --git a/src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts b/src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts index 449dae4..5315d0e 100644 --- a/src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts +++ b/src/main/ts/g0101_0200/s0114_flatten_binary_tree_to_linked_list/solution.ts @@ -1,10 +1,10 @@ // #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List -// #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(N) -// #2023_10_04_Time_55_ms_(90.66%)_Space_45.8_MB_(12.11%) +// #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N) +// #2025_03_26_Time_0_ms_(100.00%)_Space_58.93_MB_(15.60%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/readme.md b/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/readme.md new file mode 100644 index 0000000..2d6ede4 --- /dev/null +++ b/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/readme.md @@ -0,0 +1,37 @@ +117\. Populating Next Right Pointers in Each Node II + +Medium + +Given a binary tree + +struct Node { int val; Node \*left; Node \*right; Node \*next; } + +Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to `NULL`. + +Initially, all next pointers are set to `NULL`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2019/02/15/117_sample.png) + +**Input:** root = [1,2,3,4,5,null,7] + +**Output:** [1,#,2,3,#,4,5,7,#] + +**Explanation:** Given the above binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level. + +**Example 2:** + +**Input:** root = [] + +**Output:** [] + +**Constraints:** + +* The number of nodes in the tree is in the range `[0, 6000]`. +* `-100 <= Node.val <= 100` + +**Follow-up:** + +* You may only use constant extra space. +* The recursive approach is fine. You may assume implicit stack space does not count as extra space for this problem. diff --git a/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts b/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts new file mode 100644 index 0000000..84ed1bd --- /dev/null +++ b/src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.ts @@ -0,0 +1,52 @@ +// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Linked_List +// #Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search +// #Top_Interview_150_Binary_Tree_General #2025_04_07_Time_47_ms_(97.74%)_Space_61.19_MB_(53.38%) + +import { _Node } from '../../com_github_leetcode/_node' + +/** + * Definition for _Node. + * class _Node { + * val: number + * left: _Node | null + * right: _Node | null + * next: _Node | null + * + * constructor(val?: number, left?: _Node, right?: _Node, next?: _Node) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * this.next = (next===undefined ? null : next) + * } + * } + */ +function connect(root: _Node | null): _Node | null { + if (!root) { + return null + } + root.next = null + let dummyHead = new _Node() + let current: _Node | null = root + while (current) { + // reset dummyHead + dummyHead.next = null + let child = dummyHead + // traverse the current level + while (current) { + if (current.left) { + child.next = current.left + child = child.next + } + if (current.right) { + child.next = current.right + child = child.next + } + current = current.next + } + // move on to the next level + current = dummyHead.next + } + return root +} + +export { connect } diff --git a/src/main/ts/g0101_0200/s0120_triangle/readme.md b/src/main/ts/g0101_0200/s0120_triangle/readme.md new file mode 100644 index 0000000..6efc4a9 --- /dev/null +++ b/src/main/ts/g0101_0200/s0120_triangle/readme.md @@ -0,0 +1,37 @@ +120\. Triangle + +Medium + +Given a `triangle` array, return _the minimum path sum from top to bottom_. + +For each step, you may move to an adjacent number of the row below. More formally, if you are on index `i` on the current row, you may move to either index `i` or index `i + 1` on the next row. + +**Example 1:** + +**Input:** triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] + +**Output:** 11 + +**Explanation:** + + The triangle looks like: + 2 + 3 4 + 6 5 7 + 4 1 8 3 + The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above). + +**Example 2:** + +**Input:** triangle = [[-10]] + +**Output:** -10 + +**Constraints:** + +* `1 <= triangle.length <= 200` +* `triangle[0].length == 1` +* `triangle[i].length == triangle[i - 1].length + 1` +* -104 <= triangle[i][j] <= 104 + +**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle? diff --git a/src/main/ts/g0101_0200/s0120_triangle/solution.ts b/src/main/ts/g0101_0200/s0120_triangle/solution.ts new file mode 100644 index 0000000..d3e8a6d --- /dev/null +++ b/src/main/ts/g0101_0200/s0120_triangle/solution.ts @@ -0,0 +1,26 @@ +// #Medium #Array #Dynamic_Programming #Algorithm_I_Day_12_Dynamic_Programming +// #Dynamic_Programming_I_Day_13 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #2025_04_07_Time_0_ms_(100.00%)_Space_58.24_MB_(28.24%) + +function minimumTotal(triangle: number[][]): number { + if (!triangle || triangle.length === 0) { + return 0 + } + const rows = triangle.length + const cols = triangle[rows - 1].length + const dp: number[][] = Array.from({ length: rows }, () => Array(cols).fill(-10001)) + function dfs(row: number, col: number): number { + if (row >= triangle.length) { + return 0 + } + if (dp[row][col] !== -10001) { + return dp[row][col] + } + const sum = triangle[row][col] + Math.min(dfs(row + 1, col), dfs(row + 1, col + 1)) + dp[row][col] = sum + return sum + } + return dfs(0, 0) +} + +export { minimumTotal } diff --git a/src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts b/src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts index b91860d..e55644f 100644 --- a/src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts +++ b/src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(N)_Space_O(1) #2023_10_05_Time_56_ms_(99.56%)_Space_52.3_MB_(13.22%) +// #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1) +// #2025_03_26_Time_1_ms_(96.44%)_Space_65.83_MB_(26.02%) function maxProfit(prices: number[]): number { let buyPrice = prices[0] diff --git a/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md b/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md new file mode 100644 index 0000000..bdb1456 --- /dev/null +++ b/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md @@ -0,0 +1,38 @@ +122\. Best Time to Buy and Sell Stock II + +Medium + +You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day. + +On each day, you may decide to buy and/or sell the stock. You can only hold **at most one** share of the stock at any time. However, you can buy it then immediately sell it on the **same day**. + +Find and return _the **maximum** profit you can achieve_. + +**Example 1:** + +**Input:** prices = [7,1,5,3,6,4] + +**Output:** 7 + +**Explanation:** Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4. Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3. Total profit is 4 + 3 = 7. + +**Example 2:** + +**Input:** prices = [1,2,3,4,5] + +**Output:** 4 + +**Explanation:** Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4. Total profit is 4. + +**Example 3:** + +**Input:** prices = [7,6,4,3,1] + +**Output:** 0 + +**Explanation:** There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0. + +**Constraints:** + +* 1 <= prices.length <= 3 * 104 +* 0 <= prices[i] <= 104 diff --git a/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts b/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts new file mode 100644 index 0000000..ba2d3e3 --- /dev/null +++ b/src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts @@ -0,0 +1,15 @@ +// #Medium #Top_Interview_Questions #Array #Dynamic_Programming #Greedy #Dynamic_Programming_I_Day_7 +// #Udemy_Arrays #Top_Interview_150_Array/String +// #2025_04_07_Time_0_ms_(100.00%)_Space_54.88_MB_(71.79%) + +function maxProfit(prices: number[]): number { + let max = 0 + for (let i = 1; i < prices.length; i++) { + if (prices[i] > prices[i - 1]) { + max += prices[i] - prices[i - 1] + } + } + return max +} + +export { maxProfit } diff --git a/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md b/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md new file mode 100644 index 0000000..05c8547 --- /dev/null +++ b/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md @@ -0,0 +1,44 @@ +123\. Best Time to Buy and Sell Stock III + +Hard + +You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day. + +Find the maximum profit you can achieve. You may complete **at most two transactions**. + +**Note:** You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). + +**Example 1:** + +**Input:** prices = [3,3,5,0,0,3,1,4] + +**Output:** 6 + +**Explanation:** Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3. Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3. + +**Example 2:** + +**Input:** prices = [1,2,3,4,5] + +**Output:** 4 + +**Explanation:** Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4. Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again. + +**Example 3:** + +**Input:** prices = [7,6,4,3,1] + +**Output:** 0 + +**Explanation:** In this case, no transaction is done, i.e. max profit = 0. + +**Example 4:** + +**Input:** prices = [1] + +**Output:** 0 + +**Constraints:** + +* 1 <= prices.length <= 105 +* 0 <= prices[i] <= 105 diff --git a/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.ts b/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.ts new file mode 100644 index 0000000..a7a37ff --- /dev/null +++ b/src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.ts @@ -0,0 +1,18 @@ +// #Hard #Array #Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #2025_04_07_Time_5_ms_(85.07%)_Space_68.32_MB_(50.75%) + +function maxProfit(prices: number[]): number { + let firstBuy = Infinity + let secondBuy = Infinity + let firstSell = 0 + let secondSell = 0 + for (const price of prices) { + firstBuy = Math.min(firstBuy, price) + firstSell = Math.max(firstSell, price - firstBuy) + secondBuy = Math.min(secondBuy, price - firstSell) + secondSell = Math.max(secondSell, price - secondBuy) + } + return secondSell +} + +export { maxProfit } diff --git a/src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts b/src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts index 923d6db..887e1d2 100644 --- a/src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts +++ b/src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts @@ -1,10 +1,10 @@ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search -// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(N)_Space_O(N) -// #2023_10_05_Time_61_ms_(96.73%)_Space_51.2_MB_(97.45%) +// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General +// #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_2_ms_(71.11%)_Space_65.59_MB_(42.96%) import { TreeNode } from '../../com_github_leetcode/treenode' -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0101_0200/s0125_valid_palindrome/readme.md b/src/main/ts/g0101_0200/s0125_valid_palindrome/readme.md new file mode 100644 index 0000000..e522118 --- /dev/null +++ b/src/main/ts/g0101_0200/s0125_valid_palindrome/readme.md @@ -0,0 +1,36 @@ +125\. Valid Palindrome + +Easy + +A phrase is a **palindrome** if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. + +Given a string `s`, return `true` _if it is a **palindrome**, or_ `false` _otherwise_. + +**Example 1:** + +**Input:** s = "A man, a plan, a canal: Panama" + +**Output:** true + +**Explanation:** "amanaplanacanalpanama" is a palindrome. + +**Example 2:** + +**Input:** s = "race a car" + +**Output:** false + +**Explanation:** "raceacar" is not a palindrome. + +**Example 3:** + +**Input:** s = " " + +**Output:** true + +**Explanation:** s is an empty string "" after removing non-alphanumeric characters. Since an empty string reads the same forward and backward, it is a palindrome. + +**Constraints:** + +* 1 <= s.length <= 2 * 105 +* `s` consists only of printable ASCII characters. diff --git a/src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts b/src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts new file mode 100644 index 0000000..81df05d --- /dev/null +++ b/src/main/ts/g0101_0200/s0125_valid_palindrome/solution.ts @@ -0,0 +1,13 @@ +// #Easy #Top_Interview_Questions #String #Two_Pointers #Udemy_Two_Pointers +// #Top_Interview_150_Two_Pointers #2025_04_07_Time_0_ms_(100.00%)_Space_59.34_MB_(42.47%) + +function isPalindrome(s: string): boolean { + if (s.length < 2) { + return true + } + let sFormated = s.toLowerCase().replace(/[^a-zA-Z0-9]/g, '') + let reversed = sFormated.split('').reverse().join('').replace(',', '') + return sFormated === reversed +} + +export { isPalindrome } diff --git a/src/main/ts/g0101_0200/s0127_word_ladder/readme.md b/src/main/ts/g0101_0200/s0127_word_ladder/readme.md new file mode 100644 index 0000000..1d78d22 --- /dev/null +++ b/src/main/ts/g0101_0200/s0127_word_ladder/readme.md @@ -0,0 +1,37 @@ +127\. Word Ladder + +Hard + +A **transformation sequence** from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: + +* Every adjacent pair of words differs by a single letter. +* Every si for `1 <= i <= k` is in `wordList`. Note that `beginWord` does not need to be in `wordList`. +* sk == endWord + +Given two words, `beginWord` and `endWord`, and a dictionary `wordList`, return _the **number of words** in the **shortest transformation sequence** from_ `beginWord` _to_ `endWord`_, or_ `0` _if no such sequence exists._ + +**Example 1:** + +**Input:** beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] + +**Output:** 5 + +**Explanation:** One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is 5 words long. + +**Example 2:** + +**Input:** beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"] + +**Output:** 0 + +**Explanation:** The endWord "cog" is not in wordList, therefore there is no valid transformation sequence. + +**Constraints:** + +* `1 <= beginWord.length <= 10` +* `endWord.length == beginWord.length` +* `1 <= wordList.length <= 5000` +* `wordList[i].length == beginWord.length` +* `beginWord`, `endWord`, and `wordList[i]` consist of lowercase English letters. +* `beginWord != endWord` +* All the words in `wordList` are **unique**. diff --git a/src/main/ts/g0101_0200/s0127_word_ladder/solution.ts b/src/main/ts/g0101_0200/s0127_word_ladder/solution.ts new file mode 100644 index 0000000..521c4eb --- /dev/null +++ b/src/main/ts/g0101_0200/s0127_word_ladder/solution.ts @@ -0,0 +1,44 @@ +// #Hard #Top_Interview_Questions #String #Hash_Table #Breadth_First_Search +// #Graph_Theory_I_Day_12_Breadth_First_Search #Top_Interview_150_Graph_BFS +// #2025_04_07_Time_41_ms_(95.63%)_Space_63.50_MB_(82.78%) + +function ladderLength(beginWord: string, endWord: string, wordList: string[]): number { + const wordSet: Set = new Set(wordList) + if (!wordSet.has(endWord)) { + return 0 + } + let beginSet: Set = new Set([beginWord]) + let endSet: Set = new Set([endWord]) + const visited: Set = new Set() + let len = 1 + const wordLen = beginWord.length + while (beginSet.size > 0 && endSet.size > 0) { + if (beginSet.size > endSet.size) { + ;[beginSet, endSet] = [endSet, beginSet] + } + const tempSet: Set = new Set() + for (const word of beginSet) { + const chars = word.split('') + for (let i = 0; i < wordLen; i++) { + const oldChar = chars[i] + for (let c = 97; c <= 122; c++) { + chars[i] = String.fromCharCode(c) + const nextWord = chars.join('') + if (endSet.has(nextWord)) { + return len + 1 + } + if (!visited.has(nextWord) && wordSet.has(nextWord)) { + tempSet.add(nextWord) + visited.add(nextWord) + } + } + chars[i] = oldChar + } + } + beginSet = tempSet + len++ + } + return 0 +} + +export { ladderLength } diff --git a/src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts b/src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts index aa55676..6a78603 100644 --- a/src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts +++ b/src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts @@ -1,17 +1,21 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find -// #Big_O_Time_O(N_log_N)_Space_O(1) #2023_10_05_Time_92_ms_(93.69%)_Space_64_MB_(30.13%) +// #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1) +// #2025_03_26_Time_34_ms_(90.07%)_Space_82.70_MB_(18.54%) function longestConsecutive(nums: number[]): number { - const set = new Set(nums) - let max = 0 - for (const num of nums) { - if (set.has(num + 1)) continue - let counter = 1, - current = num - while (set.has(--current)) counter++ - max = Math.max(counter, max) + let sset = new Set(nums) + let maxLen = 0 + for (let num of sset) { + // check its start of the sequence + if (!sset.has(num - 1)) { + let len = 0 + while (sset.has(num + len)) { + len += 1 + } + maxLen = Math.max(maxLen, len) + } } - return max + return maxLen } export { longestConsecutive } diff --git a/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/readme.md b/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/readme.md new file mode 100644 index 0000000..c9d9fca --- /dev/null +++ b/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/readme.md @@ -0,0 +1,39 @@ +129\. Sum Root to Leaf Numbers + +Medium + +You are given the `root` of a binary tree containing digits from `0` to `9` only. + +Each root-to-leaf path in the tree represents a number. + +* For example, the root-to-leaf path `1 -> 2 -> 3` represents the number `123`. + +Return _the total sum of all root-to-leaf numbers_. Test cases are generated so that the answer will fit in a **32-bit** integer. + +A **leaf** node is a node with no children. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/num1tree.jpg) + +**Input:** root = [1,2,3] + +**Output:** 25 + +**Explanation:** The root-to-leaf path `1->2` represents the number `12`. The root-to-leaf path `1->3` represents the number `13`. Therefore, sum = 12 + 13 = `25`. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/19/num2tree.jpg) + +**Input:** root = [4,9,0,5,1] + +**Output:** 1026 + +**Explanation:** The root-to-leaf path `4->9->5` represents the number 495. The root-to-leaf path `4->9->1` represents the number 491. The root-to-leaf path `4->0` represents the number 40. Therefore, sum = 495 + 491 + 40 = `1026`. + +**Constraints:** + +* The number of nodes in the tree is in the range `[1, 1000]`. +* `0 <= Node.val <= 9` +* The depth of the tree will not exceed `10`. diff --git a/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.ts b/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.ts new file mode 100644 index 0000000..ca97250 --- /dev/null +++ b/src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.ts @@ -0,0 +1,41 @@ +// #Medium #Depth_First_Search #Tree #Binary_Tree #Top_Interview_150_Binary_Tree_General +// #2025_04_07_Time_0_ms_(100.00%)_Space_57.72_MB_(19.07%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function sumNumbers(root: TreeNode | null): number { + let sum = 0 + function recurseSum(node: TreeNode | null, curNum: number): void { + if (node === null) { + return + } + const newNum = 10 * curNum + node.val + if (node.left === null && node.right === null) { + sum += newNum + return + } + if (node.left !== null) { + recurseSum(node.left, newNum) + } + if (node.right !== null) { + recurseSum(node.right, newNum) + } + } + recurseSum(root, 0) + return sum +} + +export { sumNumbers } diff --git a/src/main/ts/g0101_0200/s0130_surrounded_regions/readme.md b/src/main/ts/g0101_0200/s0130_surrounded_regions/readme.md new file mode 100644 index 0000000..6b12aaa --- /dev/null +++ b/src/main/ts/g0101_0200/s0130_surrounded_regions/readme.md @@ -0,0 +1,30 @@ +130\. Surrounded Regions + +Medium + +Given an `m x n` matrix `board` containing `'X'` and `'O'`, _capture all regions that are 4-directionally surrounded by_ `'X'`. + +A region is **captured** by flipping all `'O'`s into `'X'`s in that surrounded region. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/19/xogrid.jpg) + +**Input:** board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]] + +**Output:** [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]] + +**Explanation:** Surrounded regions should not be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically. + +**Example 2:** + +**Input:** board = [["X"]] + +**Output:** [["X"]] + +**Constraints:** + +* `m == board.length` +* `n == board[i].length` +* `1 <= m, n <= 200` +* `board[i][j]` is `'X'` or `'O'`. \ No newline at end of file diff --git a/src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts b/src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts new file mode 100644 index 0000000..db3fb81 --- /dev/null +++ b/src/main/ts/g0101_0200/s0130_surrounded_regions/solution.ts @@ -0,0 +1,52 @@ +// #Medium #Top_Interview_Questions #Array #Depth_First_Search #Breadth_First_Search #Matrix +// #Union_Find #Algorithm_II_Day_8_Breadth_First_Search_Depth_First_Search +// #Top_Interview_150_Graph_General #2025_04_16_Time_1_ms_(99.18%)_Space_59.64_MB_(82.97%) + +/** + Do not return anything, modify board in-place instead. + */ +function solve(board: string[][]): void { + if (board.length === 0) { + return + } + const rows = board.length + const cols = board[0].length + const dfs = (board: string[][], row: number, col: number): void => { + if (row < 0 || row >= rows || col < 0 || col >= cols || board[row][col] !== 'O') { + return + } + board[row][col] = '#' + dfs(board, row + 1, col) + dfs(board, row - 1, col) + dfs(board, row, col + 1) + dfs(board, row, col - 1) + } + for (let i = 0; i < cols; i++) { + if (board[0][i] === 'O') { + dfs(board, 0, i) + } + if (board[rows - 1][i] === 'O') { + dfs(board, rows - 1, i) + } + } + for (let i = 0; i < rows; i++) { + if (board[i][0] === 'O') { + dfs(board, i, 0) + } + if (board[i][cols - 1] === 'O') { + dfs(board, i, cols - 1) + } + } + for (let i = 0; i < rows; i++) { + for (let j = 0; j < cols; j++) { + if (board[i][j] === 'O') { + board[i][j] = 'X' + } + if (board[i][j] === '#') { + board[i][j] = 'O' + } + } + } +} + +export { solve } diff --git a/src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts b/src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts index 32dca7c..406ce3d 100644 --- a/src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts +++ b/src/main/ts/g0101_0200/s0131_palindrome_partitioning/solution.ts @@ -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) -// #2023_10_05_Time_203_ms_(99.22%)_Space_81.9_MB_(42.19%) +// #2025_03_26_Time_13_ms_(94.96%)_Space_82.19_MB_(40.76%) function partition(s: string): string[][] { const ans: string[][] = [] diff --git a/src/main/ts/g0101_0200/s0133_clone_graph/readme.md b/src/main/ts/g0101_0200/s0133_clone_graph/readme.md new file mode 100644 index 0000000..97ec332 --- /dev/null +++ b/src/main/ts/g0101_0200/s0133_clone_graph/readme.md @@ -0,0 +1,69 @@ +133\. Clone Graph + +Medium + +Given a reference of a node in a **[connected](https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph)** undirected graph. + +Return a [**deep copy**](https://en.wikipedia.org/wiki/Object_copying#Deep_copy) (clone) of the graph. + +Each node in the graph contains a value (`int`) and a list (`List[Node]`) of its neighbors. + +class Node { public int val; public List neighbors; } + +**Test case format:** + +For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with `val == 1`, the second node with `val == 2`, and so on. The graph is represented in the test case using an adjacency list. + +**An adjacency list** is a collection of unordered **lists** used to represent a finite graph. Each list describes the set of neighbors of a node in the graph. + +The given node will always be the first node with `val = 1`. You must return the **copy of the given node** as a reference to the cloned graph. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2019/11/04/133_clone_graph_question.png) + +**Input:** adjList = [[2,4],[1,3],[2,4],[1,3]] + +**Output:** [[2,4],[1,3],[2,4],[1,3]] + +**Explanation:** + + There are 4 nodes in the graph. + 1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). + 2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). + 3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). + 4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/01/07/graph.png) + +**Input:** adjList = [[]] + +**Output:** [[]] + +**Explanation:** Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors. + +**Example 3:** + +**Input:** adjList = [] + +**Output:** [] + +**Explanation:** This an empty graph, it does not have any nodes. + +**Example 4:** + +![](https://assets.leetcode.com/uploads/2020/01/07/graph-1.png) + +**Input:** adjList = [[2],[1]] + +**Output:** [[2],[1]] + +**Constraints:** + +* The number of nodes in the graph is in the range `[0, 100]`. +* `1 <= Node.val <= 100` +* `Node.val` is unique for each node. +* There are no repeated edges and no self-loops in the graph. +* The Graph is connected and all nodes can be visited starting from the given node. \ No newline at end of file diff --git a/src/main/ts/g0101_0200/s0133_clone_graph/solution.ts b/src/main/ts/g0101_0200/s0133_clone_graph/solution.ts new file mode 100644 index 0000000..171143e --- /dev/null +++ b/src/main/ts/g0101_0200/s0133_clone_graph/solution.ts @@ -0,0 +1,53 @@ +// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Graph #Udemy_Graph +// #Top_Interview_150_Graph_General #2025_04_16_Time_48_ms_(82.94%)_Space_58.20_MB_(70.18%) + +class Node { + val: number + neighbors: Node[] + + constructor(val: number = 0, neighbors: Node[] = []) { + this.val = val + this.neighbors = neighbors + } + + toString(): string { + const result: string[] = [] + for (const node of this.neighbors) { + if (node.neighbors.length === 0) { + result.push(node.val.toString()) + } else { + const result2: string[] = [] + for (const nodeItem of node.neighbors) { + result2.push(nodeItem.val.toString()) + } + result.push(`[${result2.join(',')}]`) + } + } + return `[${result.join(',')}]` + } +} + +function cloneGraph(node: Node | null): Node | null { + const processedNodes = new Map() + return cloneGraphHelper(node, processedNodes) +} + +function cloneGraphHelper(node: Node | null, processedNodes: Map): Node | null { + if (node === null) { + return null + } + if (processedNodes.has(node)) { + return processedNodes.get(node)! + } + const newNode = new Node(node.val) + processedNodes.set(node, newNode) + for (const neighbor of node.neighbors) { + const clonedNeighbor = cloneGraphHelper(neighbor, processedNodes) + if (clonedNeighbor !== null) { + newNode.neighbors.push(clonedNeighbor) + } + } + return newNode +} + +export { Node, cloneGraph } diff --git a/src/main/ts/g0101_0200/s0134_gas_station/readme.md b/src/main/ts/g0101_0200/s0134_gas_station/readme.md new file mode 100644 index 0000000..30790f3 --- /dev/null +++ b/src/main/ts/g0101_0200/s0134_gas_station/readme.md @@ -0,0 +1,47 @@ +134\. Gas Station + +Medium + +There are `n` gas stations along a circular route, where the amount of gas at the ith station is `gas[i]`. + +You have a car with an unlimited gas tank and it costs `cost[i]` of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. + +Given two integer arrays `gas` and `cost`, return _the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return_ `-1`. If there exists a solution, it is **guaranteed** to be **unique** + +**Example 1:** + +**Input:** gas = [1,2,3,4,5], cost = [3,4,5,1,2] + +**Output:** 3 + +**Explanation:** + + Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4 + Travel to station 4. Your tank = 4 - 1 + 5 = 8 + Travel to station 0. Your tank = 8 - 2 + 1 = 7 + Travel to station 1. Your tank = 7 - 3 + 2 = 6 + Travel to station 2. Your tank = 6 - 4 + 3 = 5 + Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3. + Therefore, return 3 as the starting index. + +**Example 2:** + +**Input:** gas = [2,3,4], cost = [3,4,3] + +**Output:** -1 + +**Explanation:** + + You can't start at station 0 or 1, as there is not enough gas to travel to the next station. + Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4 + Travel to station 0. Your tank = 4 - 3 + 2 = 3 + Travel to station 1. Your tank = 3 - 3 + 3 = 3 + You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3. + Therefore, you can't travel around the circuit once no matter where you start. + +**Constraints:** + +* `gas.length == n` +* `cost.length == n` +* 1 <= n <= 105 +* 0 <= gas[i], cost[i] <= 104 diff --git a/src/main/ts/g0101_0200/s0134_gas_station/solution.ts b/src/main/ts/g0101_0200/s0134_gas_station/solution.ts new file mode 100644 index 0000000..4706167 --- /dev/null +++ b/src/main/ts/g0101_0200/s0134_gas_station/solution.ts @@ -0,0 +1,20 @@ +// #Medium #Top_Interview_Questions #Array #Greedy #Top_Interview_150_Array/String +// #2025_04_07_Time_0_ms_(100.00%)_Space_66.31_MB_(63.11%) + +function canCompleteCircuit(gas: number[], cost: number[]): number { + let index = 0 + let total = 0 + let current = 0 + for (let i = 0; i < gas.length; i++) { + const balance = gas[i] - cost[i] + total += balance + current += balance + if (current < 0) { + index = i + 1 + current = 0 + } + } + return total >= 0 ? index : -1 +} + +export { canCompleteCircuit } diff --git a/src/main/ts/g0101_0200/s0135_candy/readme.md b/src/main/ts/g0101_0200/s0135_candy/readme.md new file mode 100644 index 0000000..f609f87 --- /dev/null +++ b/src/main/ts/g0101_0200/s0135_candy/readme.md @@ -0,0 +1,34 @@ +135\. Candy + +Hard + +There are `n` children standing in a line. Each child is assigned a rating value given in the integer array `ratings`. + +You are giving candies to these children subjected to the following requirements: + +* Each child must have at least one candy. +* Children with a higher rating get more candies than their neighbors. + +Return _the minimum number of candies you need to have to distribute the candies to the children_. + +**Example 1:** + +**Input:** ratings = [1,0,2] + +**Output:** 5 + +**Explanation:** You can allocate to the first, second and third child with 2, 1, 2 candies respectively. + +**Example 2:** + +**Input:** ratings = [1,2,2] + +**Output:** 4 + +**Explanation:** You can allocate to the first, second and third child with 1, 2, 1 candies respectively. The third child gets 1 candy because it satisfies the above two conditions. + +**Constraints:** + +* `n == ratings.length` +* 1 <= n <= 2 * 104 +* 0 <= ratings[i] <= 2 * 104 diff --git a/src/main/ts/g0101_0200/s0135_candy/solution.ts b/src/main/ts/g0101_0200/s0135_candy/solution.ts new file mode 100644 index 0000000..534522d --- /dev/null +++ b/src/main/ts/g0101_0200/s0135_candy/solution.ts @@ -0,0 +1,20 @@ +// #Hard #Array #Greedy #Top_Interview_150_Array/String +// #2025_04_07_Time_2_ms_(96.15%)_Space_61.00_MB_(33.47%) + +function candy(ratings: number[]): number { + const n = ratings.length + const candies: number[] = new Array(n).fill(1) + for (let i = 0; i < n - 1; i++) { + if (ratings[i + 1] > ratings[i]) { + candies[i + 1] = candies[i] + 1 + } + } + for (let i = n - 1; i > 0; i--) { + if (ratings[i - 1] > ratings[i] && candies[i - 1] < candies[i] + 1) { + candies[i - 1] = candies[i] + 1 + } + } + return candies.reduce((sum, c) => sum + c, 0) +} + +export { candy } diff --git a/src/main/ts/g0101_0200/s0136_single_number/solution.ts b/src/main/ts/g0101_0200/s0136_single_number/solution.ts index 4f569f0..886fb23 100644 --- a/src/main/ts/g0101_0200/s0136_single_number/solution.ts +++ b/src/main/ts/g0101_0200/s0136_single_number/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(N)_Space_O(1) #2023_10_05_Time_56_ms_(85.48%)_Space_45.6_MB_(63.32%) +// #LeetCode_75_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_03_26_Time_1_ms_(78.27%)_Space_58.44_MB_(41.08%) function singleNumber(nums: number[]): number { let ans = 0 diff --git a/src/main/ts/g0101_0200/s0137_single_number_ii/readme.md b/src/main/ts/g0101_0200/s0137_single_number_ii/readme.md new file mode 100644 index 0000000..91053fc --- /dev/null +++ b/src/main/ts/g0101_0200/s0137_single_number_ii/readme.md @@ -0,0 +1,25 @@ +137\. Single Number II + +Medium + +Given an integer array `nums` where every element appears **three times** except for one, which appears **exactly once**. _Find the single element and return it_. + +You must implement a solution with a linear runtime complexity and use only constant extra space. + +**Example 1:** + +**Input:** nums = [2,2,3,2] + +**Output:** 3 + +**Example 2:** + +**Input:** nums = [0,1,0,1,0,1,99] + +**Output:** 99 + +**Constraints:** + +* 1 <= nums.length <= 3 * 104 +* -231 <= nums[i] <= 231 - 1 +* Each element in `nums` appears exactly **three times** except for one element which appears **once**. diff --git a/src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts b/src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts new file mode 100644 index 0000000..7c7ff33 --- /dev/null +++ b/src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts @@ -0,0 +1,14 @@ +// #Medium #Array #Bit_Manipulation #Top_Interview_150_Bit_Manipulation +// #2025_04_07_Time_0_ms_(100.00%)_Space_59.11_MB_(24.16%) + +function singleNumber(nums: number[]): number { + let ones = 0 + let twos = 0 + for (const num of nums) { + ones = (ones ^ num) & ~twos + twos = (twos ^ num) & ~ones + } + return ones +} + +export { singleNumber } diff --git a/src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts b/src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts index cabd0ff..0e9542c 100644 --- a/src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts +++ b/src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts @@ -1,10 +1,10 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Linked_List -// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(N) -// #2023_10_06_Time_52_ms_(88.27%)_Space_44.7_MB_(72.42%) +// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_49_ms_(72.42%)_Space_55.82_MB_(59.25%) import { Node } from '../../com_github_leetcode/node' -/* +/** * Definition for Node. * class Node { * val: number diff --git a/src/main/ts/g0101_0200/s0139_word_break/solution.ts b/src/main/ts/g0101_0200/s0139_word_break/solution.ts index 00ccbdc..9088d59 100644 --- a/src/main/ts/g0101_0200/s0139_word_break/solution.ts +++ b/src/main/ts/g0101_0200/s0139_word_break/solution.ts @@ -1,18 +1,22 @@ // #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 #Big_O_Time_O(M+max*N)_Space_O(M+N+max) -// #2023_10_06_Time_56_ms_(88.44%)_Space_44.1_MB_(93.39%) +// #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_03_26_Time_4_ms_(76.41%)_Space_58.68_MB_(22.70%) function wordBreak(s: string, wordDict: string[]): boolean { const dp: boolean[] = [] - for (let i = 0; i <= s.length; i++) dp.push(false) + for (let i = 0; i <= s.length; i++) { + dp.push(false) + } dp[s.length] = true for (let j = s.length - 1; j >= 0; j--) { for (const word of wordDict) { if (s.slice(j, j + word.length) === word && j + word.length <= s.length) { dp[j] = dp[j + word.length] } - if (dp[j]) break + if (dp[j]) { + break + } } } return dp[0] diff --git a/src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts b/src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts index 56e2c6b..f2d1459 100644 --- a/src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts +++ b/src/main/ts/g0101_0200/s0141_linked_list_cycle/solution.ts @@ -1,10 +1,10 @@ // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List -// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1) -// #2023_10_06_Time_59_ms_(93.37%)_Space_45.2_MB_(76.28%) +// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_47_ms_(89.37%)_Space_58.35_MB_(35.02%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number @@ -20,7 +20,9 @@ function hasCycle(head: ListNode | null): boolean { while (fast?.next) { head = head.next fast = fast.next.next - if (head === fast) return true + if (head === fast) { + return true + } } return false } diff --git a/src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts b/src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts index 645027c..481a1b1 100644 --- a/src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts +++ b/src/main/ts/g0101_0200/s0142_linked_list_cycle_ii/solution.ts @@ -1,10 +1,10 @@ // #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List // #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List -// #Big_O_Time_O(N)_Space_O(1) #2023_10_06_Time_59_ms_(94.39%)_Space_45.5_MB_(60.71%) +// #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_51_ms_(76.99%)_Space_59.02_MB_(13.39%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number @@ -18,7 +18,9 @@ import { ListNode } from '../../com_github_leetcode/listnode' function detectCycle(head: ListNode | null): ListNode | null { const set = new Set() while (head) { - if (set.has(head)) return head + if (set.has(head)) { + return head + } set.add(head) head = head.next } diff --git a/src/main/ts/g0101_0200/s0146_lru_cache/solution.ts b/src/main/ts/g0101_0200/s0146_lru_cache/solution.ts index 76159e6..9730a72 100644 --- a/src/main/ts/g0101_0200/s0146_lru_cache/solution.ts +++ b/src/main/ts/g0101_0200/s0146_lru_cache/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List -// #Doubly_Linked_List #Udemy_Linked_List #Big_O_Time_O(1)_Space_O(capacity) -// #2023_10_06_Time_473_ms_(94.72%)_Space_125.1_MB_(69.62%) +// #Doubly_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List +// #Big_O_Time_O(1)_Space_O(capacity) #2025_03_26_Time_97_ms_(81.52%)_Space_108.56_MB_(48.32%) interface ICacheNode { key: number diff --git a/src/main/ts/g0101_0200/s0148_sort_list/solution.ts b/src/main/ts/g0101_0200/s0148_sort_list/solution.ts index 4151a30..7506769 100644 --- a/src/main/ts/g0101_0200/s0148_sort_list/solution.ts +++ b/src/main/ts/g0101_0200/s0148_sort_list/solution.ts @@ -1,10 +1,10 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List -// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Big_O_Time_O(log(N))_Space_O(log(N)) -// #2023_10_08_Time_141_ms_(97.14%)_Space_71.9_MB_(47.35%) +// #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_03_26_Time_36_ms_(44.94%)_Space_86.58_MB_(5.99%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number @@ -17,7 +17,9 @@ import { ListNode } from '../../com_github_leetcode/listnode' */ function sortList(head: ListNode | null): ListNode | null { - if (!head) return null + if (!head) { + return null + } let array = [] while (head) { array.push([head, head.val]) diff --git a/src/main/ts/g0101_0200/s0149_max_points_on_a_line/readme.md b/src/main/ts/g0101_0200/s0149_max_points_on_a_line/readme.md new file mode 100644 index 0000000..99b2528 --- /dev/null +++ b/src/main/ts/g0101_0200/s0149_max_points_on_a_line/readme.md @@ -0,0 +1,28 @@ +149\. Max Points on a Line + +Hard + +Given an array of `points` where points[i] = [xi, yi] represents a point on the **X-Y** plane, return _the maximum number of points that lie on the same straight line_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/25/plane1.jpg) + +**Input:** points = [[1,1],[2,2],[3,3]] + +**Output:** 3 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/25/plane2.jpg) + +**Input:** points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] + +**Output:** 4 + +**Constraints:** + +* `1 <= points.length <= 300` +* `points[i].length == 2` +* -104 <= xi, yi <= 104 +* All the `points` are **unique**. diff --git a/src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts b/src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts new file mode 100644 index 0000000..ce5d847 --- /dev/null +++ b/src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts @@ -0,0 +1,31 @@ +// #Hard #Top_Interview_Questions #Array #Hash_Table #Math #Geometry #Algorithm_II_Day_21_Others +// #Top_Interview_150_Math #2025_04_08_Time_9_ms_(97.18%)_Space_61.36_MB_(70.42%) + +function maxPoints(points: number[][]): number { + if (points.length <= 2) { + return points.length + } + const map = new Map() + let result: number = 0 + for (let i = 0; i < points.length; i++) { + const [x0, y0] = points[i] + for (let j = i + 1; j < points.length; j++) { + const [x1, y1] = points[j] + let m: number + if (x0 === x1) { + m = Number.MAX_VALUE + } else if (y0 === y1) { + m = 0 + } else { + m = (y0 - y1) / (x0 - x1) + } + const nextM: number = map.has(m) ? map.get(m) + 1 : 2 + map.set(m, nextM) + result = Math.max(result, nextM) + } + map.clear() + } + return result +} + +export { maxPoints } diff --git a/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md b/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md new file mode 100644 index 0000000..1369eac --- /dev/null +++ b/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md @@ -0,0 +1,48 @@ +150\. Evaluate Reverse Polish Notation + +Medium + +Evaluate the value of an arithmetic expression in [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). + +Valid operators are `+`, `-`, `*`, and `/`. Each operand may be an integer or another expression. + +**Note** that division between two integers should truncate toward zero. + +It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation. + +**Example 1:** + +**Input:** tokens = ["2","1","+","3","\*"] + +**Output:** 9 + +**Explanation:** ((2 + 1) \* 3) = 9 + +**Example 2:** + +**Input:** tokens = ["4","13","5","/","+"] + +**Output:** 6 + +**Explanation:** (4 + (13 / 5)) = 6 + +**Example 3:** + +**Input:** tokens = ["10","6","9","3","+","-11","\*","/","\*","17","+","5","+"] + +**Output:** 22 + +**Explanation:** + + ((10 \* (6 / ((9 + 3) \* -11))) + 17) + 5 + = ((10 \* (6 / (12 \* -11))) + 17) + 5 + = ((10 \* (6 / -132)) + 17) + 5 + = ((10 \* 0) + 17) + 5 + = (0 + 17) + 5 + = 17 + 5 + = 22 + +**Constraints:** + +* 1 <= tokens.length <= 104 +* `tokens[i]` is either an operator: `"+"`, `"-"`, `"*"`, or `"/"`, or an integer in the range `[-200, 200]`. diff --git a/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts b/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts new file mode 100644 index 0000000..2ac3ed8 --- /dev/null +++ b/src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts @@ -0,0 +1,26 @@ +// #Medium #Top_Interview_Questions #Array #Math #Stack #Programming_Skills_II_Day_3 +// #Top_Interview_150_Stack #2025_04_08_Time_1_ms_(97.48%)_Space_60.14_MB_(28.30%) + +function evalRPN(tokens: string[]): number { + const numberStack: number[] = [] + const isOperator = (val: string): boolean => val === '+' || val === '-' || val === '*' || val === '/' + for (let token of tokens) { + if (isOperator(token)) { + const right = numberStack.pop() as number + const left = numberStack.pop() as number + if (token === '+') { + numberStack.push(left + right) + } else if (token === '-') { + numberStack.push(left - right) + } else if (token === '*') { + numberStack.push(left * right) + } else if (token === '/') { + const result = left / right + numberStack.push(result < 0 ? Math.ceil(result) : Math.floor(result)) + } + } else numberStack.push(+token) + } + return numberStack.pop() || 0 +} + +export { evalRPN } diff --git a/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/readme.md b/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/readme.md new file mode 100644 index 0000000..1f89300 --- /dev/null +++ b/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/readme.md @@ -0,0 +1,53 @@ +151\. Reverse Words in a String + +Medium + +Given an input string `s`, reverse the order of the **words**. + +A **word** is defined as a sequence of non-space characters. The **words** in `s` will be separated by at least one space. + +Return _a string of the words in reverse order concatenated by a single space._ + +**Note** that `s` may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces. + +**Example 1:** + +**Input:** s = "the sky is blue" + +**Output:** "blue is sky the" + +**Example 2:** + +**Input:** s = " hello world " + +**Output:** "world hello" + +**Explanation:** Your reversed string should not contain leading or trailing spaces. + +**Example 3:** + +**Input:** s = "a good example" + +**Output:** "example good a" + +**Explanation:** You need to reduce multiple spaces between two words to a single space in the reversed string. + +**Example 4:** + +**Input:** s = " Bob Loves Alice " + +**Output:** "Alice Loves Bob" + +**Example 5:** + +**Input:** s = "Alice does not even like bob" + +**Output:** "bob like even not does Alice" + +**Constraints:** + +* 1 <= s.length <= 104 +* `s` contains English letters (upper-case and lower-case), digits, and spaces `' '`. +* There is **at least one** word in `s`. + +**Follow-up:** If the string data type is mutable in your language, can you solve it **in-place** with `O(1)` extra space? diff --git a/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts b/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts new file mode 100644 index 0000000..b0faaf3 --- /dev/null +++ b/src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts @@ -0,0 +1,13 @@ +// #Medium #String #Two_Pointers #LeetCode_75_Array/String #Udemy_Strings +// #Top_Interview_150_Array/String #2025_04_08_Time_0_ms_(100.00%)_Space_57.70_MB_(48.75%) + +function reverseWords(s: string): string { + return s + ?.trim() + ?.replaceAll(/\s{2,}/g, ' ') + ?.split(' ') + ?.reverse() + .join(' ') +} + +export { reverseWords } diff --git a/src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts b/src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts index 111705f..64b02b9 100644 --- a/src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts +++ b/src/main/ts/g0101_0200/s0152_maximum_product_subarray/solution.ts @@ -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) #2023_10_08_Time_53_ms_(87.50%)_Space_44.6_MB_(63.86%) +// #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_0_ms_(100.00%)_Space_58.34_MB_(23.08%) function maxProduct(nums: number[]): number { let cMin = 1 diff --git a/src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts b/src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts index c8c4ea3..379c402 100644 --- a/src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts +++ b/src/main/ts/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/solution.ts @@ -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 #Big_O_Time_O(log_N)_Space_O(log_N) -// #2023_10_08_Time_42_ms_(98.87%)_Space_42.9_MB_(84.75%) +// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Top_Interview_150_Binary_Search +// #Big_O_Time_O(log_N)_Space_O(log_N) #2025_03_26_Time_0_ms_(100.00%)_Space_55.42_MB_(40.88%) function findMin(nums: number[]): number { return Math.min(...nums) diff --git a/src/main/ts/g0101_0200/s0155_min_stack/solution.ts b/src/main/ts/g0101_0200/s0155_min_stack/solution.ts index 9912e0f..9c29aa2 100644 --- a/src/main/ts/g0101_0200/s0155_min_stack/solution.ts +++ b/src/main/ts/g0101_0200/s0155_min_stack/solution.ts @@ -1,6 +1,7 @@ -// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design +// #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 #Big_O_Time_O(1)_Space_O(N) #2023_10_08_Time_84_ms_(92.72%)_Space_51.8_MB_(30.46%) +// #Udemy_Design #Top_Interview_150_Stack #Big_O_Time_O(1)_Space_O(N) +// #2025_03_26_Time_5_ms_(99.10%)_Space_65.70_MB_(50.04%) class MinStack { stack: number[] diff --git a/src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts b/src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts index 7c4e990..632dcbc 100644 --- a/src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts +++ b/src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts @@ -1,10 +1,10 @@ // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List // #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1) -// #2023_10_08_Time_67_ms_(93.58%)_Space_50.8_MB_(40.54%) +// #2025_03_26_Time_65_ms_(72.36%)_Space_63.62_MB_(41.12%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number diff --git a/src/main/ts/g0101_0200/s0162_find_peak_element/readme.md b/src/main/ts/g0101_0200/s0162_find_peak_element/readme.md new file mode 100644 index 0000000..abe70d7 --- /dev/null +++ b/src/main/ts/g0101_0200/s0162_find_peak_element/readme.md @@ -0,0 +1,33 @@ +162\. Find Peak Element + +Medium + +A peak element is an element that is strictly greater than its neighbors. + +Given an integer array `nums`, find a peak element, and return its index. If the array contains multiple peaks, return the index to **any of the peaks**. + +You may imagine that `nums[-1] = nums[n] = -∞`. + +You must write an algorithm that runs in `O(log n)` time. + +**Example 1:** + +**Input:** nums = [1,2,3,1] + +**Output:** 2 + +**Explanation:** 3 is a peak element and your function should return the index number 2. + +**Example 2:** + +**Input:** nums = [1,2,1,3,5,6,4] + +**Output:** 5 + +**Explanation:** Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6. + +**Constraints:** + +* `1 <= nums.length <= 1000` +* -231 <= nums[i] <= 231 - 1 +* `nums[i] != nums[i + 1]` for all valid `i`. diff --git a/src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts b/src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts new file mode 100644 index 0000000..1df4ccd --- /dev/null +++ b/src/main/ts/g0101_0200/s0162_find_peak_element/solution.ts @@ -0,0 +1,19 @@ +// #Medium #Top_Interview_Questions #Array #Binary_Search #LeetCode_75_Binary_Search +// #Algorithm_II_Day_2_Binary_Search #Binary_Search_II_Day_12 #Top_Interview_150_Binary_Search +// #2025_04_08_Time_0_ms_(100.00%)_Space_55.40_MB_(60.85%) + +function findPeakElement(nums: number[]): number { + let start = 0 + let end = nums.length - 1 + while (start < end) { + const mid = start + Math.floor((end - start) / 2) + if (nums[mid + 1] > nums[mid]) { + start = mid + 1 + } else { + end = mid + } + } + return start +} + +export { findPeakElement } diff --git a/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md b/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md new file mode 100644 index 0000000..238d405 --- /dev/null +++ b/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md @@ -0,0 +1,41 @@ +167\. Two Sum II - Input Array Is Sorted + +Easy + +Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. + +Return _the indices of the two numbers,_ index1 _and_ index2_, **added by one** as an integer array_ [index1, index2] _of length 2._ + +The tests are generated such that there is **exactly one solution**. You **may not** use the same element twice. + +**Example 1:** + +**Input:** numbers = [2,7,11,15], target = 9 + +**Output:** [1,2] + +**Explanation:** The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2]. + +**Example 2:** + +**Input:** numbers = [2,3,4], target = 6 + +**Output:** [1,3] + +**Explanation:** The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3]. + +**Example 3:** + +**Input:** numbers = [\-1,0], target = -1 + +**Output:** [1,2] + +**Explanation:** The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2]. + +**Constraints:** + +* 2 <= numbers.length <= 3 * 104 +* `-1000 <= numbers[i] <= 1000` +* `numbers` is sorted in **non-decreasing order**. +* `-1000 <= target <= 1000` +* The tests are generated such that there is **exactly one solution**. diff --git a/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts b/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts new file mode 100644 index 0000000..ee66d03 --- /dev/null +++ b/src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.ts @@ -0,0 +1,21 @@ +// #Medium #Array #Binary_Search #Two_Pointers #Algorithm_I_Day_3_Two_Pointers +// #Binary_Search_I_Day_7 #Top_Interview_150_Two_Pointers +// #2025_04_08_Time_0_ms_(100.00%)_Space_56.49_MB_(68.78%) + +function twoSum(numbers: number[], target: number): number[] { + let i = 0 + let j = numbers.length - 1 + while (i < j) { + const sum = numbers[i] + numbers[j] + if (sum === target) { + return [i + 1, j + 1] + } else if (sum < target) { + i++ + } else { + j-- + } + } + return [] +} + +export { twoSum } diff --git a/src/main/ts/g0101_0200/s0169_majority_element/solution.ts b/src/main/ts/g0101_0200/s0169_majority_element/solution.ts index e394d69..ad4b884 100644 --- a/src/main/ts/g0101_0200/s0169_majority_element/solution.ts +++ b/src/main/ts/g0101_0200/s0169_majority_element/solution.ts @@ -1,6 +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 -// #Big_O_Time_O(n)_Space_O(1) #2023_10_09_Time_50_ms_(96.16%)_Space_46.1_MB_(46.90%) +// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1) +// #2025_03_26_Time_0_ms_(100.00%)_Space_60.31_MB_(17.26%) function majorityElement(arr: number[]): number { let count = 1 diff --git a/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/readme.md b/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/readme.md new file mode 100644 index 0000000..1ac6005 --- /dev/null +++ b/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/readme.md @@ -0,0 +1,35 @@ +172\. Factorial Trailing Zeroes + +Medium + +Given an integer `n`, return _the number of trailing zeroes in_ `n!`. + +Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. + +**Example 1:** + +**Input:** n = 3 + +**Output:** 0 + +**Explanation:** 3! = 6, no trailing zero. + +**Example 2:** + +**Input:** n = 5 + +**Output:** 1 + +**Explanation:** 5! = 120, one trailing zero. + +**Example 3:** + +**Input:** n = 0 + +**Output:** 0 + +**Constraints:** + +* 0 <= n <= 104 + +**Follow up:** Could you write a solution that works in logarithmic time complexity? diff --git a/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts b/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts new file mode 100644 index 0000000..1ee679a --- /dev/null +++ b/src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.ts @@ -0,0 +1,14 @@ +// #Medium #Top_Interview_Questions #Math #Udemy_Integers #Top_Interview_150_Math +// #2025_04_09_Time_0_ms_(100.00%)_Space_55.76_MB_(76.26%) + +function trailingZeroes(n: number): number { + let base = 5 + let count = 0 + while (n >= base) { + count += Math.floor(n / base) + base *= 5 + } + return count +} + +export { trailingZeroes } diff --git a/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/readme.md b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/readme.md new file mode 100644 index 0000000..0e628a7 --- /dev/null +++ b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/readme.md @@ -0,0 +1,44 @@ +173\. Binary Search Tree Iterator + +Medium + +Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): + +* `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST. +* `boolean hasNext()` Returns `true` if there exists a number in the traversal to the right of the pointer, otherwise returns `false`. +* `int next()` Moves the pointer to the right, then returns the number at the pointer. + +Notice that by initializing the pointer to a non-existent smallest number, the first call to `next()` will return the smallest element in the BST. + +You may assume that `next()` calls will always be valid. That is, there will be at least a next number in the in-order traversal when `next()` is called. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png) + +**Input** ["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"] [[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []] + +**Output:** [null, 3, 7, true, 9, true, 15, true, 20, false] + +**Explanation:** + + BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); + bSTIterator.next(); // return 3 + bSTIterator.next(); // return 7 + bSTIterator.hasNext(); // return True + bSTIterator.next(); // return 9 + bSTIterator.hasNext(); // return True + bSTIterator.next(); // return 15 + bSTIterator.hasNext(); // return True + bSTIterator.next(); // return 20 + bSTIterator.hasNext(); // return False + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 105]. +* 0 <= Node.val <= 106 +* At most 105 calls will be made to `hasNext`, and `next`. + +**Follow up:** + +* Could you implement `next()` and `hasNext()` to run in average `O(1)` time and use `O(h)` memory, where `h` is the height of the tree? diff --git a/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts new file mode 100644 index 0000000..077a102 --- /dev/null +++ b/src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.ts @@ -0,0 +1,66 @@ +// #Medium #Tree #Binary_Tree #Stack #Design #Binary_Search_Tree #Iterator +// #Data_Structure_II_Day_17_Tree #Programming_Skills_II_Day_16 #Level_2_Day_9_Binary_Search_Tree +// #Top_Interview_150_Binary_Tree_General #2025_04_09_Time_6_ms_(98.16%)_Space_69.76_MB_(29.04%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +class BSTIterator { + private node: TreeNode | null + + constructor(root: TreeNode | null) { + this.node = root + } + + next(): number { + let res = -1 + while (this.node !== null) { + if (this.node.left !== null) { + let rightMost = this.node.left + while (rightMost.right !== null && rightMost.right !== this.node) { + rightMost = rightMost.right + } + + if (rightMost.right === null) { + rightMost.right = this.node + this.node = this.node.left + } else { + rightMost.right = null + res = this.node.val + this.node = this.node.right + return res + } + } else { + res = this.node.val + this.node = this.node.right + return res + } + } + return res + } + + hasNext(): boolean { + return this.node !== null + } +} + +/** + * Your BSTIterator object will be instantiated and called as such: + * var obj = new BSTIterator(root) + * var param_1 = obj.next() + * var param_2 = obj.hasNext() + */ + +export { BSTIterator } diff --git a/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md b/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md new file mode 100644 index 0000000..23e753c --- /dev/null +++ b/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md @@ -0,0 +1,31 @@ +188\. Best Time to Buy and Sell Stock IV + +Hard + +You are given an integer array `prices` where `prices[i]` is the price of a given stock on the ith day, and an integer `k`. + +Find the maximum profit you can achieve. You may complete at most `k` transactions. + +**Note:** You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). + +**Example 1:** + +**Input:** k = 2, prices = [2,4,1] + +**Output:** 2 + +**Explanation:** Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2. + +**Example 2:** + +**Input:** k = 2, prices = [3,2,6,5,0,3] + +**Output:** 7 + +**Explanation:** Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3. + +**Constraints:** + +* `0 <= k <= 100` +* `0 <= prices.length <= 1000` +* `0 <= prices[i] <= 1000` diff --git a/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.ts b/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.ts new file mode 100644 index 0000000..7c9c13f --- /dev/null +++ b/src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.ts @@ -0,0 +1,18 @@ +// #Hard #Array #Dynamic_Programming #Top_Interview_150_Multidimensional_DP +// #2025_04_09_Time_0_ms_(100.00%)_Space_58.46_MB_(61.74%) + +function maxProfit(k: number, prices: number[]): number { + const n = prices.length + const dp: number[] = new Array(k + 1).fill(0) + const maxdp: number[] = new Array(k + 1).fill(Number.MIN_SAFE_INTEGER) + for (let i = 1; i <= n; i++) { + maxdp[0] = Math.max(maxdp[0], dp[0] - prices[i - 1]) + for (let j = k; j >= 1; j--) { + maxdp[j] = Math.max(maxdp[j], dp[j] - prices[i - 1]) + dp[j] = Math.max(dp[j], maxdp[j - 1] + prices[i - 1]) + } + } + return dp[k] +} + +export { maxProfit } diff --git a/src/main/ts/g0101_0200/s0189_rotate_array/solution.ts b/src/main/ts/g0101_0200/s0189_rotate_array/solution.ts index b6c7b1e..f645bc7 100644 --- a/src/main/ts/g0101_0200/s0189_rotate_array/solution.ts +++ b/src/main/ts/g0101_0200/s0189_rotate_array/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Two_Pointers -// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1) -// #2023_10_09_Time_75_ms_(97.25%)_Space_52_MB_(63.34%) +// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String +// #Big_O_Time_O(n)_Space_O(1) #2025_03_26_Time_1_ms_(86.17%)_Space_64.71_MB_(43.34%) /* Do not return anything, modify nums in-place instead. diff --git a/src/main/ts/g0101_0200/s0190_reverse_bits/readme.md b/src/main/ts/g0101_0200/s0190_reverse_bits/readme.md new file mode 100644 index 0000000..6d126df --- /dev/null +++ b/src/main/ts/g0101_0200/s0190_reverse_bits/readme.md @@ -0,0 +1,32 @@ +190\. Reverse Bits + +Easy + +Reverse bits of a given 32 bits unsigned integer. + +**Note:** + +* Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. +* In Java, the compiler represents the signed integers using [2's complement notation](https://en.wikipedia.org/wiki/Two%27s_complement). Therefore, in **Example 2** above, the input represents the signed integer `-3` and the output represents the signed integer `-1073741825`. + +**Example 1:** + +**Input:** n = 00000010100101000001111010011100 + +**Output:** 964176192 (00111001011110000010100101000000) + +**Explanation:** The input binary string **00000010100101000001111010011100** represents the unsigned integer 43261596, so return 964176192 which its binary representation is **00111001011110000010100101000000**. + +**Example 2:** + +**Input:** n = 11111111111111111111111111111101 + +**Output:** 3221225471 (10111111111111111111111111111111) + +**Explanation:** The input binary string **11111111111111111111111111111101** represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is **10111111111111111111111111111111**. + +**Constraints:** + +* The input must be a **binary string** of length `32` + +**Follow up:** If this function is called many times, how would you optimize it? diff --git a/src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts b/src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts new file mode 100644 index 0000000..05e537d --- /dev/null +++ b/src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts @@ -0,0 +1,15 @@ +// #Easy #Top_Interview_Questions #Bit_Manipulation #Divide_and_Conquer +// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Bit_Manipulation #Top_Interview_150_Bit_Manipulation +// #2025_04_09_Time_34_ms_(99.74%)_Space_57.96_MB_(41.00%) + +function reverseBits(n: number): number { + let reversed = 0 + for (let i = 0; i < 32; i++) { + reversed <<= 1 + reversed = reversed | (n & 1) + n >>>= 1 + } + return reversed >>> 0 +} + +export { reverseBits } diff --git a/src/main/ts/g0101_0200/s0191_number_of_1_bits/readme.md b/src/main/ts/g0101_0200/s0191_number_of_1_bits/readme.md new file mode 100644 index 0000000..4014868 --- /dev/null +++ b/src/main/ts/g0101_0200/s0191_number_of_1_bits/readme.md @@ -0,0 +1,40 @@ +191\. Number of 1 Bits + +Easy + +Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)). + +**Note:** + +* Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. +* In Java, the compiler represents the signed integers using [2's complement notation](https://en.wikipedia.org/wiki/Two%27s_complement). Therefore, in **Example 3**, the input represents the signed integer. `-3`. + +**Example 1:** + +**Input:** n = 00000000000000000000000000001011 + +**Output:** 3 + +**Explanation:** The input binary string **00000000000000000000000000001011** has a total of three '1' bits. + +**Example 2:** + +**Input:** n = 00000000000000000000000010000000 + +**Output:** 1 + +**Explanation:** The input binary string **00000000000000000000000010000000** has a total of one '1' bit. + +**Example 3:** + +**Input:** n = 11111111111111111111111111111101 + +**Output:** 31 + +**Explanation:** The input binary string **11111111111111111111111111111101** has a total of thirty one '1' bits. + +**Constraints:** + +* The input must be a **binary string** of length `32`. + +**Follow up:** If this function is called many times, how would you optimize it? diff --git a/src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts b/src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts new file mode 100644 index 0000000..0ce05ed --- /dev/null +++ b/src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts @@ -0,0 +1,15 @@ +// #Easy #Top_Interview_Questions #Bit_Manipulation #Algorithm_I_Day_13_Bit_Manipulation +// #Programming_Skills_I_Day_2_Operator #Udemy_Bit_Manipulation #Top_Interview_150_Bit_Manipulation +// #2025_04_09_Time_0_ms_(100.00%)_Space_55.90_MB_(75.68%) + +function hammingWeight(n: number): number { + let sum = 0 + n = n >>> 0 + while (n > 0) { + sum += n % 2 + n = Math.floor(n / 2) + } + return sum +} + +export { hammingWeight } diff --git a/src/main/ts/g0101_0200/s0198_house_robber/solution.ts b/src/main/ts/g0101_0200/s0198_house_robber/solution.ts index 6b1c436..11753e6 100644 --- a/src/main/ts/g0101_0200/s0198_house_robber/solution.ts +++ b/src/main/ts/g0101_0200/s0198_house_robber/solution.ts @@ -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 #Big_O_Time_O(n)_Space_O(n) -// #2023_10_09_Time_51_ms_(77.29%)_Space_42.7_MB_(62.58%) +// #LeetCode_75_DP/1D #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_03_26_Time_0_ms_(100.00%)_Space_55.74_MB_(28.06%) function rob(nums: number[]): number { const n = nums.length diff --git a/src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/readme.md b/src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/readme.md new file mode 100644 index 0000000..b3cb904 --- /dev/null +++ b/src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/readme.md @@ -0,0 +1,30 @@ +199\. Binary Tree Right Side View + +Medium + +Given the `root` of a binary tree, imagine yourself standing on the **right side** of it, return _the values of the nodes you can see ordered from top to bottom_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/14/tree.jpg) + +**Input:** root = [1,2,3,null,5,null,4] + +**Output:** [1,3,4] + +**Example 2:** + +**Input:** root = [1,null,3] + +**Output:** [1,3] + +**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/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts b/src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts new file mode 100644 index 0000000..e45a4d9 --- /dev/null +++ b/src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts @@ -0,0 +1,35 @@ +// #Medium #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree +// #LeetCode_75_Binary_Tree/BFS #Data_Structure_II_Day_16_Tree #Level_2_Day_15_Tree +// #Top_Interview_150_Binary_Tree_BFS #2025_04_10_Time_0_ms_(100.00%)_Space_56.98_MB_(73.71%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function rightSideView(root: TreeNode | null): number[] { + const result: number[] = [] + function recurse(node: TreeNode | null, level: number): void { + if (node !== null) { + if (result.length === level) { + result.push(node.val) + } + recurse(node.right, level + 1) + recurse(node.left, level + 1) + } + } + recurse(root, 0) + return result +} + +export { rightSideView } diff --git a/src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts b/src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts index db5cfb0..87b9e95 100644 --- a/src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts +++ b/src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts @@ -2,7 +2,8 @@ // #Breadth_First_Search #Matrix #Union_Find // #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 -// #Big_O_Time_O(M*N)_Space_O(M*N) #2023_10_09_Time_61_ms_(96.71%)_Space_44.5_MB_(99.30%) +// #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N) +// #2025_03_26_Time_57_ms_(93.94%)_Space_59.21_MB_(64.22%) function numIslands(grid: string[][]): number { let islands = 0 diff --git a/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/readme.md b/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/readme.md new file mode 100644 index 0000000..879520b --- /dev/null +++ b/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/readme.md @@ -0,0 +1,27 @@ +201\. Bitwise AND of Numbers Range + +Medium + +Given two integers `left` and `right` that represent the range `[left, right]`, return _the bitwise AND of all numbers in this range, inclusive_. + +**Example 1:** + +**Input:** left = 5, right = 7 + +**Output:** 4 + +**Example 2:** + +**Input:** left = 0, right = 0 + +**Output:** 0 + +**Example 3:** + +**Input:** left = 1, right = 2147483647 + +**Output:** 0 + +**Constraints:** + +* 0 <= left <= right <= 231 - 1 diff --git a/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts b/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts new file mode 100644 index 0000000..04d02e0 --- /dev/null +++ b/src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts @@ -0,0 +1,18 @@ +// #Medium #Bit_Manipulation #Algorithm_II_Day_19_Bit_Manipulation +// #Top_Interview_150_Bit_Manipulation #2025_04_10_Time_2_ms_(99.12%)_Space_64.48_MB_(7.02%) + +function rangeBitwiseAnd(left: number, right: number): number { + const MASKS: number[] = [ + 0x00000000, 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, + 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, 0xffff8000, + 0xffffc000, 0xffffe000, 0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, 0xffffff80, 0xffffffc0, + 0xffffffe0, 0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe, + ] + if (left === right) { + return left + } + const leadingZeros = Math.clz32(left ^ right) + return right & MASKS[leadingZeros] +} + +export { rangeBitwiseAnd } diff --git a/src/main/ts/g0201_0300/s0202_happy_number/readme.md b/src/main/ts/g0201_0300/s0202_happy_number/readme.md new file mode 100644 index 0000000..6a56b07 --- /dev/null +++ b/src/main/ts/g0201_0300/s0202_happy_number/readme.md @@ -0,0 +1,39 @@ +202\. Happy Number + +Easy + +Write an algorithm to determine if a number `n` is happy. + +A **happy number** is a number defined by the following process: + +* Starting with any positive integer, replace the number by the sum of the squares of its digits. +* Repeat the process until the number equals 1 (where it will stay), or it **loops endlessly in a cycle** which does not include 1. +* Those numbers for which this process **ends in 1** are happy. + +Return `true` _if_ `n` _is a happy number, and_ `false` _if not_. + +**Example 1:** + +**Input:** n = 19 + +**Output:** true + +**Explanation:** + +12 + 92 = 82 + +82 + 22 = 68 + +62 + 82 = 100 + +12 + 02 + 02 = 1 + +**Example 2:** + +**Input:** n = 2 + +**Output:** false + +**Constraints:** + +* 1 <= n <= 231 - 1 \ No newline at end of file diff --git a/src/main/ts/g0201_0300/s0202_happy_number/solution.ts b/src/main/ts/g0201_0300/s0202_happy_number/solution.ts new file mode 100644 index 0000000..0e48c4d --- /dev/null +++ b/src/main/ts/g0201_0300/s0202_happy_number/solution.ts @@ -0,0 +1,23 @@ +// #Easy #Top_Interview_Questions #Hash_Table #Math #Two_Pointers #Algorithm_II_Day_21_Others +// #Programming_Skills_I_Day_4_Loop #Level_2_Day_1_Implementation/Simulation +// #Top_Interview_150_Hashmap #2025_04_10_Time_0_ms_(100.00%)_Space_55.45_MB_(83.98%) + +function isHappy(n: number): boolean { + let a = n + let rem: number + let sum = 0 + if (a === 1 || a === 7) { + return true + } else if (a > 1 && a < 10) { + return false + } else { + while (a !== 0) { + rem = a % 10 + sum += rem * rem + a = Math.floor(a / 10) + } + return sum === 1 ? true : isHappy(sum) + } +} + +export { isHappy } diff --git a/src/main/ts/g0201_0300/s0205_isomorphic_strings/readme.md b/src/main/ts/g0201_0300/s0205_isomorphic_strings/readme.md new file mode 100644 index 0000000..d91e8ce --- /dev/null +++ b/src/main/ts/g0201_0300/s0205_isomorphic_strings/readme.md @@ -0,0 +1,33 @@ +205\. Isomorphic Strings + +Easy + +Given two strings `s` and `t`, _determine if they are isomorphic_. + +Two strings `s` and `t` are isomorphic if the characters in `s` can be replaced to get `t`. + +All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. + +**Example 1:** + +**Input:** s = "egg", t = "add" + +**Output:** true + +**Example 2:** + +**Input:** s = "foo", t = "bar" + +**Output:** false + +**Example 3:** + +**Input:** s = "paper", t = "title" + +**Output:** true + +**Constraints:** + +* 1 <= s.length <= 5 * 104 +* `t.length == s.length` +* `s` and `t` consist of any valid ascii character. diff --git a/src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts b/src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts new file mode 100644 index 0000000..cc73876 --- /dev/null +++ b/src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts @@ -0,0 +1,23 @@ +// #Easy #String #Hash_Table #Level_1_Day_2_String #Top_Interview_150_Hashmap +// #2025_04_10_Time_3_ms_(96.02%)_Space_56.62_MB_(65.86%) + +function isIsomorphic(s: string, t: string): boolean { + if (s.length !== t.length) { + return false + } + const mapS = new Map() + const mapT = new Map() + for (let i = 0; i < s.length; i++) { + if (mapS.has(s[i]) || mapT.has(t[i])) { + if (mapS.get(s[i]) !== t[i] || mapT.get(t[i]) !== s[i]) { + return false + } + } else { + mapS.set(s[i], t[i]) + mapT.set(t[i], s[i]) + } + } + return true +} + +export { isIsomorphic } diff --git a/src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts b/src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts index 513c8c4..12b2ca0 100644 --- a/src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts +++ b/src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts @@ -1,11 +1,11 @@ // #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) -// #2023_10_09_Time_51_ms_(92.87%)_Space_44.3_MB_(96.03%) +// #LeetCode_75_LinkedList #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_03_26_Time_0_ms_(100.00%)_Space_58.92_MB_(16.01%) import { ListNode } from '../../com_github_leetcode/listnode' -/* +/** * Definition for singly-linked list. * class ListNode { * val: number diff --git a/src/main/ts/g0201_0300/s0207_course_schedule/solution.ts b/src/main/ts/g0201_0300/s0207_course_schedule/solution.ts index db5be9f..1b23ff3 100644 --- a/src/main/ts/g0201_0300/s0207_course_schedule/solution.ts +++ b/src/main/ts/g0201_0300/s0207_course_schedule/solution.ts @@ -1,6 +1,6 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search -// #Breadth_First_Search #Graph #Topological_Sort #Big_O_Time_O(N)_Space_O(N) -// #2023_10_09_Time_68_ms_(70.14%)_Space_47.7_MB_(73.55%) +// #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General +// #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_11_ms_(81.08%)_Space_62.76_MB_(51.00%) const WHITE = 0 const GRAY = 1 @@ -26,7 +26,6 @@ function hasCycle(adj: number[][], node: number, colors: number[]): boolean { if (colors[nei] === GRAY) { return true } - if (colors[nei] === WHITE && hasCycle(adj, nei, colors)) { return true } diff --git a/src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts b/src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts index aafabc9..f490b91 100644 --- a/src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts +++ b/src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts @@ -1,7 +1,7 @@ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie -// #Level_2_Day_16_Design #Udemy_Trie_and_Heap +// #LeetCode_75_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) -// #2023_10_09_Time_168_ms_(80.99%)_Space_79.5_MB_(14.46%) +// #2025_03_26_Time_48_ms_(63.95%)_Space_81.97_MB_(12.22%) class TrieNode { children: TrieNode[] diff --git a/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/readme.md b/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/readme.md new file mode 100644 index 0000000..0e301a6 --- /dev/null +++ b/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/readme.md @@ -0,0 +1,33 @@ +209\. Minimum Size Subarray Sum + +Medium + +Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a **contiguous subarray** [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than or equal to `target`. If there is no such subarray, return `0` instead. + +**Example 1:** + +**Input:** target = 7, nums = [2,3,1,2,4,3] + +**Output:** 2 + +**Explanation:** The subarray [4,3] has the minimal length under the problem constraint. + +**Example 2:** + +**Input:** target = 4, nums = [1,4,4] + +**Output:** 1 + +**Example 3:** + +**Input:** target = 11, nums = [1,1,1,1,1,1,1,1] + +**Output:** 0 + +**Constraints:** + +* 1 <= target <= 109 +* 1 <= nums.length <= 105 +* 1 <= nums[i] <= 105 + +**Follow up:** If you have figured out the `O(n)` solution, try coding another solution of which the time complexity is `O(n log(n))`. diff --git a/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts b/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts new file mode 100644 index 0000000..296d41a --- /dev/null +++ b/src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts @@ -0,0 +1,28 @@ +// #Medium #Array #Binary_Search #Prefix_Sum #Sliding_Window #Algorithm_II_Day_5_Sliding_Window +// #Binary_Search_II_Day_1 #Top_Interview_150_Sliding_Window +// #2025_04_10_Time_2_ms_(88.11%)_Space_59.64_MB_(83.02%) + +function minSubArrayLen(target: number, nums: number[]): number { + let i = 0 + let j = 0 + let sum = 0 + let min = Number.MAX_SAFE_INTEGER + while (j < nums.length) { + sum += nums[j] + if (sum >= target) { + while (i <= j) { + if (sum - nums[i] >= target) { + sum -= nums[i] + i++ + } else { + break + } + } + min = Math.min(min, j - i + 1) + } + j++ + } + return min === Number.MAX_SAFE_INTEGER ? 0 : min +} + +export { minSubArrayLen } diff --git a/src/main/ts/g0201_0300/s0210_course_schedule_ii/readme.md b/src/main/ts/g0201_0300/s0210_course_schedule_ii/readme.md new file mode 100644 index 0000000..5a1b0cb --- /dev/null +++ b/src/main/ts/g0201_0300/s0210_course_schedule_ii/readme.md @@ -0,0 +1,46 @@ +210\. Course Schedule II + +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 _the ordering of courses you should take to finish all courses_. If there are many valid answers, return **any** of them. If it is impossible to finish all courses, return **an empty array**. + +**Example 1:** + +**Input:** numCourses = 2, prerequisites = [[1,0]] + +**Output:** [0,1] + +**Explanation:** + + There are a total of 2 courses to take. To take course 1 you should have finished course 0. + So the correct course order is [0,1]. + +**Example 2:** + +**Input:** numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]] + +**Output:** [0,2,1,3] + +**Explanation:** + + There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0. + So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3]. + +**Example 3:** + +**Input:** numCourses = 1, prerequisites = [] + +**Output:** [0] + +**Constraints:** + +* `1 <= numCourses <= 2000` +* `0 <= prerequisites.length <= numCourses * (numCourses - 1)` +* `prerequisites[i].length == 2` +* 0 <= ai, bi < numCourses +* ai != bi +* All the pairs [ai, bi] are **distinct**. diff --git a/src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts b/src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts new file mode 100644 index 0000000..919dd15 --- /dev/null +++ b/src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts @@ -0,0 +1,36 @@ +// #Medium #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search #Graph +// #Topological_Sort #Level_2_Day_11_Graph/BFS/DFS #Top_Interview_150_Graph_General +// #2025_04_12_Time_2_ms_(99.76%)_Space_58.61_MB_(86.54%) + +function findOrder(numCourses: number, prerequisites: number[][]): number[] { + let sortedOrder: number[] = [] + if (numCourses < 0) { + return sortedOrder + } + let inDegree = new Array(numCourses).fill(0), + graph = new Array(numCourses).fill(0).map(() => new Array()), + source = new Array() + prerequisites.forEach((course: number[]) => { + graph[course[1]].push(course[0]) + inDegree[course[0]]++ + }) + inDegree.forEach((value: number, index: number) => { + if (value === 0) { + source.push(index) + } + }) + while (source.length > 0) { + const course = source.shift() + if (course === undefined) break + sortedOrder.push(course) + graph[course].forEach((val) => { + inDegree[val]-- + if (inDegree[val] === 0) { + source.push(val) + } + }) + } + return sortedOrder.length === numCourses ? sortedOrder : [] +} + +export { findOrder } diff --git a/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md b/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md new file mode 100644 index 0000000..940cb2f --- /dev/null +++ b/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md @@ -0,0 +1,39 @@ +211\. Design Add and Search Words Data Structure + +Medium + +Design a data structure that supports adding new words and finding if a string matches any previously added string. + +Implement the `WordDictionary` class: + +* `WordDictionary()` Initializes the object. +* `void addWord(word)` Adds `word` to the data structure, it can be matched later. +* `bool search(word)` Returns `true` if there is any string in the data structure that matches `word` or `false` otherwise. `word` may contain dots `'.'` where dots can be matched with any letter. + +**Example:** + +**Input** + + ["WordDictionary","addWord","addWord","addWord","search","search","search","search"] [[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]] + +**Output** + + [null,null,null,null,false,true,true,true] + +**Explanation** + + WordDictionary wordDictionary = new WordDictionary(); + wordDictionary.addWord("bad"); + wordDictionary.addWord("dad"); + wordDictionary.addWord("mad"); + wordDictionary.search("pad"); // return False + wordDictionary.search("bad"); // return True + wordDictionary.search(".ad"); // return True + wordDictionary.search("b.."); // return True + +**Constraints:** + +* `1 <= word.length <= 500` +* `word` in `addWord` consists lower-case English letters. +* `word` in `search` consist of `'.'` or lower-case English letters. +* At most `50000` calls will be made to `addWord` and `search`. diff --git a/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts b/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts new file mode 100644 index 0000000..60d11ae --- /dev/null +++ b/src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts @@ -0,0 +1,55 @@ +// #Medium #String #Depth_First_Search #Design #Trie #Top_Interview_150_Trie +// #2025_04_12_Time_450_ms_(92.88%)_Space_92.76_MB_(88.14%) + +interface TrieNode { + [key: string]: TrieNode | boolean +} + +class WordDictionary { + root: TrieNode + + constructor() { + this.root = {} + } + + addWord(word: string): void { + let current = this.root + for (let i = 0; i < word.length; i++) { + const letter = word[i] + if (!current.hasOwnProperty(letter)) { + current[letter] = {} + } + current = current[letter] as TrieNode + } + current.end = true + } + + search(word: string): boolean { + const searchSubtree = (word: string, index: number, subtree: TrieNode) => { + if (word.length === index) { + return subtree.hasOwnProperty('end') + } + const currentLetter = word[index] + index += 1 + if (currentLetter === '.') { + return Object.keys(subtree).some((letter) => searchSubtree(word, index, subtree[letter] as TrieNode)) + } else { + if (subtree.hasOwnProperty(currentLetter)) { + return searchSubtree(word, index, subtree[currentLetter] as TrieNode) + } else { + return false + } + } + } + return searchSubtree(word, 0, this.root) + } +} + +/** + * Your WordDictionary object will be instantiated and called as such: + * var obj = new WordDictionary() + * obj.addWord(word) + * var param_2 = obj.search(word) + */ + +export { WordDictionary } diff --git a/src/main/ts/g0201_0300/s0212_word_search_ii/readme.md b/src/main/ts/g0201_0300/s0212_word_search_ii/readme.md new file mode 100644 index 0000000..f6e6f9d --- /dev/null +++ b/src/main/ts/g0201_0300/s0212_word_search_ii/readme.md @@ -0,0 +1,34 @@ +212\. Word Search II + +Hard + +Given an `m x n` `board` of characters and a list of strings `words`, return _all words on the board_. + +Each word must be constructed from letters of sequentially adjacent cells, where **adjacent cells** are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/07/search1.jpg) + +**Input:** board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"] + +**Output:** ["eat","oath"] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/11/07/search2.jpg) + +**Input:** board = [["a","b"],["c","d"]], words = ["abcb"] + +**Output:** [] + +**Constraints:** + +* `m == board.length` +* `n == board[i].length` +* `1 <= m, n <= 12` +* `board[i][j]` is a lowercase English letter. +* 1 <= words.length <= 3 * 104 +* `1 <= words[i].length <= 10` +* `words[i]` consists of lowercase English letters. +* All the strings of `words` are unique. diff --git a/src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts b/src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts new file mode 100644 index 0000000..4fd1dc5 --- /dev/null +++ b/src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts @@ -0,0 +1,104 @@ +// #Hard #Top_Interview_Questions #Array #String #Matrix #Backtracking #Trie #Top_Interview_150_Trie +// #2025_04_12_Time_62_ms_(99.46%)_Space_60.47_MB_(72.83%) + +class Tree { + children: Map + end: string | null + + constructor() { + this.children = new Map() + this.end = null + } + + static addWord(node: Tree, word: string): void { + let cur = node + for (const char of word) { + if (!cur.children.has(char)) { + cur.children.set(char, new Tree()) + } + cur = cur.children.get(char)! + } + cur.end = word + } + + static deleteWord(node: Tree, word: string): void { + const stack: [Tree, string][] = [] + let cur = node + for (const char of word) { + const next = cur.children.get(char) + if (!next) return + stack.push([cur, char]) + cur = next + } + cur.end = null + for (let i = stack.length - 1; i >= 0; i--) { + const [parent, char] = stack[i] + const child = parent.children.get(char)! + if (child.children.size === 0 && child.end === null) { + parent.children.delete(char) + } else { + break + } + } + } + + getChild(char: string): Tree | null { + return this.children.get(char) || null + } + + len(): number { + return this.children.size + } +} + +function findWords(board: string[][], words: string[]): string[] { + if (board.length === 0 || board[0].length === 0) { + return [] + } + const root = new Tree() + for (const word of words) { + Tree.addWord(root, word) + } + const collected: string[] = [] + for (let i = 0; i < board.length; i++) { + for (let j = 0; j < board[0].length; j++) { + dfs(board, i, j, root, collected, root) + } + } + return collected +} + +function dfs(board: string[][], i: number, j: number, cur: Tree, collected: string[], root: Tree): void { + const c = board[i][j] + if (c === '-') { + return + } + const next = cur.getChild(c) + if (!next) { + return + } + if (next.end !== null) { + collected.push(next.end) + const word = next.end + next.end = null + if (next.len() === 0) { + Tree.deleteWord(root, word) + } + } + board[i][j] = '-' + if (i > 0) { + dfs(board, i - 1, j, next, collected, root) + } + if (i + 1 < board.length) { + dfs(board, i + 1, j, next, collected, root) + } + if (j > 0) { + dfs(board, i, j - 1, next, collected, root) + } + if (j + 1 < board[0].length) { + dfs(board, i, j + 1, next, collected, root) + } + board[i][j] = c +} + +export { findWords } diff --git a/src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts b/src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts index bc2ec15..cb0d0ff 100644 --- a/src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts +++ b/src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts @@ -1,10 +1,20 @@ // #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 -// #Big_O_Time_O(n*log(n))_Space_O(log(n)) #2023_10_09_Time_148_ms_(54.45%)_Space_51.5_MB_(73.60%) +// #Divide_and_Conquer #Quickselect #LeetCode_75_Heap/Priority_Queue +// #Data_Structure_II_Day_20_Heap_Priority_Queue #Top_Interview_150_Heap +// #Big_O_Time_O(n*log(n))_Space_O(log(n)) #2025_03_26_Time_4_ms_(99.64%)_Space_66.28_MB_(62.13%) function findKthLargest(nums: number[], k: number): number { - nums.sort((prev, next) => next - prev) - return nums[k - 1] + const countingLen = 2e4 + 1 + const counting = new Int32Array(countingLen) + for (const num of nums) { + counting[num + 1e4]++ + } + for (let i = countingLen - 1; i >= 0; i--) { + k -= counting[i] + if (k <= 0) { + return i - 1e4 + } + } } export { findKthLargest } diff --git a/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/readme.md b/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/readme.md new file mode 100644 index 0000000..41bd3ac --- /dev/null +++ b/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/readme.md @@ -0,0 +1,29 @@ +219\. Contains Duplicate II + +Easy + +Given an integer array `nums` and an integer `k`, return `true` if there are two **distinct indices** `i` and `j` in the array such that `nums[i] == nums[j]` and `abs(i - j) <= k`. + +**Example 1:** + +**Input:** nums = [1,2,3,1], k = 3 + +**Output:** true + +**Example 2:** + +**Input:** nums = [1,0,1,1], k = 1 + +**Output:** true + +**Example 3:** + +**Input:** nums = [1,2,3,1,2,3], k = 2 + +**Output:** false + +**Constraints:** + +* 1 <= nums.length <= 105 +* -109 <= nums[i] <= 109 +* 0 <= k <= 105 diff --git a/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts b/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts new file mode 100644 index 0000000..5ac8948 --- /dev/null +++ b/src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts @@ -0,0 +1,18 @@ +// #Easy #Array #Hash_Table #Sliding_Window #Top_Interview_150_Hashmap +// #2025_04_12_Time_17_ms_(79.29%)_Space_70.85_MB_(72.75%) + +function containsNearbyDuplicate(nums: number[], k: number): boolean { + const s = new Set() + for (let i = 0, l = nums.length; i < l; i++) { + if (i > k) { + s.delete(nums[i - k - 1]) + } + if (s.has(nums[i])) { + return true + } + s.add(nums[i]) + } + return false +} + +export { containsNearbyDuplicate } diff --git a/src/main/ts/g0201_0300/s0221_maximal_square/solution.ts b/src/main/ts/g0201_0300/s0221_maximal_square/solution.ts index 10aa2ce..81cafc9 100644 --- a/src/main/ts/g0201_0300/s0221_maximal_square/solution.ts +++ b/src/main/ts/g0201_0300/s0221_maximal_square/solution.ts @@ -1,6 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix -// #Dynamic_Programming_I_Day_16 #Big_O_Time_O(m*n)_Space_O(m*n) -// #2023_10_09_Time_83_ms_(79.70%)_Space_50.2_MB_(56.39%) +// #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_03_28_Time_18_ms_(59.02%)_Space_66.03_MB_(29.27%) function maximalSquare(matrix: string[][]): number { const m = matrix.length diff --git a/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/readme.md b/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/readme.md new file mode 100644 index 0000000..07e88f8 --- /dev/null +++ b/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/readme.md @@ -0,0 +1,35 @@ +222\. Count Complete Tree Nodes + +Medium + +Given the `root` of a **complete** binary tree, return the number of the nodes in the tree. + +According to **[Wikipedia](http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees)**, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between `1` and 2h nodes inclusive at the last level `h`. + +Design an algorithm that runs in less than `O(n)` time complexity. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/01/14/complete.jpg) + +**Input:** root = [1,2,3,4,5,6] + +**Output:** 6 + +**Example 2:** + +**Input:** root = [] + +**Output:** 0 + +**Example 3:** + +**Input:** root = [1] + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [0, 5 * 104]. +* 0 <= Node.val <= 5 * 104 +* The tree is guaranteed to be **complete**. diff --git a/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts b/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts new file mode 100644 index 0000000..60f5c7e --- /dev/null +++ b/src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts @@ -0,0 +1,50 @@ +// #Easy #Depth_First_Search #Tree #Binary_Search #Binary_Tree #Binary_Search_II_Day_10 +// #Top_Interview_150_Binary_Tree_General #2025_04_12_Time_0_ms_(100.00%)_Space_75.06_MB_(64.02%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function countNodes(root: TreeNode | null): number { + if (root === null) { + return 0 + } + const leftHeight = getLeftHeight(root) + const rightHeight = getRightHeight(root) + if (leftHeight === rightHeight) { + return (1 << leftHeight) - 1 + } else { + return 1 + countNodes(root.left) + countNodes(root.right) + } +} + +function getLeftHeight(node: TreeNode | null): number { + let height = 0 + while (node !== null) { + height++ + node = node.left + } + return height +} + +function getRightHeight(node: TreeNode | null): number { + let height = 0 + while (node !== null) { + height++ + node = node.right + } + return height +} + +export { countNodes } diff --git a/src/main/ts/g0201_0300/s0224_basic_calculator/readme.md b/src/main/ts/g0201_0300/s0224_basic_calculator/readme.md new file mode 100644 index 0000000..fc89eda --- /dev/null +++ b/src/main/ts/g0201_0300/s0224_basic_calculator/readme.md @@ -0,0 +1,35 @@ +224\. Basic Calculator + +Hard + +Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return _the result of the evaluation_. + +**Note:** You are **not** allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`. + +**Example 1:** + +**Input:** s = "1 + 1" + +**Output:** 2 + +**Example 2:** + +**Input:** s = " 2-1 + 2 " + +**Output:** 3 + +**Example 3:** + +**Input:** s = "(1+(4+5+2)-3)+(6+8)" + +**Output:** 23 + +**Constraints:** + +* 1 <= s.length <= 3 * 105 +* `s` consists of digits, `'+'`, `'-'`, `'('`, `')'`, and `' '`. +* `s` represents a valid expression. +* `'+'` is **not** used as a unary operation (i.e., `"+1"` and `"+(2 + 3)"` is invalid). +* `'-'` could be used as a unary operation (i.e., `"-1"` and `"-(2 + 3)"` is valid). +* There will be no two consecutive operators in the input. +* Every number and running calculation will fit in a signed 32-bit integer. diff --git a/src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts b/src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts new file mode 100644 index 0000000..811c88f --- /dev/null +++ b/src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts @@ -0,0 +1,39 @@ +// #Hard #String #Math #Stack #Recursion #Top_Interview_150_Stack +// #2025_04_12_Time_6_ms_(96.62%)_Space_57.57_MB_(89.85%) + +function calculate(s: string): number { + let i = 0 + + function helper(ca: string[]): number { + let num = 0 + let prenum = 0 + let isPlus = true + while (i < ca.length) { + const c = ca[i] + if (c !== ' ') { + if (c >= '0' && c <= '9') { + num = num * 10 + parseInt(c) + } else if (c === '+') { + prenum += num * (isPlus ? 1 : -1) + isPlus = true + num = 0 + } else if (c === '-') { + prenum += num * (isPlus ? 1 : -1) + isPlus = false + num = 0 + } else if (c === '(') { + i++ + num = helper(ca) + } else if (c === ')') { + prenum += num * (isPlus ? 1 : -1) + return prenum + } + } + i++ + } + return prenum + num * (isPlus ? 1 : -1) + } + return helper(s.split('')) +} + +export { calculate } diff --git a/src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts b/src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts index 4f1b49c..4887133 100644 --- a/src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts +++ b/src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts @@ -1,6 +1,7 @@ // #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 -// #Big_O_Time_O(n)_Space_O(n) #2023_10_09_Time_52_ms_(81.65%)_Space_44.2_MB_(79.49%) +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n) +// #2025_03_28_Time_0_ms_(100.00%)_Space_55.85_MB_(47.98%) function invertTree(root: TreeNode | null): TreeNode | null { if (root === null) { diff --git a/src/main/ts/g0201_0300/s0228_summary_ranges/readme.md b/src/main/ts/g0201_0300/s0228_summary_ranges/readme.md new file mode 100644 index 0000000..e8593fb --- /dev/null +++ b/src/main/ts/g0201_0300/s0228_summary_ranges/readme.md @@ -0,0 +1,53 @@ +228\. Summary Ranges + +Easy + +You are given a **sorted unique** integer array `nums`. + +Return _the **smallest sorted** list of ranges that **cover all the numbers in the array exactly**_. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`. + +Each range `[a,b]` in the list should be output as: + +* `"a->b"` if `a != b` +* `"a"` if `a == b` + +**Example 1:** + +**Input:** nums = [0,1,2,4,5,7] + +**Output:** ["0->2","4->5","7"] + +**Explanation:** The ranges are: [0,2] --> "0->2" [4,5] --> "4->5" [7,7] --> "7" + +**Example 2:** + +**Input:** nums = [0,2,3,4,6,8,9] + +**Output:** ["0","2->4","6","8->9"] + +**Explanation:** The ranges are: [0,0] --> "0" [2,4] --> "2->4" [6,6] --> "6" [8,9] --> "8->9" + +**Example 3:** + +**Input:** nums = [] + +**Output:** [] + +**Example 4:** + +**Input:** nums = [-1] + +**Output:** ["-1"] + +**Example 5:** + +**Input:** nums = [0] + +**Output:** ["0"] + +**Constraints:** + +* `0 <= nums.length <= 20` +* -231 <= nums[i] <= 231 - 1 +* All the values of `nums` are **unique**. +* `nums` is sorted in ascending order. diff --git a/src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts b/src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts new file mode 100644 index 0000000..347c551 --- /dev/null +++ b/src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts @@ -0,0 +1,34 @@ +// #Easy #Array #Top_Interview_150_Intervals #2025_04_12_Time_0_ms_(100.00%)_Space_55.25_MB_(57.62%) + +function summaryRanges(nums: number[]): string[] { + const ranges: string[] = [] + const n = nums.length + if (n === 0) { + return ranges + } + let a = nums[0] + let b = a + let strB = '' + for (let i = 1; i < n; i++) { + if (nums[i] !== b + 1) { + strB = a.toString() + if (a !== b) { + strB += '->' + b.toString() + } + ranges.push(strB) + a = nums[i] + b = a + strB = '' + } else { + b++ + } + } + strB = a.toString() + if (a !== b) { + strB += '->' + b.toString() + } + ranges.push(strB) + return ranges +} + +export { summaryRanges } diff --git a/src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts b/src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts index c40c632..bc18228 100644 --- a/src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts +++ b/src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts @@ -1,8 +1,9 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree -// #Binary_Search_Tree #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree -// #Big_O_Time_O(n)_Space_O(n) #2023_10_09_Time_54_ms_(97.22%)_Space_47.7_MB_(99.80%) +// #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_03_28_Time_0_ms_(100.00%)_Space_61.27_MB_(52.69%) -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts b/src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts index 32ca9be..581f652 100644 --- a/src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts +++ b/src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts @@ -1,8 +1,8 @@ -// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Stack #Linked_List -// #Recursion #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1) -// #2023_10_09_Time_96_ms_(95.67%)_Space_72.8_MB_(87.01%) +// #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_03_28_Time_3_ms_(92.85%)_Space_79.85_MB_(44.75%) -/* +/** * Definition for singly-linked list. * class ListNode { * val: number diff --git a/src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts b/src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts index 4d770b3..3acdf46 100644 --- a/src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts +++ b/src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts @@ -1,8 +1,9 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree -// #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n) -// #2023_10_09_Time_59_ms_(96.11%)_Space_52.8_MB_(24.18%) +// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree +// #LeetCode_75_Binary_Tree/DFS #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue +// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n) +// #2025_03_28_Time_61_ms_(75.97%)_Space_65.98_MB_(36.62%) -/* +/** * Definition for a binary tree node. * class TreeNode { * val: number diff --git a/src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts b/src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts index cded71d..b91f58a 100644 --- a/src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts +++ b/src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts @@ -1,6 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Prefix_Sum -// #Data_Structure_II_Day_5_Array #Udemy_Arrays #Big_O_Time_O(n^2)_Space_O(n) -// #2023_10_09_Time_89_ms_(64.48%)_Space_55.4_MB_(36.71%) +// #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #LeetCode_75_Array/String +// #Data_Structure_II_Day_5_Array #Udemy_Arrays #Top_Interview_150_Array/String +// #Big_O_Time_O(n^2)_Space_O(n) #2025_03_28_Time_3_ms_(92.81%)_Space_70.08_MB_(42.74%) function productExceptSelf(nums: number[]): number[] { const n = nums.length diff --git a/src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts b/src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts index 4d38555..5f944d0 100644 --- a/src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts +++ b/src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts @@ -1,6 +1,6 @@ -// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Heap_Priority_Queue -// #Sliding_Window #Queue #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k) -// #2023_10_06_Time_216_ms_(99.50%)_Space_71.4_MB_(89.85%) +// #Hard #Top_100_Liked_Questions #Array #Heap_Priority_Queue #Sliding_Window #Queue +// #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k) +// #2025_03_28_Time_26_ms_(99.07%)_Space_86.22_MB_(58.38%) function maxSlidingWindow(nums: number[], k: number): number[] { const result: number[] = [] diff --git a/src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts b/src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts index ee06606..beef395 100644 --- a/src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts +++ b/src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts @@ -1,6 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Matrix -// #Divide_and_Conquer #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 -// #Big_O_Time_O(n+m)_Space_O(1) #2023_10_06_Time_58_ms_(64.44%)_Space_45.6_MB_(50.00%) +// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Divide_and_Conquer +// #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1) +// #2025_03_28_Time_42_ms_(94.61%)_Space_58.52_MB_(36.53%) function searchMatrix(matrix: number[][], target: number): boolean { let r: number = 0 diff --git a/src/main/ts/g0201_0300/s0242_valid_anagram/readme.md b/src/main/ts/g0201_0300/s0242_valid_anagram/readme.md new file mode 100644 index 0000000..417acc0 --- /dev/null +++ b/src/main/ts/g0201_0300/s0242_valid_anagram/readme.md @@ -0,0 +1,24 @@ +242\. Valid Anagram + +Easy + +Given two strings `s` and `t`, return `true` _if_ `t` _is an anagram of_ `s`_, and_ `false` _otherwise_. + +**Example 1:** + +**Input:** s = "anagram", t = "nagaram" + +**Output:** true + +**Example 2:** + +**Input:** s = "rat", t = "car" + +**Output:** false + +**Constraints:** + +* 1 <= s.length, t.length <= 5 * 104 +* `s` and `t` consist of lowercase English letters. + +**Follow up:** What if the inputs contain Unicode characters? How would you adapt your solution to such a case? diff --git a/src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts b/src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts new file mode 100644 index 0000000..936a93e --- /dev/null +++ b/src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts @@ -0,0 +1,17 @@ +// #Easy #String #Hash_Table #Sorting #Data_Structure_I_Day_6_String +// #Programming_Skills_I_Day_11_Containers_and_Libraries #Udemy_Strings #Top_Interview_150_Hashmap +// #2025_04_12_Time_4_ms_(97.99%)_Space_57.08_MB_(80.13%) + +function isAnagram(s: string, t: string): boolean { + if (s.length !== t.length) { + return false + } + let counts = new Array(26).fill(0) + for (let i = 0; i < s.length; ++i) { + counts[s.charCodeAt(i) - 'a'.charCodeAt(0)]++ + counts[t.charCodeAt(i) - 'a'.charCodeAt(0)]-- + } + return counts.every((c) => c === 0) +} + +export { isAnagram } diff --git a/src/main/ts/g0201_0300/s0274_h_index/readme.md b/src/main/ts/g0201_0300/s0274_h_index/readme.md new file mode 100644 index 0000000..73d5909 --- /dev/null +++ b/src/main/ts/g0201_0300/s0274_h_index/readme.md @@ -0,0 +1,32 @@ +274\. H-Index + +Medium + +Given an array of integers `citations` where `citations[i]` is the number of citations a researcher received for their ith paper, return compute the researcher's `h`**\-index**. + +According to the [definition of h-index on Wikipedia](https://en.wikipedia.org/wiki/H-index): A scientist has an index `h` if `h` of their `n` papers have at least `h` citations each, and the other `n − h` papers have no more than `h` citations each. + +If there are several possible values for `h`, the maximum one is taken as the `h`**\-index**. + +**Example 1:** + +**Input:** citations = [3,0,6,1,5] + +**Output:** 3 + +**Explanation:** + + [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. + Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3. + +**Example 2:** + +**Input:** citations = [1,3,1] + +**Output:** 1 + +**Constraints:** + +* `n == citations.length` +* `1 <= n <= 5000` +* `0 <= citations[i] <= 1000` diff --git a/src/main/ts/g0201_0300/s0274_h_index/solution.ts b/src/main/ts/g0201_0300/s0274_h_index/solution.ts new file mode 100644 index 0000000..d832195 --- /dev/null +++ b/src/main/ts/g0201_0300/s0274_h_index/solution.ts @@ -0,0 +1,20 @@ +// #Medium #Array #Sorting #Counting_Sort #Top_Interview_150_Array/String +// #2025_04_16_Time_0_ms_(100.00%)_Space_54.06_MB_(91.25%) + +function hIndex(citations: number[]): number { + const len = citations.length + const freqArray = new Array(len + 1).fill(0) + for (const citation of citations) { + freqArray[Math.min(citation, len)]++ + } + let totalSoFar = 0 + for (let k = len; k >= 0; k--) { + totalSoFar += freqArray[k] + if (totalSoFar >= k) { + return k + } + } + return -1 +} + +export { hIndex } diff --git a/src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts b/src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts index 98ef336..236324e 100644 --- a/src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts +++ b/src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts @@ -1,6 +1,6 @@ -// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Two_Pointers +// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #LeetCode_75_Two_Pointers // #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays -// #Big_O_Time_O(n)_Space_O(1) #2023_10_06_Time_71_ms_(91.63%)_Space_47.2_MB_(57.52%) +// #Big_O_Time_O(n)_Space_O(1) #2025_03_28_Time_1_ms_(82.86%)_Space_62.16_MB_(10.71%) /* Do not return anything, modify nums in-place instead. diff --git a/src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts b/src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts index 02a43b7..9bcd4ee 100644 --- a/src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts +++ b/src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts @@ -1,6 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Two_Pointers -// #Bit_Manipulation #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n) -// #2023_10_06_Time_60_ms_(98.11%)_Space_53.5_MB_(50.00%) +// #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_03_28_Time_5_ms_(88.65%)_Space_67.23_MB_(32.75%) function findDuplicate(nums: number[]): number { const arr: number[] = new Array(nums.length + 1).fill(0) diff --git a/src/main/ts/g0201_0300/s0289_game_of_life/readme.md b/src/main/ts/g0201_0300/s0289_game_of_life/readme.md new file mode 100644 index 0000000..1f38ba1 --- /dev/null +++ b/src/main/ts/g0201_0300/s0289_game_of_life/readme.md @@ -0,0 +1,42 @@ +289\. Game of Life + +Medium + +According to [Wikipedia's article](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life): "The **Game of Life**, also known simply as **Life**, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." + +The board is made up of an `m x n` grid of cells, where each cell has an initial state: **live** (represented by a `1`) or **dead** (represented by a `0`). Each cell interacts with its [eight neighbors](https://en.wikipedia.org/wiki/Moore_neighborhood) (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article): + +1. Any live cell with fewer than two live neighbors dies as if caused by under-population. +2. Any live cell with two or three live neighbors lives on to the next generation. +3. Any live cell with more than three live neighbors dies, as if by over-population. +4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. + +The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the `m x n` grid `board`, return _the next state_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/12/26/grid1.jpg) + +**Input:** board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]] + +**Output:** [[0,0,0],[1,0,1],[0,1,1],[0,1,0]] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/12/26/grid2.jpg) + +**Input:** board = [[1,1],[1,0]] + +**Output:** [[1,1],[1,1]] + +**Constraints:** + +* `m == board.length` +* `n == board[i].length` +* `1 <= m, n <= 25` +* `board[i][j]` is `0` or `1`. + +**Follow up:** + +* Could you solve it in-place? Remember that the board needs to be updated simultaneously: You cannot update some cells first and then use their updated values to update other cells. +* In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches upon the border of the array (i.e., live cells reach the border). How would you address these problems? diff --git a/src/main/ts/g0201_0300/s0289_game_of_life/solution.ts b/src/main/ts/g0201_0300/s0289_game_of_life/solution.ts new file mode 100644 index 0000000..4be31b3 --- /dev/null +++ b/src/main/ts/g0201_0300/s0289_game_of_life/solution.ts @@ -0,0 +1,38 @@ +// #Medium #Array #Matrix #Simulation #Top_Interview_150_Matrix +// #2025_04_12_Time_0_ms_(100.00%)_Space_53.84_MB_(79.20%) + +/** + * Do not return anything, modify board in-place instead. + */ +function gameOfLife(board: number[][]): void { + const m = board.length + const n = board[0].length + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + const liveNeighbors = countLives(board, i, j, m, n) + if (board[i][j] === 0 && liveNeighbors === 3) { + board[i][j] = 2 + } else if (board[i][j] === 1 && (liveNeighbors === 2 || liveNeighbors === 3)) { + board[i][j] = 3 + } + } + } + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + board[i][j] >>= 1 + } + } +} + +function countLives(board: number[][], i: number, j: number, m: number, n: number): number { + let lives = 0 + for (let r = Math.max(0, i - 1); r <= Math.min(m - 1, i + 1); r++) { + for (let c = Math.max(0, j - 1); c <= Math.min(n - 1, j + 1); c++) { + lives += board[r][c] & 1 + } + } + lives -= board[i][j] & 1 + return lives +} + +export { gameOfLife } diff --git a/src/main/ts/g0201_0300/s0290_word_pattern/readme.md b/src/main/ts/g0201_0300/s0290_word_pattern/readme.md new file mode 100644 index 0000000..f69f9f9 --- /dev/null +++ b/src/main/ts/g0201_0300/s0290_word_pattern/readme.md @@ -0,0 +1,40 @@ +290\. Word Pattern + +Easy + +Given a `pattern` and a string `s`, find if `s` follows the same pattern. + +Here **follow** means a full match, such that there is a bijection between a letter in `pattern` and a **non-empty** word in `s`. + +**Example 1:** + +**Input:** pattern = "abba", s = "dog cat cat dog" + +**Output:** true + +**Example 2:** + +**Input:** pattern = "abba", s = "dog cat cat fish" + +**Output:** false + +**Example 3:** + +**Input:** pattern = "aaaa", s = "dog cat cat dog" + +**Output:** false + +**Example 4:** + +**Input:** pattern = "abba", s = "dog dog dog dog" + +**Output:** false + +**Constraints:** + +* `1 <= pattern.length <= 300` +* `pattern` contains only lower-case English letters. +* `1 <= s.length <= 3000` +* `s` contains only lower-case English letters and spaces `' '`. +* `s` **does not contain** any leading or trailing spaces. +* All the words in `s` are separated by a **single space**. diff --git a/src/main/ts/g0201_0300/s0290_word_pattern/solution.ts b/src/main/ts/g0201_0300/s0290_word_pattern/solution.ts new file mode 100644 index 0000000..4bc7476 --- /dev/null +++ b/src/main/ts/g0201_0300/s0290_word_pattern/solution.ts @@ -0,0 +1,27 @@ +// #Easy #String #Hash_Table #Data_Structure_II_Day_7_String #Top_Interview_150_Hashmap +// #2025_04_12_Time_0_ms_(100.00%)_Space_55.01_MB_(70.10%) + +function wordPattern(pattern: string, s: string): boolean { + const map = new Map() + const words = s.split(' ') + if (words.length !== pattern.length) { + return false + } + for (let i = 0; i < pattern.length; i++) { + const char = pattern[i] + const word = words[i] + if (!map.has(char)) { + if ([...map.values()].includes(word)) { + return false + } + map.set(char, word) + } else { + if (map.get(char) !== word) { + return false + } + } + } + return true +} + +export { wordPattern } diff --git a/src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts b/src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts index d429c85..99e79e2 100644 --- a/src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts +++ b/src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts @@ -1,6 +1,6 @@ -// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Design -// #Heap_Priority_Queue #Data_Stream #Big_O_Time_O(n*log_n)_Space_O(n) -// #2023_10_13_Time_335_ms_(99.44%)_Space_96.8_MB_(69.49%) +// #Hard #Top_100_Liked_Questions #Sorting #Two_Pointers #Design #Heap_Priority_Queue #Data_Stream +// #Top_Interview_150_Heap #Big_O_Time_O(n*log_n)_Space_O(n) +// #2025_03_28_Time_106_ms_(92.31%)_Space_94.21_MB_(5.43%) class Heap { private heap: number[] diff --git a/src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts b/src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts index 742db90..c45a8f5 100644 --- a/src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts +++ b/src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts @@ -1,7 +1,7 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_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 #Big_O_Time_O(n*log_n)_Space_O(n) -// #2023_10_04_Time_57_ms_(93.75%)_Space_45_MB_(33.55%) +// #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_03_28_Time_6_ms_(84.68%)_Space_58.13_MB_(39.69%) function lengthOfLIS(nums: number[]): number { if (nums === null || nums.length === 0) { diff --git a/src/main/ts/g0301_0400/s0322_coin_change/solution.ts b/src/main/ts/g0301_0400/s0322_coin_change/solution.ts index d91f8c6..c9cc931 100644 --- a/src/main/ts/g0301_0400/s0322_coin_change/solution.ts +++ b/src/main/ts/g0301_0400/s0322_coin_change/solution.ts @@ -1,7 +1,7 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming -// #Breadth_First_Search #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20 -// #Level_2_Day_12_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(amount) -// #2023_10_04_Time_85_ms_(86.14%)_Space_47.7_MB_(84.40%) +// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Breadth_First_Search +// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20 +// #Level_2_Day_12_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(m*n)_Space_O(amount) +// #2025_03_28_Time_27_ms_(89.42%)_Space_61.11_MB_(55.40%) function coinChange(coins: number[], amount: number): number { const dp: number[] = new Array(amount + 1).fill(0) diff --git a/src/main/ts/g0301_0400/s0338_counting_bits/solution.ts b/src/main/ts/g0301_0400/s0338_counting_bits/solution.ts index 8ff56ee..dac0ca4 100644 --- a/src/main/ts/g0301_0400/s0338_counting_bits/solution.ts +++ b/src/main/ts/g0301_0400/s0338_counting_bits/solution.ts @@ -1,5 +1,6 @@ -// #Easy #Top_100_Liked_Questions #Dynamic_Programming #Bit_Manipulation #Udemy_Bit_Manipulation -// #Big_O_Time_O(num)_Space_O(num) #2023_10_04_Time_69_ms_(86.81%)_Space_49_MB_(78.01%) +// #Easy #Dynamic_Programming #Bit_Manipulation #LeetCode_75_Bit_Manipulation +// #Udemy_Bit_Manipulation #Big_O_Time_O(num)_Space_O(num) +// #2025_03_28_Time_1_ms_(89.22%)_Space_62.26_MB_(53.31%) function countBits(n: number): number[] { const bits: number[] = [0] diff --git a/src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts b/src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts index ee32d6e..d925d9e 100644 --- a/src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts +++ b/src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts @@ -1,7 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting -// #Heap_Priority_Queue #Counting #Divide_and_Conquer #Quickselect #Bucket_Sort -// #Data_Structure_II_Day_20_Heap_Priority_Queue #Big_O_Time_O(n*log(n))_Space_O(k) -// #2023_10_04_Time_62_ms_(87.48%)_Space_45.6_MB_(67.84%) +// #Medium #Top_100_Liked_Questions #Array #Hash_Table #Sorting #Heap_Priority_Queue #Counting +// #Divide_and_Conquer #Quickselect #Bucket_Sort #Data_Structure_II_Day_20_Heap_Priority_Queue +// #Big_O_Time_O(n*log(n))_Space_O(k) #2025_03_28_Time_7_ms_(87.13%)_Space_59.57_MB_(56.27%) function topKFrequent(nums: number[], k: number): number[] { let elementCount = new Array(nums.length) diff --git a/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md b/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md new file mode 100644 index 0000000..71e2c20 --- /dev/null +++ b/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md @@ -0,0 +1,40 @@ +373\. Find K Pairs with Smallest Sums + +Medium + +You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`. + +Define a pair `(u, v)` which consists of one element from the first array and one element from the second array. + +Return _the_ `k` _pairs_ (u1, v1), (u2, v2), ..., (uk, vk) _with the smallest sums_. + +**Example 1:** + +**Input:** nums1 = [1,7,11], nums2 = [2,4,6], k = 3 + +**Output:** [[1,2],[1,4],[1,6]] + +**Explanation:** The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6] + +**Example 2:** + +**Input:** nums1 = [1,1,2], nums2 = [1,2,3], k = 2 + +**Output:** [[1,1],[1,1]] + +**Explanation:** The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3] + +**Example 3:** + +**Input:** nums1 = [1,2], nums2 = [3], k = 3 + +**Output:** [[1,3],[2,3]] + +**Explanation:** All possible pairs are returned from the sequence: [1,3],[2,3] + +**Constraints:** + +* 1 <= nums1.length, nums2.length <= 105 +* -109 <= nums1[i], nums2[i] <= 109 +* `nums1` and `nums2` both are sorted in **ascending order**. +* `1 <= k <= 1000` diff --git a/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts b/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts new file mode 100644 index 0000000..79b22dc --- /dev/null +++ b/src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts @@ -0,0 +1,86 @@ +// #Medium #Array #Heap_Priority_Queue #Top_Interview_150_Heap +// #2025_04_14_Time_42_ms_(85.15%)_Space_85.10_MB_(76.24%) + +class MinHeap { + private heap: { sum: number; i: number; j: number }[] + + constructor() { + this.heap = [] + } + + push(val: { sum: number; i: number; j: number }) { + this.heap.push(val) + this.bubbleUp() + } + + pop(): { sum: number; i: number; j: number } | undefined { + if (this.heap.length === 0) { + return undefined + } + if (this.heap.length === 1) { + return this.heap.pop() + } + const min = this.heap[0] + this.heap[0] = this.heap.pop()! + this.bubbleDown() + return min + } + + isEmpty(): boolean { + return this.heap.length === 0 + } + + private bubbleUp() { + let index = this.heap.length - 1 + while (index > 0) { + let parentIndex = Math.floor((index - 1) / 2) + if (this.heap[parentIndex].sum <= this.heap[index].sum) { + break + } + ;[this.heap[parentIndex], this.heap[index]] = [this.heap[index], this.heap[parentIndex]] + index = parentIndex + } + } + + private bubbleDown() { + let index = 0 + let length = this.heap.length + while (true) { + let leftChildIndex = 2 * index + 1 + let rightChildIndex = 2 * index + 2 + let smallest = index + if (leftChildIndex < length && this.heap[leftChildIndex].sum < this.heap[smallest].sum) { + smallest = leftChildIndex + } + if (rightChildIndex < length && this.heap[rightChildIndex].sum < this.heap[smallest].sum) { + smallest = rightChildIndex + } + if (smallest === index) { + break + } + ;[this.heap[index], this.heap[smallest]] = [this.heap[smallest], this.heap[index]] + index = smallest + } + } +} + +function kSmallestPairs(nums1: number[], nums2: number[], k: number): number[][] { + let ans: number[][] = [] + if (nums1.length === 0 || nums2.length === 0 || k === 0) { + return ans + } + let minHeap = new MinHeap() + for (let i = 0; i < Math.min(nums1.length, k); i++) { + minHeap.push({ sum: nums1[i] + nums2[0], i, j: 0 }) + } + while (k-- > 0 && !minHeap.isEmpty()) { + let { i, j } = minHeap.pop()! + ans.push([nums1[i], nums2[j]]) + if (j + 1 < nums2.length) { + minHeap.push({ sum: nums1[i] + nums2[j + 1], i, j: j + 1 }) + } + } + return ans +} + +export { kSmallestPairs } diff --git a/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md b/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md new file mode 100644 index 0000000..7e2c591 --- /dev/null +++ b/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md @@ -0,0 +1,38 @@ +380\. Insert Delete GetRandom O(1) + +Medium + +Implement the `RandomizedSet` class: + +* `RandomizedSet()` Initializes the `RandomizedSet` object. +* `bool insert(int val)` Inserts an item `val` into the set if not present. Returns `true` if the item was not present, `false` otherwise. +* `bool remove(int val)` Removes an item `val` from the set if present. Returns `true` if the item was present, `false` otherwise. +* `int getRandom()` Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the **same probability** of being returned. + +You must implement the functions of the class such that each function works in **average** `O(1)` time complexity. + +**Example 1:** + +**Input** + + ["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"] + [[], [1], [2], [2], [], [1], [2], []] + +**Output:** [null, true, false, true, 2, true, false, 2] + +**Explanation:** + + RandomizedSet randomizedSet = new RandomizedSet(); + randomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully. + randomizedSet.remove(2); // Returns false as 2 does not exist in the set. + randomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2]. + randomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly. + randomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2]. + randomizedSet.insert(2); // 2 was already in the set, so return false. + randomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2. + +**Constraints:** + +* -231 <= val <= 231 - 1 +* At most `2 * `105 calls will be made to `insert`, `remove`, and `getRandom`. +* There will be **at least one** element in the data structure when `getRandom` is called. diff --git a/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts b/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts new file mode 100644 index 0000000..6b57db9 --- /dev/null +++ b/src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts @@ -0,0 +1,51 @@ +// #Medium #Array #Hash_Table #Math #Design #Randomized #Programming_Skills_II_Day_20 +// #Top_Interview_150_Array/String #2025_04_16_Time_73_ms_(82.52%)_Space_106.13_MB_(72.14%) + +class RandomizedSet { + private rand: () => number + private list: number[] + private map: Map + + constructor() { + this.rand = () => Math.floor(Math.random() * this.list.length) // NOSONAR + this.list = [] + this.map = new Map() + } + + insert(val: number): boolean { + if (this.map.has(val)) { + return false + } + this.map.set(val, this.list.length) + this.list.push(val) + return true + } + + remove(val: number): boolean { + if (!this.map.has(val)) { + return false + } + const swap1 = this.map.get(val)! + const swap2 = this.list.length - 1 + const val2 = this.list[swap2] + this.map.set(val2, swap1) + this.map.delete(val) + this.list[swap1] = val2 + this.list.pop() + return true + } + + getRandom(): number { + return this.list[this.rand()] + } +} + +/** + * Your RandomizedSet object will be instantiated and called as such: + * var obj = new RandomizedSet() + * var param_1 = obj.insert(val) + * var param_2 = obj.remove(val) + * var param_3 = obj.getRandom() + */ + +export { RandomizedSet } diff --git a/src/main/ts/g0301_0400/s0383_ransom_note/readme.md b/src/main/ts/g0301_0400/s0383_ransom_note/readme.md new file mode 100644 index 0000000..6e85a1f --- /dev/null +++ b/src/main/ts/g0301_0400/s0383_ransom_note/readme.md @@ -0,0 +1,30 @@ +383\. Ransom Note + +Easy + +Given two stings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed from `magazine` and `false` otherwise. + +Each letter in `magazine` can only be used once in `ransomNote`. + +**Example 1:** + +**Input:** ransomNote = "a", magazine = "b" + +**Output:** false + +**Example 2:** + +**Input:** ransomNote = "aa", magazine = "ab" + +**Output:** false + +**Example 3:** + +**Input:** ransomNote = "aa", magazine = "aab" + +**Output:** true + +**Constraints:** + +* 1 <= ransomNote.length, magazine.length <= 105 +* `ransomNote` and `magazine` consist of lowercase English letters. diff --git a/src/main/ts/g0301_0400/s0383_ransom_note/solution.ts b/src/main/ts/g0301_0400/s0383_ransom_note/solution.ts new file mode 100644 index 0000000..7eb3282 --- /dev/null +++ b/src/main/ts/g0301_0400/s0383_ransom_note/solution.ts @@ -0,0 +1,20 @@ +// #Easy #String #Hash_Table #Counting #Data_Structure_I_Day_6_String #Top_Interview_150_Hashmap +// #2025_04_14_Time_4_ms_(97.40%)_Space_57.51_MB_(84.32%) + +function canConstruct(ransomNote: string, magazine: string): boolean { + const freq: number[] = new Array(26).fill(0) + let remaining = ransomNote.length + for (let i = 0; i < remaining; i++) { + freq[ransomNote.charCodeAt(i) - 97]++ + } + for (let i = 0; i < magazine.length && remaining > 0; i++) { + const index = magazine.charCodeAt(i) - 97 + if (freq[index] > 0) { + freq[index]-- + remaining-- + } + } + return remaining === 0 +} + +export { canConstruct } diff --git a/src/main/ts/g0301_0400/s0392_is_subsequence/readme.md b/src/main/ts/g0301_0400/s0392_is_subsequence/readme.md new file mode 100644 index 0000000..8a6dee7 --- /dev/null +++ b/src/main/ts/g0301_0400/s0392_is_subsequence/readme.md @@ -0,0 +1,27 @@ +392\. Is Subsequence + +Easy + +Given two strings `s` and `t`, return `true` _if_ `s` _is a **subsequence** of_ `t`_, or_ `false` _otherwise_. + +A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of `"abcde"` while `"aec"` is not). + +**Example 1:** + +**Input:** s = "abc", t = "ahbgdc" + +**Output:** true + +**Example 2:** + +**Input:** s = "axc", t = "ahbgdc" + +**Output:** false + +**Constraints:** + +* `0 <= s.length <= 100` +* 0 <= t.length <= 104 +* `s` and `t` consist only of lowercase English letters. + +**Follow up:** Suppose there are lots of incoming `s`, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if `t` has its subsequence. In this scenario, how would you change your code? diff --git a/src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts b/src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts new file mode 100644 index 0000000..ae62cb8 --- /dev/null +++ b/src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts @@ -0,0 +1,25 @@ +// #Easy #String #Dynamic_Programming #Two_Pointers #LeetCode_75_Two_Pointers +// #Dynamic_Programming_I_Day_19 #Level_1_Day_2_String #Udemy_Two_Pointers +// #Top_Interview_150_Two_Pointers #2025_04_14_Time_0_ms_(100.00%)_Space_56.51_MB_(36.22%) + +function isSubsequence(s: string, t: string): boolean { + let i = 0 + let j = 0 + const m = s.length + const n = t.length + if (m === 0) { + return true + } + while (j < n) { + if (s[i] === t[j]) { + i++ + if (i === m) { + return true + } + } + j++ + } + return false +} + +export { isSubsequence } diff --git a/src/main/ts/g0301_0400/s0394_decode_string/solution.ts b/src/main/ts/g0301_0400/s0394_decode_string/solution.ts index 6adb121..812511a 100644 --- a/src/main/ts/g0301_0400/s0394_decode_string/solution.ts +++ b/src/main/ts/g0301_0400/s0394_decode_string/solution.ts @@ -1,5 +1,6 @@ -// #Medium #Top_100_Liked_Questions #String #Stack #Recursion #Level_1_Day_14_Stack #Udemy_Strings -// #Big_O_Time_O(n)_Space_O(n) #2023_10_04_Time_51_ms_(81.02%)_Space_43_MB_(55.52%) +// #Medium #Top_100_Liked_Questions #String #Stack #Recursion #LeetCode_75_Stack +// #Level_1_Day_14_Stack #Udemy_Strings #Big_O_Time_O(n)_Space_O(n) +// #2025_03_28_Time_0_ms_(100.00%)_Space_55.70_MB_(34.63%) function decodeString(s: string): string { let stack: string[] = [] diff --git a/src/main/ts/g0301_0400/s0399_evaluate_division/readme.md b/src/main/ts/g0301_0400/s0399_evaluate_division/readme.md new file mode 100644 index 0000000..18a83c5 --- /dev/null +++ b/src/main/ts/g0301_0400/s0399_evaluate_division/readme.md @@ -0,0 +1,49 @@ +399\. Evaluate Division + +Medium + +You are given an array of variable pairs `equations` and an array of real numbers `values`, where equations[i] = [Ai, Bi] and `values[i]` represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable. + +You are also given some `queries`, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?. + +Return _the answers to all queries_. If a single answer cannot be determined, return `-1.0`. + +**Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction. + +**Example 1:** + +**Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] + +**Output:** [6.00000,0.50000,-1.00000,1.00000,-1.00000] + +**Explanation:** + +Given: _a / b = 2.0_, _b / c = 3.0_ + +queries are: _a / c = ?_, _b / a = ?_, _a / e = ?_, _a / a = ?_, _x / x = ?_ + +return: [6.0, 0.5, -1.0, 1.0, -1.0 ] + +**Example 2:** + +**Input:** equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]] + +**Output:** [3.75000,0.40000,5.00000,0.20000] + +**Example 3:** + +**Input:** equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]] + +**Output:** [0.50000,2.00000,-1.00000,-1.00000] + +**Constraints:** + +* `1 <= equations.length <= 20` +* `equations[i].length == 2` +* 1 <= Ai.length, Bi.length <= 5 +* `values.length == equations.length` +* `0.0 < values[i] <= 20.0` +* `1 <= queries.length <= 20` +* `queries[i].length == 2` +* 1 <= Cj.length, Dj.length <= 5 +* Ai, Bi, Cj, Dj consist of lower case English letters and digits. \ No newline at end of file diff --git a/src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts b/src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts new file mode 100644 index 0000000..d401761 --- /dev/null +++ b/src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts @@ -0,0 +1,63 @@ +// #Medium #Array #Depth_First_Search #Breadth_First_Search #Graph #Union_Find #Shortest_Path +// #LeetCode_75_Graphs/DFS #Top_Interview_150_Graph_General +// #2025_04_16_Time_0_ms_(100.00%)_Space_54.98_MB_(77.31%) + +type MapType = Map +type RateType = Map + +function calcEquation(equations: [string, string][], values: number[], queries: [string, string][]): number[] { + const root: MapType = new Map() + const rate: RateType = new Map() + for (const [x, y] of equations) { + if (!root.has(x)) { + root.set(x, x) + rate.set(x, 1.0) + } + if (!root.has(y)) { + root.set(y, y) + rate.set(y, 1.0) + } + } + for (let i = 0; i < equations.length; ++i) { + const [x, y] = equations[i] + union(x, y, values[i], root, rate) + } + const result: number[] = [] + for (const [x, y] of queries) { + if (!root.has(x) || !root.has(y)) { + result.push(-1.0) + } else { + const rootX = findRoot(x, x, 1.0, root, rate) + const rootY = findRoot(y, y, 1.0, root, rate) + if (rootX === rootY) { + result.push(rate.get(x)! / rate.get(y)!) + } else { + result.push(-1.0) + } + } + } + return result +} + +function union(x: string, y: string, value: number, root: MapType, rate: RateType): void { + const rootX = findRoot(x, x, 1.0, root, rate) + const rootY = findRoot(y, y, 1.0, root, rate) + + if (rootX !== rootY) { + root.set(rootX, rootY) + const rateX = rate.get(x)! + const rateY = rate.get(y)! + rate.set(rootX, (value * rateY) / rateX) + } +} + +function findRoot(originalX: string, x: string, rateSoFar: number, root: MapType, rate: RateType): string { + if (root.get(x) === x) { + root.set(originalX, x) + rate.set(originalX, rateSoFar * rate.get(x)!) + return x + } + return findRoot(originalX, root.get(x)!, rateSoFar * rate.get(x)!, root, rate) +} + +export { calcEquation } diff --git a/src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts b/src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts index 5ad6375..aa05ea4 100644 --- a/src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts +++ b/src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts @@ -1,5 +1,5 @@ // #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Level_2_Day_13_Dynamic_Programming -// #Big_O_Time_O(n*sums)_Space_O(n*sums) #2023_09_30_Time_91_ms_(74.38%)_Space_44.7_MB_(83.25%) +// #Big_O_Time_O(n*sums)_Space_O(n*sums) #2025_03_28_Time_33_ms_(93.24%)_Space_59.12_MB_(71.50%) function canPartition(nums: number[]): boolean { let sums: number = 0 diff --git a/src/main/ts/g0401_0500/s0427_construct_quad_tree/readme.md b/src/main/ts/g0401_0500/s0427_construct_quad_tree/readme.md new file mode 100644 index 0000000..9e9dd3d --- /dev/null +++ b/src/main/ts/g0401_0500/s0427_construct_quad_tree/readme.md @@ -0,0 +1,78 @@ +427\. Construct Quad Tree + +Medium + +Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent the `grid` with a Quad-Tree. + +Return _the root of the Quad-Tree_ representing the `grid`. + +Notice that you can assign the value of a node to **True** or **False** when `isLeaf` is **False**, and both are **accepted** in the answer. + +A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: + +* `val`: True if the node represents a grid of 1's or False if the node represents a grid of 0's. +* `isLeaf`: True if the node is leaf node on the tree or False if the node has the four children. +``` + class Node { + public boolean val; + public boolean isLeaf; + public Node topLeft; + public Node topRight; + public Node bottomLeft; + public Node bottomRight; + } +``` +We can construct a Quad-Tree from a two-dimensional area using the following steps: + +1. If the current grid has the same value (i.e all `1's` or all `0's`) set `isLeaf` True and set `val` to the value of the grid and set the four children to Null and stop. +2. If the current grid has different values, set `isLeaf` to False and set `val` to any value and divide the current grid into four sub-grids as shown in the photo. +3. Recurse for each of the children with the proper sub-grid. + +![](https://assets.leetcode.com/uploads/2020/02/11/new_top.png) + +If you want to know more about the Quad-Tree, you can refer to the [wiki](https://en.wikipedia.org/wiki/Quadtree). + +**Quad-Tree format:** + +The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below. + +It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list `[isLeaf, val]`. + +If the value of `isLeaf` or `val` is True we represent it as **1** in the list `[isLeaf, val]` and if the value of `isLeaf` or `val` is False we represent it as **0**. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/02/11/grid1.png) + +**Input:** grid = [[0,1],[1,0]] + +**Output:** [[0,1],[1,0],[1,1],[1,1],[1,0]] + +**Explanation:** + + The explanation of this example is shown below: + Notice that 0 represnts False and 1 represents True in the photo representing the Quad-Tree. + +![](https://assets.leetcode.com/uploads/2020/02/12/e1tree.png) + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/02/12/e2mat.png) + +**Input:** grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]] + +**Output:** [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]] + +**Explanation:** + + All values in the grid are not the same. We divide the grid into four sub-grids. + The topLeft, bottomLeft and bottomRight each has the same value. + The topRight have different values so we divide it into 4 sub-grids where each has the same value. + Explanation is shown in the photo below: + +![](https://assets.leetcode.com/uploads/2020/02/12/e2tree.png) + +**Constraints:** + +* `n == grid.length == grid[i].length` +* n == 2x where `0 <= x <= 6` diff --git a/src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts b/src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts new file mode 100644 index 0000000..78a00d8 --- /dev/null +++ b/src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts @@ -0,0 +1,93 @@ +// #Medium #Array #Tree #Matrix #Divide_and_Conquer #Top_Interview_150_Divide_and_Conquer +// #2025_04_16_Time_51_ms_(96.23%)_Space_60.83_MB_(77.36%) + +class _Node { + val: boolean + isLeaf: boolean + topLeft: _Node | null + topRight: _Node | null + bottomLeft: _Node | null + bottomRight: _Node | null + + constructor( + val: boolean, + isLeaf: boolean, + topLeft: _Node | null = null, + topRight: _Node | null = null, + bottomLeft: _Node | null = null, + bottomRight: _Node | null = null, + ) { + this.val = val + this.isLeaf = isLeaf + this.topLeft = topLeft + this.topRight = topRight + this.bottomLeft = bottomLeft + this.bottomRight = bottomRight + } + + toString(): string { + return ( + this.getNode(this) + + this.getNode(this.topLeft) + + this.getNode(this.topRight) + + this.getNode(this.bottomLeft) + + this.getNode(this.bottomRight) + ) + } + + private getNode(node: _Node | null): string { + if (node === null) return 'null' + return `[${node.isLeaf ? '1' : '0'},${node.val ? '1' : '0'}]` + } +} + +/** + * Definition for _Node. + * class _Node { + * val: boolean + * isLeaf: boolean + * topLeft: _Node | null + * topRight: _Node | null + * bottomLeft: _Node | null + * bottomRight: _Node | null + * constructor(val?: boolean, isLeaf?: boolean, topLeft?: _Node, topRight?: _Node, bottomLeft?: _Node, bottomRight?: _Node) { + * this.val = (val===undefined ? false : val) + * this.isLeaf = (isLeaf===undefined ? false : isLeaf) + * this.topLeft = (topLeft===undefined ? null : topLeft) + * this.topRight = (topRight===undefined ? null : topRight) + * this.bottomLeft = (bottomLeft===undefined ? null : bottomLeft) + * this.bottomRight = (bottomRight===undefined ? null : bottomRight) + * } + * } + */ +function construct(grid: number[][]): _Node | null { + return build(grid, 0, 0, grid.length) +} + +function build(grid: number[][], row: number, col: number, size: number): _Node { + if (size === 1) { + return new _Node(grid[row][col] === 1, true) + } + let isSame = true + let firstVal = grid[row][col] + for (let i = row; i < row + size; i++) { + for (let j = col; j < col + size; j++) { + if (grid[i][j] !== firstVal) { + isSame = false + break + } + } + if (!isSame) break + } + if (isSame) { + return new _Node(firstVal === 1, true) + } + let newSize = size / 2 + let topLeft = build(grid, row, col, newSize) + let topRight = build(grid, row, col + newSize, newSize) + let bottomLeft = build(grid, row + newSize, col, newSize) + let bottomRight = build(grid, row + newSize, col + newSize, newSize) + return new _Node(true, false, topLeft, topRight, bottomLeft, bottomRight) +} + +export { construct } diff --git a/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/readme.md b/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/readme.md new file mode 100644 index 0000000..852b252 --- /dev/null +++ b/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/readme.md @@ -0,0 +1,41 @@ +433\. Minimum Genetic Mutation + +Medium + +A gene string can be represented by an 8-character long string, with choices from `'A'`, `'C'`, `'G'`, and `'T'`. + +Suppose we need to investigate a mutation from a gene string `start` to a gene string `end` where one mutation is defined as one single character changed in the gene string. + +* For example, `"AACCGGTT" --> "AACCGGTA"` is one mutation. + +There is also a gene bank `bank` that records all the valid gene mutations. A gene must be in `bank` to make it a valid gene string. + +Given the two gene strings `start` and `end` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `start` _to_ `end`. If there is no such a mutation, return `-1`. + +Note that the starting point is assumed to be valid, so it might not be included in the bank. + +**Example 1:** + +**Input:** start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"] + +**Output:** 1 + +**Example 2:** + +**Input:** start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"] + +**Output:** 2 + +**Example 3:** + +**Input:** start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"] + +**Output:** 3 + +**Constraints:** + +* `start.length == 8` +* `end.length == 8` +* `0 <= bank.length <= 10` +* `bank[i].length == 8` +* `start`, `end`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`. diff --git a/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts b/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts new file mode 100644 index 0000000..1768f7e --- /dev/null +++ b/src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts @@ -0,0 +1,41 @@ +// #Medium #String #Hash_Table #Breadth_First_Search #Graph_Theory_I_Day_12_Breadth_First_Search +// #Top_Interview_150_Graph_BFS #2025_04_14_Time_0_ms_(100.00%)_Space_55.27_MB_(71.43%) + +function minMutation(startGene: string, endGene: string, bank: string[]): number { + const isInBank = (set: Set, cur: string): string[] => { + const res: string[] = [] + for (const each of set) { + let diff = 0 + for (let i = 0; i < each.length; i++) { + if (each[i] !== cur[i]) { + diff++ + if (diff > 1) break + } + } + if (diff === 1) { + res.push(each) + } + } + return res + } + const set = new Set(bank) + const queue: string[] = [startGene] + let step = 0 + while (queue.length > 0) { + const curSize = queue.length + for (let i = 0; i < curSize; i++) { + const cur = queue.shift()! + if (cur === endGene) { + return step + } + for (const next of isInBank(set, cur)) { + queue.push(next) + set.delete(next) + } + } + step++ + } + return -1 +} + +export { minMutation } diff --git a/src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts b/src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts index 9a2b73b..bfea432 100644 --- a/src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts +++ b/src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts @@ -1,5 +1,5 @@ -// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Level_2_Day_7_Tree -// #Big_O_Time_O(n)_Space_O(n) #2023_09_30_Time_68_ms_(86.71%)_Space_47.3_MB_(98.10%) +// #Medium #Depth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS #Level_2_Day_7_Tree +// #Big_O_Time_O(n)_Space_O(n) #2025_03_28_Time_3_ms_(86.41%)_Space_61.43_MB_(43.21%) function pathSum(root: TreeNode | null, targetSum: number): number { let count = 0 diff --git a/src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts b/src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts index 4b72af7..6cd3d9b 100644 --- a/src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts +++ b/src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts @@ -1,7 +1,7 @@ // #Medium #Top_100_Liked_Questions #String #Hash_Table #Sliding_Window // #Algorithm_II_Day_5_Sliding_Window #Programming_Skills_II_Day_12 // #Level_1_Day_12_Sliding_Window/Two_Pointer #Big_O_Time_O(n+m)_Space_O(1) -// #2023_09_30_Time_69_ms_(96.69%)_Space_46.1_MB_(80.99%) +// #2025_03_28_Time_8_ms_(97.80%)_Space_59.42_MB_(72.16%) function findAnagrams(s: string, p: string): number[] { const map: number[] = new Array(26).fill(0) diff --git a/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/readme.md b/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/readme.md new file mode 100644 index 0000000..acd3967 --- /dev/null +++ b/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/readme.md @@ -0,0 +1,47 @@ +452\. Minimum Number of Arrows to Burst Balloons + +Medium + +There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array `points` where points[i] = [xstart, xend] denotes a balloon whose **horizontal diameter** stretches between xstart and xend. You do not know the exact y-coordinates of the balloons. + +Arrows can be shot up **directly vertically** (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is **burst** by an arrow shot at `x` if xstart <= x <= xend. There is **no limit** to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path. + +Given the array `points`, return _the **minimum** number of arrows that must be shot to burst all balloons_. + +**Example 1:** + +**Input:** points = [[10,16],[2,8],[1,6],[7,12]] + +**Output:** 2 + +**Explanation:** The balloons can be burst by 2 arrows: + +- Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6]. + +- Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12]. + +**Example 2:** + +**Input:** points = [[1,2],[3,4],[5,6],[7,8]] + +**Output:** 4 + +**Explanation:** One arrow needs to be shot for each balloon for a total of 4 arrows. + +**Example 3:** + +**Input:** points = [[1,2],[2,3],[3,4],[4,5]] + +**Output:** 2 + +**Explanation:** The balloons can be burst by 2 arrows: + +- Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3]. + +- Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5]. + +**Constraints:** + +* 1 <= points.length <= 105 +* `points[i].length == 2` +* -231 <= xstart < xend <= 231 - 1 diff --git a/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.ts b/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.ts new file mode 100644 index 0000000..8e7b241 --- /dev/null +++ b/src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.ts @@ -0,0 +1,20 @@ +// #Medium #Array #Sorting #Greedy #LeetCode_75_Intervals #Top_Interview_150_Intervals +// #2025_04_15_Time_75_ms_(98.54%)_Space_79.44_MB_(62.20%) + +function findMinArrowShots(points: number[][]): number { + if (points.length === 0) { + return 0 + } + points.sort((a, b) => a[1] - b[1]) + let minArrows = 1 + let end = points[0][1] + for (let i = 1; i < points.length; i++) { + if (points[i][0] > end) { + minArrows++ + end = points[i][1] + } + } + return minArrows +} + +export { findMinArrowShots } diff --git a/src/main/ts/g0401_0500/s0494_target_sum/solution.ts b/src/main/ts/g0401_0500/s0494_target_sum/solution.ts index c6fe322..0e08730 100644 --- a/src/main/ts/g0401_0500/s0494_target_sum/solution.ts +++ b/src/main/ts/g0401_0500/s0494_target_sum/solution.ts @@ -1,6 +1,5 @@ -// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Backtracking -// #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s)) -// #2023_09_30_Time_77_ms_(81.99%)_Space_48.3_MB_(62.73%) +// #Medium #Array #Dynamic_Programming #Backtracking #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s)) +// #2025_03_28_Time_24_ms_(83.43%)_Space_63.15_MB_(21.89%) function findTargetSumWays(nums: number[], s: number): number { let sum: number = 0 diff --git a/src/main/ts/g0501_0600/s0502_ipo/readme.md b/src/main/ts/g0501_0600/s0502_ipo/readme.md new file mode 100644 index 0000000..8e36db7 --- /dev/null +++ b/src/main/ts/g0501_0600/s0502_ipo/readme.md @@ -0,0 +1,47 @@ +502\. IPO + +Hard + +Suppose LeetCode will start its **IPO** soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the **IPO**. Since it has limited resources, it can only finish at most `k` distinct projects before the **IPO**. Help LeetCode design the best way to maximize its total capital after finishing at most `k` distinct projects. + +You are given `n` projects where the ith project has a pure profit `profits[i]` and a minimum capital of `capital[i]` is needed to start it. + +Initially, you have `w` capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital. + +Pick a list of **at most** `k` distinct projects from given projects to **maximize your final capital**, and return _the final maximized capital_. + +The answer is guaranteed to fit in a 32-bit signed integer. + +**Example 1:** + +**Input:** k = 2, w = 0, profits = [1,2,3], capital = [0,1,1] + +**Output:** 4 + +**Explanation:** + +Since your initial capital is 0, you can only start the project indexed 0. + +After finishing it you will obtain profit 1 and your capital becomes 1. + +With capital 1, you can either start the project indexed 1 or the project indexed 2. + +Since you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital. + +Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4. + +**Example 2:** + +**Input:** k = 3, w = 0, profits = [1,2,3], capital = [0,1,2] + +**Output:** 6 + +**Constraints:** + +* 1 <= k <= 105 +* 0 <= w <= 109 +* `n == profits.length` +* `n == capital.length` +* 1 <= n <= 105 +* 0 <= profits[i] <= 104 +* 0 <= capital[i] <= 109 diff --git a/src/main/ts/g0501_0600/s0502_ipo/solution.ts b/src/main/ts/g0501_0600/s0502_ipo/solution.ts new file mode 100644 index 0000000..3800003 --- /dev/null +++ b/src/main/ts/g0501_0600/s0502_ipo/solution.ts @@ -0,0 +1,88 @@ +// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue #Top_Interview_150_Heap +// #2025_04_15_Time_193_ms_(89.19%)_Space_102.47_MB_(8.11%) + +class MaxHeap { + private heap: number[] + + constructor() { + this.heap = [] + } + + push(value: number) { + this.heap.push(value) + this.heapifyUp() + } + + pop(): number | undefined { + if (this.heap.length === 0) { + return undefined + } + if (this.heap.length === 1) { + return this.heap.pop() + } + const max = this.heap[0] + this.heap[0] = this.heap.pop()! + this.heapifyDown() + return max + } + + isEmpty(): boolean { + return this.heap.length === 0 + } + + private heapifyUp() { + let index = this.heap.length - 1 + while (index > 0) { + let parentIndex = Math.floor((index - 1) / 2) + if (this.heap[parentIndex] >= this.heap[index]) { + break + } + ;[this.heap[parentIndex], this.heap[index]] = [this.heap[index], this.heap[parentIndex]] + index = parentIndex + } + } + + private heapifyDown() { + let index = 0 + while (true) { + let left = 2 * index + 1 + let right = 2 * index + 2 + let largest = index + if (left < this.heap.length && this.heap[left] > this.heap[largest]) { + largest = left + } + if (right < this.heap.length && this.heap[right] > this.heap[largest]) { + largest = right + } + if (largest === index) { + break + } + ;[this.heap[index], this.heap[largest]] = [this.heap[largest], this.heap[index]] + index = largest + } + } +} + +function findMaximizedCapital(k: number, w: number, profits: number[], capital: number[]): number { + let projects: [number, number][] = [] + const n = profits.length + for (let i = 0; i < n; i++) { + projects.push([capital[i], profits[i]]) + } + projects.sort((a, b) => a[0] - b[0]) + const maxHeap = new MaxHeap() + let i = 0 + while (k--) { + while (i < n && projects[i][0] <= w) { + maxHeap.push(projects[i][1]) + i++ + } + if (maxHeap.isEmpty()) { + break + } + w += maxHeap.pop()! + } + return w +} + +export { findMaximizedCapital } diff --git a/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/readme.md b/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/readme.md new file mode 100644 index 0000000..64fdaa4 --- /dev/null +++ b/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/readme.md @@ -0,0 +1,28 @@ +530\. Minimum Absolute Difference in BST + +Easy + +Given the `root` of a Binary Search Tree (BST), return _the minimum absolute difference between the values of any two different nodes in the tree_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg) + +**Input:** root = [4,2,6,1,3] + +**Output:** 1 + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg) + +**Input:** root = [1,0,48,null,null,12,49] + +**Output:** 1 + +**Constraints:** + +* The number of nodes in the tree is in the range [2, 104]. +* 0 <= Node.val <= 105 + +**Note:** This question is the same as 783: [https://leetcode.com/problems/minimum-distance-between-bst-nodes/](https://leetcode.com/problems/minimum-distance-between-bst-nodes/) diff --git a/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.ts b/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.ts new file mode 100644 index 0000000..e833b6d --- /dev/null +++ b/src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.ts @@ -0,0 +1,37 @@ +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Binary_Search_Tree +// #Top_Interview_150_Binary_Search_Tree #2025_04_15_Time_0_ms_(100.00%)_Space_61.15_MB_(83.13%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function getMinimumDifference(root: TreeNode | null): number { + let ans = Number.MAX_SAFE_INTEGER + let prev: number | null = null + function dfs(node: TreeNode | null) { + if (!node) { + return + } + dfs(node.left) + if (prev !== null) { + ans = Math.min(ans, Math.abs(node.val - prev)) + } + prev = node.val + dfs(node.right) + } + dfs(root) + return ans +} + +export { getMinimumDifference } diff --git a/src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts b/src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts index db0215c..1480bfa 100644 --- a/src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts +++ b/src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts @@ -1,6 +1,6 @@ // #Easy #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Level_2_Day_7_Tree // #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n) -// #2023_09_30_Time_61_ms_(80.89%)_Space_47.4_MB_(18.15%) +// #2025_03_28_Time_1_ms_(87.16%)_Space_63.47_MB_(59.51%) function diameterOfBinaryTree(root: TreeNode | null): number { let ans = 0 diff --git a/src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts b/src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts index 831ff8d..3ccaa10 100644 --- a/src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts +++ b/src/main/ts/g0501_0600/s0560_subarray_sum_equals_k/solution.ts @@ -1,5 +1,5 @@ // #Medium #Top_100_Liked_Questions #Array #Hash_Table #Prefix_Sum #Data_Structure_II_Day_5_Array -// #Big_O_Time_O(n)_Space_O(n) #2023_09_30_Time_70_ms_(92.45%)_Space_52.7_MB_(27.70%) +// #Big_O_Time_O(n)_Space_O(n) #2025_03_28_Time_14_ms_(87.34%)_Space_67.32_MB_(18.02%) function subarraySum(nums: number[], k: number): number { let tempSum: number = 0 diff --git a/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md b/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md new file mode 100644 index 0000000..5dac74e --- /dev/null +++ b/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md @@ -0,0 +1,26 @@ +637\. Average of Levels in Binary Tree + +Easy + +Given the `root` of a binary tree, return _the average value of the nodes on each level in the form of an array_. Answers within 10-5 of the actual answer will be accepted. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/09/avg1-tree.jpg) + +**Input:** root = [3,9,20,null,null,15,7] + +**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg) + +**Input:** root = [3,9,20,15,7] + +**Output:** [3.00000,14.50000,11.00000] + +**Constraints:** + +* The number of nodes in the tree is in the range [1, 104]. +* -231 <= Node.val <= 231 - 1 diff --git a/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.ts b/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.ts new file mode 100644 index 0000000..9dc0d5e --- /dev/null +++ b/src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.ts @@ -0,0 +1,43 @@ +// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree +// #Top_Interview_150_Binary_Tree_BFS #2025_04_15_Time_0_ms_(100.00%)_Space_61.24_MB_(69.52%) + +import { TreeNode } from '../../com_github_leetcode/treenode' + +/** + * Definition for a binary tree node. + * class TreeNode { + * val: number + * left: TreeNode | null + * right: TreeNode | null + * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + * } + */ +function averageOfLevels(root: TreeNode | null): number[] { + if (!root) { + return [] + } + let res = [] + let queue = [root] + while (queue.length) { + let len = queue.length + let sum = 0 + for (let i = 0; i < len; i++) { + let node = queue.shift() + sum += node.val + if (node.left) { + queue.push(node.left) + } + if (node.right) { + queue.push(node.right) + } + } + res.push(sum / len) + } + return res +} + +export { averageOfLevels } diff --git a/src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts b/src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts index e97f100..e4fc2ab 100644 --- a/src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts +++ b/src/main/ts/g0601_0700/s0647_palindromic_substrings/solution.ts @@ -1,5 +1,5 @@ -// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n) -// #2023_09_30_Time_60_ms_(89.76%)_Space_43_MB_(93.98%) +// #Medium #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n) +// #2025_03_28_Time_5_ms_(100.00%)_Space_56.80_MB_(51.20%) function expand(a: string[], l: number, r: number, res: number[]): void { while (l >= 0 && r < a.length) { diff --git a/src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts b/src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts index 77f9d78..65fee87 100644 --- a/src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts +++ b/src/main/ts/g0701_0800/s0739_daily_temperatures/solution.ts @@ -1,5 +1,6 @@ -// #Medium #Top_100_Liked_Questions #Array #Stack #Monotonic_Stack #Programming_Skills_II_Day_6 -// #Big_O_Time_O(n)_Space_O(n) #2023_09_30_Time_194_ms_(97.36%)_Space_66.2_MB_(69.52%) +// #Medium #Top_100_Liked_Questions #Array #Stack #Monotonic_Stack #LeetCode_75_Monotonic_Stack +// #Programming_Skills_II_Day_6 #Big_O_Time_O(n)_Space_O(n) +// #2025_03_28_Time_18_ms_(80.57%)_Space_78.12_MB_(62.08%) function dailyTemperatures(temperatures: number[]): number[] { let stack: number[] = [] diff --git a/src/main/ts/g0701_0800/s0763_partition_labels/solution.ts b/src/main/ts/g0701_0800/s0763_partition_labels/solution.ts index 2cdf78f..a9fdb0e 100644 --- a/src/main/ts/g0701_0800/s0763_partition_labels/solution.ts +++ b/src/main/ts/g0701_0800/s0763_partition_labels/solution.ts @@ -1,6 +1,5 @@ -// #Medium #Top_100_Liked_Questions #String #Hash_Table #Greedy #Two_Pointers -// #Data_Structure_II_Day_7_String #Big_O_Time_O(n)_Space_O(1) -// #2023_09_30_Time_54_ms_(94.74%)_Space_45.2_MB_(56.58%) +// #Medium #String #Hash_Table #Greedy #Two_Pointers #Data_Structure_II_Day_7_String +// #Big_O_Time_O(n)_Space_O(1) #2025_03_28_Time_4_ms_(86.89%)_Space_58.06_MB_(34.43%) function partitionLabels(s: string): number[] { const map = new Map() diff --git a/src/main/ts/g0901_1000/s0909_snakes_and_ladders/readme.md b/src/main/ts/g0901_1000/s0909_snakes_and_ladders/readme.md new file mode 100644 index 0000000..50734a0 --- /dev/null +++ b/src/main/ts/g0901_1000/s0909_snakes_and_ladders/readme.md @@ -0,0 +1,55 @@ +909\. Snakes and Ladders + +Medium + +You are given an `n x n` integer matrix `board` where the cells are labeled from `1` to n2 in a [**Boustrophedon style**](https://en.wikipedia.org/wiki/Boustrophedon) starting from the bottom left of the board (i.e. `board[n - 1][0]`) and alternating direction each row. + +You start on square `1` of the board. In each move, starting from square `curr`, do the following: + +* Choose a destination square `next` with a label in the range [curr + 1, min(curr + 6, n2)]. + * This choice simulates the result of a standard **6-sided die roll**: i.e., there are always at most 6 destinations, regardless of the size of the board. +* If `next` has a snake or ladder, you **must** move to the destination of that snake or ladder. Otherwise, you move to `next`. +* The game ends when you reach the square n2. + +A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and n2 do not have a snake or ladder. + +Note that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder. + +* For example, suppose the board is `[[-1,4],[-1,3]]`, and on the first move, your destination square is `2`. You follow the ladder to square `3`, but do **not** follow the subsequent ladder to `4`. + +Return _the least number of moves required to reach the square_ n2_. If it is not possible to reach the square, return_ `-1`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/09/23/snakes.png) + +**Input:** board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]] + +**Output:** 4 + +**Explanation:** + +In the beginning, you start at square 1 (at row 5, column 0). + +You decide to move to square 2 and must take the ladder to square 15. + +You then decide to move to square 17 and must take the snake to square 13. + +You then decide to move to square 14 and must take the ladder to square 35. + +You then decide to move to square 36, ending the game. + +This is the lowest possible number of moves to reach the last square, so return 4. + +**Example 2:** + +**Input:** board = [[-1,-1],[-1,3]] + +**Output:** 1 + +**Constraints:** + +* `n == board.length == board[i].length` +* `2 <= n <= 20` +* `grid[i][j]` is either `-1` or in the range [1, n2]. +* The squares labeled `1` and n2 do not have any ladders or snakes. diff --git a/src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution.ts b/src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution.ts new file mode 100644 index 0000000..c711d28 --- /dev/null +++ b/src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution.ts @@ -0,0 +1,44 @@ +// #Medium #Array #Breadth_First_Search #Matrix #Top_Interview_150_Graph_BFS +// #2025_04_15_Time_5_ms_(98.27%)_Space_59.74_MB_(65.90%) + +function snakesAndLadders(board: number[][]): number { + const size = board.length + const target = size * size + const visited: boolean[] = new Array(target).fill(false) + const queue: number[] = [] + queue.push(1) + visited[0] = true + let steps = 0 + while (queue.length > 0) { + const levelSize = queue.length + for (let i = 0; i < levelSize; i++) { + const current = queue.shift()! + if (current === target) { + return steps + } + for (let next = current + 1; next <= Math.min(current + 6, target); next++) { + if (visited[next - 1]) continue + visited[next - 1] = true + const [row, col] = indexToPosition(next, size) + const destination = board[row][col] === -1 ? next : board[row][col] + queue.push(destination) + } + } + steps++ + } + + return -1 +} + +function indexToPosition(index: number, size: number): [number, number] { + const row = size - 1 - Math.floor((index - 1) / size) + let col: number + if ((size - row) % 2 === 1) { + col = (index - 1) % size + } else { + col = size - 1 - ((index - 1) % size) + } + return [row, col] +} + +export { snakesAndLadders } diff --git a/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/readme.md b/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/readme.md new file mode 100644 index 0000000..60c43ad --- /dev/null +++ b/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/readme.md @@ -0,0 +1,39 @@ +918\. Maximum Sum Circular Subarray + +Medium + +Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`. + +A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` is `nums[(i - 1 + n) % n]`. + +A **subarray** may only include each element of the fixed buffer `nums` at most once. Formally, for a subarray `nums[i], nums[i + 1], ..., nums[j]`, there does not exist `i <= k1`, `k2 <= j` with `k1 % n == k2 % n`. + +**Example 1:** + +**Input:** nums = [1,-2,3,-2] + +**Output:** 3 + +**Explanation:** Subarray [3] has maximum sum 3. + +**Example 2:** + +**Input:** nums = [5,-3,5] + +**Output:** 10 + +**Explanation:** Subarray [5,5] has maximum sum 5 + 5 = 10. + +**Example 3:** + +**Input:** nums = [-3,-2,-3] + +**Output:** -2 + +**Explanation:** Subarray [-2] has maximum sum -2. + +**Constraints:** + +* `n == nums.length` +* 1 <= n <= 3 * 104 +* -3 * 104 <= nums[i] <= 3 * 104 diff --git a/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts b/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts new file mode 100644 index 0000000..8fadd4a --- /dev/null +++ b/src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.ts @@ -0,0 +1,24 @@ +// #Medium #Array #Dynamic_Programming #Divide_and_Conquer #Queue #Monotonic_Queue +// #Dynamic_Programming_I_Day_5 #Top_Interview_150_Kadane's_Algorithm +// #2025_04_15_Time_2_ms_(91.04%)_Space_61.54_MB_(85.07%) + +function maxSubarraySumCircular(nums: number[]): number { + let total = 0 + let maxSum = nums[0], + curMax = 0 + let minSum = nums[0], + curMin = 0 + for (let num of nums) { + curMax = Math.max(num, curMax + num) + maxSum = Math.max(maxSum, curMax) + curMin = Math.min(num, curMin + num) + minSum = Math.min(minSum, curMin) + total += num + } + if (maxSum < 0) { + return maxSum + } + return Math.max(maxSum, total - minSum) +} + +export { maxSubarraySumCircular } diff --git a/src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts b/src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts index ddfcd36..003fafd 100644 --- a/src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts +++ b/src/main/ts/g1101_1200/s1143_longest_common_subsequence/solution.ts @@ -1,7 +1,7 @@ -// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming +// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional // #Algorithm_II_Day_17_Dynamic_Programming #Dynamic_Programming_I_Day_19 // #Udemy_Dynamic_Programming #Big_O_Time_O(n*m)_Space_O(n*m) -// #2023_09_30_Time_94_ms_(80.56%)_Space_73.5_MB_(53.24%) +// #2025_03_28_Time_50_ms_(69.40%)_Space_85.72_MB_(16.94%) function longestCommonSubsequence(text1: string, text2: string): number { const n: number = text1.length diff --git a/src/test/ts/g0001_0100/s0012_integer_to_roman/solution.test.ts b/src/test/ts/g0001_0100/s0012_integer_to_roman/solution.test.ts new file mode 100644 index 0000000..e489986 --- /dev/null +++ b/src/test/ts/g0001_0100/s0012_integer_to_roman/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { intToRoman } from 'src/main/ts/g0001_0100/s0012_integer_to_roman/solution' +import { expect, test } from 'vitest' + +test('intToRoman', () => { + expect(intToRoman(3749)).toEqual('MMMDCCXLIX') +}) + +test('intToRoman2', () => { + expect(intToRoman(58)).toEqual('LVIII') +}) + +test('intToRoman3', () => { + expect(intToRoman(1994)).toEqual('MCMXCIV') +}) diff --git a/src/test/ts/g0001_0100/s0013_roman_to_integer/solution.test.ts b/src/test/ts/g0001_0100/s0013_roman_to_integer/solution.test.ts new file mode 100644 index 0000000..fc05b04 --- /dev/null +++ b/src/test/ts/g0001_0100/s0013_roman_to_integer/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { romanToInt } from 'src/main/ts/g0001_0100/s0013_roman_to_integer/solution' +import { expect, test } from 'vitest' + +test('romanToInt', () => { + expect(romanToInt('III')).toEqual(3) +}) + +test('romanToInt2', () => { + expect(romanToInt('LVIII')).toEqual(58) +}) + +test('romanToInt3', () => { + expect(romanToInt('MCMXCIV')).toEqual(1994) +}) diff --git a/src/test/ts/g0001_0100/s0014_longest_common_prefix/solution.test.ts b/src/test/ts/g0001_0100/s0014_longest_common_prefix/solution.test.ts new file mode 100644 index 0000000..62b1934 --- /dev/null +++ b/src/test/ts/g0001_0100/s0014_longest_common_prefix/solution.test.ts @@ -0,0 +1,19 @@ +// tslint:disable:no-magic-numbers +import { longestCommonPrefix } from 'src/main/ts/g0001_0100/s0014_longest_common_prefix/solution' +import { expect, test } from 'vitest' + +test('longestCommonPrefix', () => { + expect(longestCommonPrefix(['flower', 'flow', 'flight'])).toEqual('fl') +}) + +test('longestCommonPrefix2', () => { + expect(longestCommonPrefix(['dog', 'racecar', 'car'])).toEqual('') +}) + +test('longestCommonPrefix3', () => { + expect(longestCommonPrefix([])).toEqual('') +}) + +test('longestCommonPrefix4', () => { + expect(longestCommonPrefix(['dog'])).toEqual('dog') +}) diff --git a/src/test/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.test.ts b/src/test/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.test.ts new file mode 100644 index 0000000..b8e0f40 --- /dev/null +++ b/src/test/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { removeDuplicates } from 'src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution' +import { expect, test } from 'vitest' + +test('removeDuplicates', () => { + expect(removeDuplicates([1, 1, 2])).toEqual(2) +}) + +test('removeDuplicates2', () => { + expect(removeDuplicates([0, 0, 1, 1, 1, 2, 2, 3, 3, 4])).toEqual(5) +}) diff --git a/src/test/ts/g0001_0100/s0027_remove_element/solution.test.ts b/src/test/ts/g0001_0100/s0027_remove_element/solution.test.ts new file mode 100644 index 0000000..08f06fd --- /dev/null +++ b/src/test/ts/g0001_0100/s0027_remove_element/solution.test.ts @@ -0,0 +1,30 @@ +// tslint:disable:no-magic-numbers +import { removeElement } from 'src/main/ts/g0001_0100/s0027_remove_element/solution' +import { expect, test } from 'vitest' + +test('removeElement', () => { + expect(removeElement([3, 2, 2, 3], 3)).toEqual(2) +}) + +test('removeElement2', () => { + expect(removeElement([0, 1, 2, 2, 3, 0, 4, 2], 2)).toEqual(5) +}) + +test('removeElement3', () => { + const nums: number[] = [] + const val = 1 + expect(removeElement(nums, val)).toEqual(0) +}) + +test('removeElement4', () => { + const nums = [1, 1, 1, 1] + const val = 1 + expect(removeElement(nums, val)).toEqual(0) +}) + +test('removeElement5', () => { + const nums = [4, 5] + const val = 4 + expect(removeElement(nums, val)).toEqual(1) + expect(nums[0]).toEqual(5) +}) diff --git a/src/test/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.test.ts b/src/test/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.test.ts new file mode 100644 index 0000000..1d1bbd4 --- /dev/null +++ b/src/test/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { strStr } from 'src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution' +import { expect, test } from 'vitest' + +test('strStr', () => { + expect(strStr('sadbutsad', 'sad')).toEqual(0) +}) + +test('strStr2', () => { + expect(strStr('leetcode', 'leeto')).toEqual(-1) +}) + +test('strStr3', () => { + expect(strStr('leetcode', '')).toEqual(0) +}) diff --git a/src/test/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.test.ts b/src/test/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.test.ts new file mode 100644 index 0000000..03206ff --- /dev/null +++ b/src/test/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { findSubstring } from 'src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution' +import { expect, test } from 'vitest' + +test('findSubstring', () => { + expect(findSubstring('barfoothefoobarman', ['foo', 'bar'])).toEqual([0, 9]) +}) + +test('findSubstring2', () => { + expect(findSubstring('wordgoodgoodgoodbestword', ['word', 'good', 'best', 'word'])).toEqual([]) +}) + +test('findSubstring3', () => { + expect(findSubstring('barfoofoobarthefoobarman', ['bar', 'foo', 'the'])).toEqual([6, 9, 12]) +}) diff --git a/src/test/ts/g0001_0100/s0036_valid_sudoku/solution.test.ts b/src/test/ts/g0001_0100/s0036_valid_sudoku/solution.test.ts new file mode 100644 index 0000000..36659a9 --- /dev/null +++ b/src/test/ts/g0001_0100/s0036_valid_sudoku/solution.test.ts @@ -0,0 +1,35 @@ +// tslint:disable:no-magic-numbers +import { isValidSudoku } from 'src/main/ts/g0001_0100/s0036_valid_sudoku/solution' +import { expect, test } from 'vitest' + +test('isValidSudoku', () => { + expect( + isValidSudoku([ + ['5', '3', '.', '.', '7', '.', '.', '.', '.'], + ['6', '.', '.', '1', '9', '5', '.', '.', '.'], + ['.', '9', '8', '.', '.', '.', '.', '6', '.'], + ['8', '.', '.', '.', '6', '.', '.', '.', '3'], + ['4', '.', '.', '8', '.', '3', '.', '.', '1'], + ['7', '.', '.', '.', '2', '.', '.', '.', '6'], + ['.', '6', '.', '.', '.', '.', '2', '8', '.'], + ['.', '.', '.', '4', '1', '9', '.', '.', '5'], + ['.', '.', '.', '.', '8', '.', '.', '7', '9'], + ]), + ).toEqual(true) +}) + +test('isValidSudoku2', () => { + expect( + isValidSudoku([ + ['8', '3', '.', '.', '7', '.', '.', '.', '.'], + ['6', '.', '.', '1', '9', '5', '.', '.', '.'], + ['.', '9', '8', '.', '.', '.', '.', '6', '.'], + ['8', '.', '.', '.', '6', '.', '.', '.', '3'], + ['4', '.', '.', '8', '.', '3', '.', '.', '1'], + ['7', '.', '.', '.', '2', '.', '.', '.', '6'], + ['.', '6', '.', '.', '.', '.', '2', '8', '.'], + ['.', '.', '.', '4', '1', '9', '.', '.', '5'], + ['.', '.', '.', '.', '8', '.', '.', '7', '9'], + ]), + ).toEqual(false) +}) diff --git a/src/test/ts/g0001_0100/s0050_powx_n/solution.test.ts b/src/test/ts/g0001_0100/s0050_powx_n/solution.test.ts new file mode 100644 index 0000000..40375e2 --- /dev/null +++ b/src/test/ts/g0001_0100/s0050_powx_n/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { myPow } from 'src/main/ts/g0001_0100/s0050_powx_n/solution' +import { expect, test } from 'vitest' + +test('myPow', () => { + expect(myPow(2.0, 10)).toEqual(1024.0) +}) + +test('myPow2', () => { + expect(myPow(2.1, 3)).toEqual(9.261000000000001) +}) + +test('myPow3', () => { + expect(myPow(2.0, -2)).toEqual(0.25) +}) diff --git a/src/test/ts/g0001_0100/s0052_n_queens_ii/solution.test.ts b/src/test/ts/g0001_0100/s0052_n_queens_ii/solution.test.ts new file mode 100644 index 0000000..456c671 --- /dev/null +++ b/src/test/ts/g0001_0100/s0052_n_queens_ii/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { totalNQueens } from 'src/main/ts/g0001_0100/s0052_n_queens_ii/solution' +import { expect, test } from 'vitest' + +test('totalNQueens', () => { + expect(totalNQueens(4)).toEqual(2) +}) + +test('totalNQueens2', () => { + expect(totalNQueens(1)).toEqual(1) +}) diff --git a/src/test/ts/g0001_0100/s0054_spiral_matrix/solution.test.ts b/src/test/ts/g0001_0100/s0054_spiral_matrix/solution.test.ts new file mode 100644 index 0000000..bb2901e --- /dev/null +++ b/src/test/ts/g0001_0100/s0054_spiral_matrix/solution.test.ts @@ -0,0 +1,23 @@ +// tslint:disable:no-magic-numbers +import { spiralOrder } from 'src/main/ts/g0001_0100/s0054_spiral_matrix/solution' +import { expect, test } from 'vitest' + +test('spiralOrder', () => { + expect( + spiralOrder([ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ]), + ).toEqual([1, 2, 3, 6, 9, 8, 7, 4, 5]) +}) + +test('spiralOrder2', () => { + expect( + spiralOrder([ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + ]), + ).toEqual([1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]) +}) diff --git a/src/test/ts/g0001_0100/s0057_insert_interval/solution.test.ts b/src/test/ts/g0001_0100/s0057_insert_interval/solution.test.ts new file mode 100644 index 0000000..5dc4062 --- /dev/null +++ b/src/test/ts/g0001_0100/s0057_insert_interval/solution.test.ts @@ -0,0 +1,37 @@ +// tslint:disable:no-magic-numbers +import { insert } from 'src/main/ts/g0001_0100/s0057_insert_interval/solution' +import { expect, test } from 'vitest' + +test('insert', () => { + expect( + insert( + [ + [1, 3], + [6, 9], + ], + [2, 5], + ), + ).toEqual([ + [1, 5], + [6, 9], + ]) +}) + +test('insert2', () => { + expect( + insert( + [ + [1, 2], + [3, 5], + [6, 7], + [8, 10], + [12, 16], + ], + [4, 8], + ), + ).toEqual([ + [1, 2], + [3, 10], + [12, 16], + ]) +}) diff --git a/src/test/ts/g0001_0100/s0058_length_of_last_word/solution.test.ts b/src/test/ts/g0001_0100/s0058_length_of_last_word/solution.test.ts new file mode 100644 index 0000000..d3bb8fd --- /dev/null +++ b/src/test/ts/g0001_0100/s0058_length_of_last_word/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { lengthOfLastWord } from 'src/main/ts/g0001_0100/s0058_length_of_last_word/solution' +import { expect, test } from 'vitest' + +test('lengthOfLastWord', () => { + expect(lengthOfLastWord('Hello World')).toEqual(5) +}) + +test('lengthOfLastWord2', () => { + expect(lengthOfLastWord(' fly me to the moon ')).toEqual(4) +}) + +test('lengthOfLastWord3', () => { + expect(lengthOfLastWord('luffy is still joyboy')).toEqual(6) +}) diff --git a/src/test/ts/g0001_0100/s0061_rotate_list/solution.test.ts b/src/test/ts/g0001_0100/s0061_rotate_list/solution.test.ts new file mode 100644 index 0000000..7fa2109 --- /dev/null +++ b/src/test/ts/g0001_0100/s0061_rotate_list/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { rotateRight } from 'src/main/ts/g0001_0100/s0061_rotate_list/solution' +import { expect, test } from 'vitest' +import { constructLinkedList } from '../../com_github_leetcode/linkedlistutils' + +test('rotateRight', () => { + expect(rotateRight(constructLinkedList([1, 2, 3, 4, 5]), 2).toString()).toEqual('4, 5, 1, 2, 3') +}) + +test('rotateRight2', () => { + expect(rotateRight(constructLinkedList([0, 1, 2]), 4).toString()).toEqual('2, 0, 1') +}) diff --git a/src/test/ts/g0001_0100/s0063_unique_paths_ii/solution.test.ts b/src/test/ts/g0001_0100/s0063_unique_paths_ii/solution.test.ts new file mode 100644 index 0000000..dde6cd1 --- /dev/null +++ b/src/test/ts/g0001_0100/s0063_unique_paths_ii/solution.test.ts @@ -0,0 +1,22 @@ +// tslint:disable:no-magic-numbers +import { uniquePathsWithObstacles } from 'src/main/ts/g0001_0100/s0063_unique_paths_ii/solution' +import { expect, test } from 'vitest' + +test('uniquePathsWithObstacles', () => { + expect( + uniquePathsWithObstacles([ + [0, 0, 0], + [0, 1, 0], + [0, 0, 0], + ]), + ).toEqual(2) +}) + +test('uniquePathsWithObstacles2', () => { + expect( + uniquePathsWithObstacles([ + [0, 1], + [0, 0], + ]), + ).toEqual(1) +}) diff --git a/src/test/ts/g0001_0100/s0066_plus_one/solution.test.ts b/src/test/ts/g0001_0100/s0066_plus_one/solution.test.ts new file mode 100644 index 0000000..3b4ec47 --- /dev/null +++ b/src/test/ts/g0001_0100/s0066_plus_one/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { plusOne } from 'src/main/ts/g0001_0100/s0066_plus_one/solution' +import { expect, test } from 'vitest' + +test('plusOne', () => { + expect(plusOne([1, 2, 3])).toEqual([1, 2, 4]) +}) + +test('plusOne2', () => { + expect(plusOne([4, 3, 2, 1])).toEqual([4, 3, 2, 2]) +}) + +test('plusOne3', () => { + expect(plusOne([9])).toEqual([1, 0]) +}) diff --git a/src/test/ts/g0001_0100/s0067_add_binary/solution.test.ts b/src/test/ts/g0001_0100/s0067_add_binary/solution.test.ts new file mode 100644 index 0000000..b6c5ce3 --- /dev/null +++ b/src/test/ts/g0001_0100/s0067_add_binary/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { addBinary } from 'src/main/ts/g0001_0100/s0067_add_binary/solution' +import { expect, test } from 'vitest' + +test('addBinary', () => { + expect(addBinary('11', '1')).toEqual('100') +}) + +test('addBinary2', () => { + expect(addBinary('1010', '1011')).toEqual('10101') +}) diff --git a/src/test/ts/g0001_0100/s0068_text_justification/solution.test.ts b/src/test/ts/g0001_0100/s0068_text_justification/solution.test.ts new file mode 100644 index 0000000..3333d34 --- /dev/null +++ b/src/test/ts/g0001_0100/s0068_text_justification/solution.test.ts @@ -0,0 +1,54 @@ +// tslint:disable:no-magic-numbers +import { fullJustify } from 'src/main/ts/g0001_0100/s0068_text_justification/solution' +import { expect, test } from 'vitest' + +test('fullJustify', () => { + expect(fullJustify(['This', 'is', 'an', 'example', 'of', 'text', 'justification.'], 16)).toEqual([ + 'This is an', + 'example of text', + 'justification. ', + ]) +}) + +test('fullJustify2', () => { + expect(fullJustify(['What', 'must', 'be', 'acknowledgment', 'shall', 'be'], 16)).toEqual([ + 'What must be', + 'acknowledgment ', + 'shall be ', + ]) +}) + +test('fullJustify3', () => { + expect( + fullJustify( + [ + 'Science', + 'is', + 'what', + 'we', + 'understand', + 'well', + 'enough', + 'to', + 'explain', + 'to', + 'a', + 'computer.', + 'Art', + 'is', + 'everything', + 'else', + 'we', + 'do', + ], + 20, + ), + ).toEqual([ + 'Science is what we', + 'understand well', + 'enough to explain to', + 'a computer. Art is', + 'everything else we', + 'do ', + ]) +}) diff --git a/src/test/ts/g0001_0100/s0069_sqrtx/solution.test.ts b/src/test/ts/g0001_0100/s0069_sqrtx/solution.test.ts new file mode 100644 index 0000000..15cf769 --- /dev/null +++ b/src/test/ts/g0001_0100/s0069_sqrtx/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { mySqrt } from 'src/main/ts/g0001_0100/s0069_sqrtx/solution' +import { expect, test } from 'vitest' + +test('mySqrt', () => { + expect(mySqrt(4)).toEqual(2) +}) + +test('mySqrt2', () => { + expect(mySqrt(8)).toEqual(2) +}) diff --git a/src/test/ts/g0001_0100/s0071_simplify_path/solution.test.ts b/src/test/ts/g0001_0100/s0071_simplify_path/solution.test.ts new file mode 100644 index 0000000..9e9bcd9 --- /dev/null +++ b/src/test/ts/g0001_0100/s0071_simplify_path/solution.test.ts @@ -0,0 +1,23 @@ +// tslint:disable:no-magic-numbers +import { simplifyPath } from 'src/main/ts/g0001_0100/s0071_simplify_path/solution' +import { expect, test } from 'vitest' + +test('simplifyPath', () => { + expect(simplifyPath('/home/')).toEqual('/home') +}) + +test('simplifyPath2', () => { + expect(simplifyPath('/home//foo/')).toEqual('/home/foo') +}) + +test('simplifyPath3', () => { + expect(simplifyPath('/home/user/Documents/../Pictures')).toEqual('/home/user/Pictures') +}) + +test('simplifyPath4', () => { + expect(simplifyPath('/../')).toEqual('/') +}) + +test('simplifyPath5', () => { + expect(simplifyPath('/.../a/../b/c/../d/./')).toEqual('/.../b/d') +}) diff --git a/src/test/ts/g0001_0100/s0077_combinations/solution.test.ts b/src/test/ts/g0001_0100/s0077_combinations/solution.test.ts new file mode 100644 index 0000000..b548d1e --- /dev/null +++ b/src/test/ts/g0001_0100/s0077_combinations/solution.test.ts @@ -0,0 +1,18 @@ +// tslint:disable:no-magic-numbers +import { combine } from 'src/main/ts/g0001_0100/s0077_combinations/solution' +import { expect, test } from 'vitest' + +test('combine', () => { + expect(combine(4, 2)).toEqual([ + [1, 2], + [1, 3], + [1, 4], + [2, 3], + [2, 4], + [3, 4], + ]) +}) + +test('combine2', () => { + expect(combine(1, 1)).toEqual([[1]]) +}) diff --git a/src/test/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.test.ts b/src/test/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.test.ts new file mode 100644 index 0000000..6a2960c --- /dev/null +++ b/src/test/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { removeDuplicates } from 'src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution' +import { expect, test } from 'vitest' + +test('removeDuplicates', () => { + expect(removeDuplicates([1, 1, 1, 2, 2, 3])).toEqual(5) +}) + +test('removeDuplicates2', () => { + expect(removeDuplicates([0, 0, 1, 1, 1, 1, 2, 3, 3])).toEqual(7) +}) diff --git a/src/test/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.test.ts b/src/test/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.test.ts new file mode 100644 index 0000000..e3a6d05 --- /dev/null +++ b/src/test/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { deleteDuplicates } from 'src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution' +import { expect, test } from 'vitest' +import { constructLinkedList } from '../../com_github_leetcode/linkedlistutils' + +test('deleteDuplicates', () => { + expect(deleteDuplicates(constructLinkedList([1, 2, 3, 3, 4, 4, 5])).toString()).toEqual('1, 2, 5') +}) + +test('deleteDuplicates2', () => { + expect(deleteDuplicates(constructLinkedList([1, 1, 1, 2, 3])).toString()).toEqual('2, 3') +}) diff --git a/src/test/ts/g0001_0100/s0086_partition_list/solution.test.ts b/src/test/ts/g0001_0100/s0086_partition_list/solution.test.ts new file mode 100644 index 0000000..2e2f174 --- /dev/null +++ b/src/test/ts/g0001_0100/s0086_partition_list/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { partition } from 'src/main/ts/g0001_0100/s0086_partition_list/solution' +import { expect, test } from 'vitest' +import { constructLinkedList } from '../../com_github_leetcode/linkedlistutils' + +test('partition', () => { + expect(partition(constructLinkedList([1, 4, 3, 2, 5, 2]), 3).toString()).toEqual('1, 2, 2, 4, 3, 5') +}) + +test('partition2', () => { + expect(partition(constructLinkedList([2, 1]), 2).toString()).toEqual('1, 2') +}) diff --git a/src/test/ts/g0001_0100/s0088_merge_sorted_array/solution.test.ts b/src/test/ts/g0001_0100/s0088_merge_sorted_array/solution.test.ts new file mode 100644 index 0000000..b1bfd97 --- /dev/null +++ b/src/test/ts/g0001_0100/s0088_merge_sorted_array/solution.test.ts @@ -0,0 +1,21 @@ +// tslint:disable:no-magic-numbers +import { merge } from 'src/main/ts/g0001_0100/s0088_merge_sorted_array/solution' +import { expect, test } from 'vitest' + +test('merge', () => { + const nums1 = [1, 2, 3, 0, 0, 0] + merge(nums1, 3, [2, 5, 6], 3) + expect(nums1).toEqual([1, 2, 2, 3, 5, 6]) +}) + +test('merge2', () => { + const nums1 = [1] + merge(nums1, 1, [], 0) + expect(nums1).toEqual([1]) +}) + +test('merge3', () => { + const nums1 = [0] + merge(nums1, 0, [1], 1) + expect(nums1).toEqual([1]) +}) diff --git a/src/test/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.test.ts b/src/test/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.test.ts new file mode 100644 index 0000000..6377584 --- /dev/null +++ b/src/test/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { reverseBetween } from 'src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution' +import { expect, test } from 'vitest' +import { constructLinkedList } from '../../com_github_leetcode/linkedlistutils' + +test('reverseBetween', () => { + expect(reverseBetween(constructLinkedList([1, 2, 3, 4, 5]), 2, 4).toString()).toEqual('1, 4, 3, 2, 5') +}) + +test('reverseBetween2', () => { + expect(reverseBetween(constructLinkedList([5]), 1, 1).toString()).toEqual('5') +}) diff --git a/src/test/ts/g0001_0100/s0097_interleaving_string/solution.test.ts b/src/test/ts/g0001_0100/s0097_interleaving_string/solution.test.ts new file mode 100644 index 0000000..8c6335f --- /dev/null +++ b/src/test/ts/g0001_0100/s0097_interleaving_string/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { isInterleave } from 'src/main/ts/g0001_0100/s0097_interleaving_string/solution' +import { expect, test } from 'vitest' + +test('isInterleave', () => { + expect(isInterleave('aabcc', 'dbbca', 'aadbbcbcac')).toEqual(true) +}) + +test('isInterleave2', () => { + expect(isInterleave('aabcc', 'dbbca', 'aadbbbaccc')).toEqual(false) +}) diff --git a/src/test/ts/g0001_0100/s0100_same_tree/solution.test.ts b/src/test/ts/g0001_0100/s0100_same_tree/solution.test.ts new file mode 100644 index 0000000..6f994a4 --- /dev/null +++ b/src/test/ts/g0001_0100/s0100_same_tree/solution.test.ts @@ -0,0 +1,16 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { isSameTree } from 'src/main/ts/g0001_0100/s0100_same_tree/solution' +import { expect, test } from 'vitest' + +test('isSameTree', () => { + expect(isSameTree(createTreeNode([1, 2, 3]), createTreeNode([1, 2, 3]))).toEqual(true) +}) + +test('isSameTree2', () => { + expect(isSameTree(createTreeNode([1, 2, 3]), createTreeNode([1, null, 2]))).toEqual(false) +}) + +test('isSameTree3', () => { + expect(isSameTree(createTreeNode([1, 2, 1]), createTreeNode([1, 1, 2]))).toEqual(false) +}) diff --git a/src/test/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.test.ts b/src/test/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.test.ts new file mode 100644 index 0000000..96bda40 --- /dev/null +++ b/src/test/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.test.ts @@ -0,0 +1,16 @@ +// tslint:disable:no-magic-numbers +import { zigzagLevelOrder } from 'src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution' +import { expect, test } from 'vitest' +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' + +test('zigzagLevelOrder', () => { + expect(zigzagLevelOrder(createTreeNode([3, 9, 20, null, null, 15, 7]))).toEqual([[3], [20, 9], [15, 7]]) +}) + +test('zigzagLevelOrder2', () => { + expect(zigzagLevelOrder(createTreeNode([1]))).toEqual([[1]]) +}) + +test('zigzagLevelOrder3', () => { + expect(zigzagLevelOrder(createTreeNode([]))).toEqual([]) +}) diff --git a/src/test/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.test.ts b/src/test/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.test.ts new file mode 100644 index 0000000..8168042 --- /dev/null +++ b/src/test/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { buildTree } from 'src/main/ts/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/solution' +import { expect, test } from 'vitest' +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' + +test('buildTree', () => { + expect(buildTree([9, 3, 15, 20, 7], [9, 15, 7, 20, 3])).toEqual(createTreeNode([3, 9, 20, null, null, 15, 7])) +}) + +test('buildTree', () => { + expect(buildTree([-1], [-1])).toEqual(createTreeNode([-1])) +}) diff --git a/src/test/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.test.ts b/src/test/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.test.ts new file mode 100644 index 0000000..9ca1b18 --- /dev/null +++ b/src/test/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { sortedArrayToBST } from 'src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution' +import { expect, test } from 'vitest' +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' + +test('sortedArrayToBST', () => { + expect(sortedArrayToBST([-10, -3, 0, 5, 9])).toEqual(createTreeNode([0, -10, 5, null, -3, null, 9])) +}) + +test('sortedArrayToBST2', () => { + expect(sortedArrayToBST([1, 3])).toEqual(createTreeNode([1, null, 3])) +}) diff --git a/src/test/ts/g0101_0200/s0112_path_sum/solution.test.ts b/src/test/ts/g0101_0200/s0112_path_sum/solution.test.ts new file mode 100644 index 0000000..9f3a658 --- /dev/null +++ b/src/test/ts/g0101_0200/s0112_path_sum/solution.test.ts @@ -0,0 +1,16 @@ +// tslint:disable:no-magic-numbers +import { hasPathSum } from 'src/main/ts/g0101_0200/s0112_path_sum/solution' +import { expect, test } from 'vitest' +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' + +test('hasPathSum', () => { + expect(hasPathSum(createTreeNode([5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1]), 22)).toEqual(true) +}) + +test('hasPathSum2', () => { + expect(hasPathSum(createTreeNode([1, 2, 3]), 5)).toEqual(false) +}) + +test('hasPathSum3', () => { + expect(hasPathSum(createTreeNode([]), 0)).toEqual(false) +}) diff --git a/src/test/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.test.ts b/src/test/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.test.ts new file mode 100644 index 0000000..57f4d23 --- /dev/null +++ b/src/test/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution.test.ts @@ -0,0 +1,48 @@ +// tslint:disable:no-magic-numbers +import { _Node } from 'src/main/ts/com_github_leetcode/_node' +import { connect } from 'src/main/ts/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/solution' +import { expect, test } from 'vitest' + +test('connect', () => { + expect(connect(null)).toBeNull() +}) + +test('connect2', () => { + const node = new _Node( + 1, + new _Node(2, new _Node(4), new _Node(5), null), + new _Node(3, null, new _Node(7), null), + null, + ) + + const node7 = new _Node(7) + const node3 = new _Node(3, null, node7, null) + const node5 = new _Node(5, null, null, node7) + const node4 = new _Node(4, null, null, node5) + const node2 = new _Node(2, node4, node5, node3) + const node1 = new _Node(1, node2, node3, null) + + expect(connect(node)).toEqual(node1) +}) + +test('connect3', () => { + const node = new _Node( + 1, + new _Node(2, new _Node(4, new _Node(7), null, null), new _Node(5), null), + new _Node(3, null, new _Node(6, null, new _Node(8), null), null), + null, + ) + + // Creating expected output tree with connections + const node8 = new _Node(8, null, null, null) + const node7 = new _Node(7, null, null, node8) + const node6 = new _Node(6, null, node8, null) + const node3 = new _Node(3, null, node6, null) + const node5 = new _Node(5, null, null, node6) + const node4 = new _Node(4, node7, null, node5) + const node2 = new _Node(2, node4, node5, node3) + const node1 = new _Node(1, node2, node3, null) + + // Connect nodes and compare + expect(connect(node)).toEqual(node1) +}) diff --git a/src/test/ts/g0101_0200/s0120_triangle/solution.test.ts b/src/test/ts/g0101_0200/s0120_triangle/solution.test.ts new file mode 100644 index 0000000..4404f47 --- /dev/null +++ b/src/test/ts/g0101_0200/s0120_triangle/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { minimumTotal } from 'src/main/ts/g0101_0200/s0120_triangle/solution' +import { expect, test } from 'vitest' + +test('minimumTotal', () => { + expect(minimumTotal([[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]])).toEqual(11) +}) + +test('minimumTotal2', () => { + expect(minimumTotal([[-10]])).toEqual(-10) +}) diff --git a/src/test/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.test.ts b/src/test/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.test.ts new file mode 100644 index 0000000..82d46de --- /dev/null +++ b/src/test/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { maxProfit } from 'src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution' +import { expect, test } from 'vitest' + +test('maxProfit', () => { + expect(maxProfit([7, 1, 5, 3, 6, 4])).toEqual(7) +}) + +test('maxProfit2', () => { + expect(maxProfit([1, 2, 3, 4, 5])).toEqual(4) +}) + +test('maxProfit3', () => { + expect(maxProfit([7, 6, 4, 3, 1])).toEqual(0) +}) diff --git a/src/test/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.test.ts b/src/test/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.test.ts new file mode 100644 index 0000000..7c73ba3 --- /dev/null +++ b/src/test/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { maxProfit } from 'src/main/ts/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/solution' +import { expect, test } from 'vitest' + +test('maxProfit', () => { + expect(maxProfit([3, 3, 5, 0, 0, 3, 1, 4])).toEqual(6) +}) + +test('maxProfit2', () => { + expect(maxProfit([1, 2, 3, 4, 5])).toEqual(4) +}) + +test('maxProfit6', () => { + expect(maxProfit([7, 6, 4, 3, 1])).toEqual(0) +}) diff --git a/src/test/ts/g0101_0200/s0125_valid_palindrome/solution.test.ts b/src/test/ts/g0101_0200/s0125_valid_palindrome/solution.test.ts new file mode 100644 index 0000000..1b30a84 --- /dev/null +++ b/src/test/ts/g0101_0200/s0125_valid_palindrome/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { isPalindrome } from 'src/main/ts/g0101_0200/s0125_valid_palindrome/solution' +import { expect, test } from 'vitest' + +test('isPalindrome', () => { + expect(isPalindrome('A man, a plan, a canal: Panama')).toEqual(true) +}) + +test('isPalindrome2', () => { + expect(isPalindrome('race a car')).toEqual(false) +}) + +test('isPalindrome3', () => { + expect(isPalindrome(' ')).toEqual(true) +}) diff --git a/src/test/ts/g0101_0200/s0127_word_ladder/solution.test.ts b/src/test/ts/g0101_0200/s0127_word_ladder/solution.test.ts new file mode 100644 index 0000000..03d5d2c --- /dev/null +++ b/src/test/ts/g0101_0200/s0127_word_ladder/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { ladderLength } from 'src/main/ts/g0101_0200/s0127_word_ladder/solution' +import { expect, test } from 'vitest' + +test('ladderLength', () => { + expect(ladderLength('hit', 'cog', ['hot', 'dot', 'dog', 'lot', 'log', 'cog'])).toEqual(5) +}) + +test('ladderLength2', () => { + expect(ladderLength('hit', 'cog', ['hot', 'dot', 'dog', 'lot', 'log'])).toEqual(0) +}) diff --git a/src/test/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.test.ts b/src/test/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.test.ts new file mode 100644 index 0000000..a123294 --- /dev/null +++ b/src/test/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { sumNumbers } from 'src/main/ts/g0101_0200/s0129_sum_root_to_leaf_numbers/solution' +import { expect, test } from 'vitest' + +test('sumNumbers', () => { + expect(sumNumbers(createTreeNode([1, 2, 3]))).toEqual(25) +}) + +test('sumNumbers2', () => { + expect(sumNumbers(createTreeNode([4, 9, 0, 5, 1]))).toEqual(1026) +}) diff --git a/src/test/ts/g0101_0200/s0130_surrounded_regions/solution.test.ts b/src/test/ts/g0101_0200/s0130_surrounded_regions/solution.test.ts new file mode 100644 index 0000000..13ec8cd --- /dev/null +++ b/src/test/ts/g0101_0200/s0130_surrounded_regions/solution.test.ts @@ -0,0 +1,25 @@ +// tslint:disable:no-magic-numbers +import { solve } from 'src/main/ts/g0101_0200/s0130_surrounded_regions/solution' +import { expect, test } from 'vitest' + +test('solve', () => { + const board: string[][] = [ + ['X', 'X', 'X', 'X'], + ['X', 'O', 'O', 'X'], + ['X', 'X', 'O', 'X'], + ['X', 'O', 'X', 'X'], + ] + solve(board) + expect(board).toEqual([ + ['X', 'X', 'X', 'X'], + ['X', 'X', 'X', 'X'], + ['X', 'X', 'X', 'X'], + ['X', 'O', 'X', 'X'], + ]) +}) + +test('solve', () => { + const board: string[][] = [['X']] + solve(board) + expect(board).toEqual([['X']]) +}) diff --git a/src/test/ts/g0101_0200/s0133_clone_graph/solution.test.ts b/src/test/ts/g0101_0200/s0133_clone_graph/solution.test.ts new file mode 100644 index 0000000..1fd2f9d --- /dev/null +++ b/src/test/ts/g0101_0200/s0133_clone_graph/solution.test.ts @@ -0,0 +1,22 @@ +// tslint:disable:no-magic-numbers +import { Node, cloneGraph } from 'src/main/ts/g0101_0200/s0133_clone_graph/solution' +import { expect, test } from 'vitest' + +test('cloneGraph', () => { + const node1 = new Node(1) + const node2 = new Node(2) + const node3 = new Node(3) + const node4 = new Node(4) + node1.neighbors = [node2, node4] + node2.neighbors = [node1, node3] + node3.neighbors = [node2, node4] + node4.neighbors = [node1, node3] + const clonedNode1 = cloneGraph(node1) + expect(clonedNode1?.toString()).toEqual('[[1,3],[1,3]]') +}) + +test('cloneGraph2', () => { + const node1 = new Node(1) + const clonedNode1 = cloneGraph(node1) + expect(clonedNode1?.toString()).toEqual('[]') +}) diff --git a/src/test/ts/g0101_0200/s0134_gas_station/solution.test.ts b/src/test/ts/g0101_0200/s0134_gas_station/solution.test.ts new file mode 100644 index 0000000..d13aeea --- /dev/null +++ b/src/test/ts/g0101_0200/s0134_gas_station/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { canCompleteCircuit } from 'src/main/ts/g0101_0200/s0134_gas_station/solution' +import { expect, test } from 'vitest' + +test('canCompleteCircuit', () => { + expect(canCompleteCircuit([1, 2, 3, 4, 5], [3, 4, 5, 1, 2])).toEqual(3) +}) + +test('canCompleteCircuit2', () => { + expect(canCompleteCircuit([2, 3, 4], [3, 4, 3])).toEqual(-1) +}) diff --git a/src/test/ts/g0101_0200/s0135_candy/solution.test.ts b/src/test/ts/g0101_0200/s0135_candy/solution.test.ts new file mode 100644 index 0000000..92f5cde --- /dev/null +++ b/src/test/ts/g0101_0200/s0135_candy/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { candy } from 'src/main/ts/g0101_0200/s0135_candy/solution' +import { expect, test } from 'vitest' + +test('candy', () => { + expect(candy([1, 0, 2])).toEqual(5) +}) + +test('candy2', () => { + expect(candy([1, 2, 2])).toEqual(4) +}) diff --git a/src/test/ts/g0101_0200/s0137_single_number_ii/solution.test.ts b/src/test/ts/g0101_0200/s0137_single_number_ii/solution.test.ts new file mode 100644 index 0000000..dbb3717 --- /dev/null +++ b/src/test/ts/g0101_0200/s0137_single_number_ii/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { singleNumber } from 'src/main/ts/g0101_0200/s0137_single_number_ii/solution' +import { expect, test } from 'vitest' + +test('singleNumber', () => { + expect(singleNumber([2, 2, 3, 2])).toEqual(3) +}) + +test('singleNumber2', () => { + expect(singleNumber([0, 1, 0, 1, 0, 1, 99])).toEqual(99) +}) diff --git a/src/test/ts/g0101_0200/s0149_max_points_on_a_line/solution.test.ts b/src/test/ts/g0101_0200/s0149_max_points_on_a_line/solution.test.ts new file mode 100644 index 0000000..2934c36 --- /dev/null +++ b/src/test/ts/g0101_0200/s0149_max_points_on_a_line/solution.test.ts @@ -0,0 +1,26 @@ +// tslint:disable:no-magic-numbers +import { maxPoints } from 'src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution' +import { expect, test } from 'vitest' + +test('maxPoints', () => { + expect( + maxPoints([ + [1, 1], + [2, 2], + [3, 3], + ]), + ).toEqual(3) +}) + +test('maxPoints2', () => { + expect( + maxPoints([ + [1, 1], + [3, 2], + [5, 3], + [4, 1], + [2, 3], + [1, 4], + ]), + ).toEqual(4) +}) diff --git a/src/test/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.test.ts b/src/test/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.test.ts new file mode 100644 index 0000000..2a4048f --- /dev/null +++ b/src/test/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { evalRPN } from 'src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution' +import { expect, test } from 'vitest' + +test('evalRPN', () => { + expect(evalRPN(['2', '1', '+', '3', '*'])).toEqual(9) +}) + +test('evalRPN2', () => { + expect(evalRPN(['4', '13', '5', '/', '+'])).toEqual(6) +}) + +test('evalRPN3', () => { + expect(evalRPN(['10', '6', '9', '3', '+', '-11', '*', '/', '*', '17', '+', '5', '+'])).toEqual(22) +}) diff --git a/src/test/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.test.ts b/src/test/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.test.ts new file mode 100644 index 0000000..5477310 --- /dev/null +++ b/src/test/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { reverseWords } from 'src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution' +import { expect, test } from 'vitest' + +test('reverseWords', () => { + expect(reverseWords('the sky is blue')).toEqual('blue is sky the') +}) + +test('reverseWords2', () => { + expect(reverseWords(' hello world ')).toEqual('world hello') +}) + +test('reverseWords3', () => { + expect(reverseWords('a good example')).toEqual('example good a') +}) diff --git a/src/test/ts/g0101_0200/s0162_find_peak_element/solution.test.ts b/src/test/ts/g0101_0200/s0162_find_peak_element/solution.test.ts new file mode 100644 index 0000000..74ece3c --- /dev/null +++ b/src/test/ts/g0101_0200/s0162_find_peak_element/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { findPeakElement } from 'src/main/ts/g0101_0200/s0162_find_peak_element/solution' +import { expect, test } from 'vitest' + +test('findPeakElement', () => { + expect(findPeakElement([1, 2, 3, 1])).toEqual(2) +}) + +test('findPeakElement2', () => { + expect(findPeakElement([1, 2, 1, 3, 5, 6, 4])).toEqual(5) +}) diff --git a/src/test/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.test.ts b/src/test/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.test.ts new file mode 100644 index 0000000..58aea70 --- /dev/null +++ b/src/test/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { twoSum } from 'src/main/ts/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/solution' +import { expect, test } from 'vitest' + +test('twoSum', () => { + expect(twoSum([2, 7, 11, 15], 9)).toEqual([1, 2]) +}) + +test('twoSum2', () => { + expect(twoSum([2, 3, 4], 6)).toEqual([1, 3]) +}) + +test('twoSum3', () => { + expect(twoSum([-1, 0], -1)).toEqual([1, 2]) +}) diff --git a/src/test/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.test.ts b/src/test/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.test.ts new file mode 100644 index 0000000..c555973 --- /dev/null +++ b/src/test/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { trailingZeroes } from 'src/main/ts/g0101_0200/s0172_factorial_trailing_zeroes/solution' +import { expect, test } from 'vitest' + +test('trailingZeroes', () => { + expect(trailingZeroes(3)).toEqual(0) +}) + +test('trailingZeroes2', () => { + expect(trailingZeroes(5)).toEqual(1) +}) + +test('trailingZeroe3', () => { + expect(trailingZeroes(0)).toEqual(0) +}) diff --git a/src/test/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.test.ts b/src/test/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.test.ts new file mode 100644 index 0000000..433ad23 --- /dev/null +++ b/src/test/ts/g0101_0200/s0173_binary_search_tree_iterator/solution.test.ts @@ -0,0 +1,17 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { BSTIterator } from 'src/main/ts/g0101_0200/s0173_binary_search_tree_iterator/solution' +import { expect, test } from 'vitest' + +test('bSTIterator', () => { + const bSTIterator = new BSTIterator(createTreeNode([7, 3, 15, null, null, 9, 20])) + expect(bSTIterator.next()).toEqual(3) + expect(bSTIterator.next()).toEqual(7) + expect(bSTIterator.hasNext()).toBeTruthy() + expect(bSTIterator.next()).toEqual(9) + expect(bSTIterator.hasNext()).toBeTruthy() + expect(bSTIterator.next()).toEqual(15) + expect(bSTIterator.hasNext()).toBeTruthy() + expect(bSTIterator.next()).toEqual(20) + expect(bSTIterator.hasNext()).toBeFalsy() +}) diff --git a/src/test/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.test.ts b/src/test/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.test.ts new file mode 100644 index 0000000..4225084 --- /dev/null +++ b/src/test/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { maxProfit } from 'src/main/ts/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/solution' +import { expect, test } from 'vitest' + +test('maxProfit', () => { + expect(maxProfit(2, [2, 4, 1])).toEqual(2) +}) + +test('maxProfit2', () => { + expect(maxProfit(2, [3, 2, 6, 5, 0, 3])).toEqual(7) +}) diff --git a/src/test/ts/g0101_0200/s0190_reverse_bits/solution.test.ts b/src/test/ts/g0101_0200/s0190_reverse_bits/solution.test.ts new file mode 100644 index 0000000..27cac28 --- /dev/null +++ b/src/test/ts/g0101_0200/s0190_reverse_bits/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { reverseBits } from 'src/main/ts/g0101_0200/s0190_reverse_bits/solution' +import { expect, test } from 'vitest' + +test('reverseBits', () => { + expect(reverseBits(0b00000010100101000001111010011100)).toEqual(964176192) +}) + +test('reverseBits2', () => { + expect(reverseBits(0b11111111111111111111111111111101)).toEqual(3221225471) +}) diff --git a/src/test/ts/g0101_0200/s0191_number_of_1_bits/solution.test.ts b/src/test/ts/g0101_0200/s0191_number_of_1_bits/solution.test.ts new file mode 100644 index 0000000..5cf7530 --- /dev/null +++ b/src/test/ts/g0101_0200/s0191_number_of_1_bits/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { hammingWeight } from 'src/main/ts/g0101_0200/s0191_number_of_1_bits/solution' +import { expect, test } from 'vitest' + +test('hammingWeight', () => { + expect(hammingWeight(11)).toEqual(3) +}) + +test('hammingWeight2', () => { + expect(hammingWeight(128)).toEqual(1) +}) + +test('hammingWeight3', () => { + expect(hammingWeight(2147483645)).toEqual(30) +}) diff --git a/src/test/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.test.ts b/src/test/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.test.ts new file mode 100644 index 0000000..bec5f07 --- /dev/null +++ b/src/test/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.test.ts @@ -0,0 +1,20 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { rightSideView } from 'src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution' +import { expect, test } from 'vitest' + +test('rightSideView', () => { + expect(rightSideView(createTreeNode([1, 2, 3, null, 5, null, 4]))).toEqual([1, 3, 4]) +}) + +test('rightSideView2', () => { + expect(rightSideView(createTreeNode([1, 2, 3, 4, null, null, null, 5]))).toEqual([1, 3, 4, 5]) +}) + +test('rightSideView3', () => { + expect(rightSideView(createTreeNode([1, null, 3]))).toEqual([1, 3]) +}) + +test('rightSideView4', () => { + expect(rightSideView(createTreeNode([]))).toEqual([]) +}) diff --git a/src/test/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.test.ts b/src/test/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.test.ts new file mode 100644 index 0000000..bcae1f9 --- /dev/null +++ b/src/test/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { rangeBitwiseAnd } from 'src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution' +import { expect, test } from 'vitest' + +test('rangeBitwiseAnd', () => { + expect(rangeBitwiseAnd(5, 7)).toEqual(4) +}) + +test('rangeBitwiseAnd2', () => { + expect(rangeBitwiseAnd(0, 0)).toEqual(0) +}) + +test('rangeBitwiseAnd3', () => { + expect(rangeBitwiseAnd(1, 2147483647)).toEqual(0) +}) diff --git a/src/test/ts/g0201_0300/s0202_happy_number/solution.test.ts b/src/test/ts/g0201_0300/s0202_happy_number/solution.test.ts new file mode 100644 index 0000000..71b00b9 --- /dev/null +++ b/src/test/ts/g0201_0300/s0202_happy_number/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { isHappy } from 'src/main/ts/g0201_0300/s0202_happy_number/solution' +import { expect, test } from 'vitest' + +test('isHappy', () => { + expect(isHappy(19)).toEqual(true) +}) + +test('isHappy2', () => { + expect(isHappy(2)).toEqual(false) +}) diff --git a/src/test/ts/g0201_0300/s0205_isomorphic_strings/solution.test.ts b/src/test/ts/g0201_0300/s0205_isomorphic_strings/solution.test.ts new file mode 100644 index 0000000..241b098 --- /dev/null +++ b/src/test/ts/g0201_0300/s0205_isomorphic_strings/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { isIsomorphic } from 'src/main/ts/g0201_0300/s0205_isomorphic_strings/solution' +import { expect, test } from 'vitest' + +test('isIsomorphic', () => { + expect(isIsomorphic('egg', 'add')).toEqual(true) +}) + +test('isIsomorphic2', () => { + expect(isIsomorphic('foo', 'bar')).toEqual(false) +}) + +test('isIsomorphic3', () => { + expect(isIsomorphic('paper', 'title')).toEqual(true) +}) diff --git a/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts b/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts new file mode 100644 index 0000000..5ad38e7 --- /dev/null +++ b/src/test/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { minSubArrayLen } from 'src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution' +import { expect, test } from 'vitest' + +test('minSubArrayLen', () => { + expect(minSubArrayLen(7, [2, 3, 1, 2, 4, 3])).toEqual(2) +}) + +test('minSubArrayLen2', () => { + expect(minSubArrayLen(4, [1, 4, 4])).toEqual(1) +}) + +test('minSubArrayLen3', () => { + expect(minSubArrayLen(11, [1, 1, 1, 1, 1, 1, 1, 1])).toEqual(0) +}) diff --git a/src/test/ts/g0201_0300/s0210_course_schedule_ii/solution.test.ts b/src/test/ts/g0201_0300/s0210_course_schedule_ii/solution.test.ts new file mode 100644 index 0000000..193e5bc --- /dev/null +++ b/src/test/ts/g0201_0300/s0210_course_schedule_ii/solution.test.ts @@ -0,0 +1,22 @@ +// tslint:disable:no-magic-numbers +import { findOrder } from 'src/main/ts/g0201_0300/s0210_course_schedule_ii/solution' +import { expect, test } from 'vitest' + +test('findOrder', () => { + expect(findOrder(2, [[1, 0]])).toEqual([0, 1]) +}) + +test('findOrder2', () => { + expect( + findOrder(4, [ + [1, 0], + [2, 0], + [3, 1], + [3, 2], + ]), + ).toEqual([0, 1, 2, 3]) +}) + +test('findOrder2', () => { + expect(findOrder(1, [])).toEqual([0]) +}) diff --git a/src/test/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.test.ts b/src/test/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.test.ts new file mode 100644 index 0000000..0341658 --- /dev/null +++ b/src/test/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.test.ts @@ -0,0 +1,14 @@ +// tslint:disable:no-magic-numbers +import { WordDictionary } from 'src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution' +import { expect, test } from 'vitest' + +test('wordDictionary', () => { + const wordDictionary = new WordDictionary() + wordDictionary.addWord('bad') + wordDictionary.addWord('dad') + wordDictionary.addWord('mad') + expect(wordDictionary.search('pad')).toBeFalsy() + expect(wordDictionary.search('bad')).toBeTruthy() + expect(wordDictionary.search('.ad')).toBeTruthy() + expect(wordDictionary.search('b..')).toBeTruthy() +}) diff --git a/src/test/ts/g0201_0300/s0212_word_search_ii/solution.test.ts b/src/test/ts/g0201_0300/s0212_word_search_ii/solution.test.ts new file mode 100644 index 0000000..c669386 --- /dev/null +++ b/src/test/ts/g0201_0300/s0212_word_search_ii/solution.test.ts @@ -0,0 +1,29 @@ +// tslint:disable:no-magic-numbers +import { findWords } from 'src/main/ts/g0201_0300/s0212_word_search_ii/solution' +import { expect, test } from 'vitest' + +test('findWords', () => { + expect( + findWords( + [ + ['o', 'a', 'a', 'n'], + ['e', 't', 'a', 'e'], + ['i', 'h', 'k', 'r'], + ['i', 'f', 'l', 'v'], + ], + ['oath', 'pea', 'eat', 'rain'], + ), + ).toEqual(['oath', 'eat']) +}) + +test('findWords2', () => { + expect( + findWords( + [ + ['a', 'b'], + ['c', 'd'], + ], + ['abcb'], + ), + ).toEqual([]) +}) diff --git a/src/test/ts/g0201_0300/s0219_contains_duplicate_ii/solution.test.ts b/src/test/ts/g0201_0300/s0219_contains_duplicate_ii/solution.test.ts new file mode 100644 index 0000000..6614546 --- /dev/null +++ b/src/test/ts/g0201_0300/s0219_contains_duplicate_ii/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { containsNearbyDuplicate } from 'src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution' +import { expect, test } from 'vitest' + +test('containsNearbyDuplicate', () => { + expect(containsNearbyDuplicate([1, 2, 3, 1], 3)).toEqual(true) +}) + +test('containsNearbyDuplicate2', () => { + expect(containsNearbyDuplicate([1, 0, 1, 1], 1)).toEqual(true) +}) + +test('containsNearbyDuplicate3', () => { + expect(containsNearbyDuplicate([1, 2, 3, 1, 2, 3], 2)).toEqual(false) +}) diff --git a/src/test/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.test.ts b/src/test/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.test.ts new file mode 100644 index 0000000..65eb6d8 --- /dev/null +++ b/src/test/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.test.ts @@ -0,0 +1,16 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { countNodes } from 'src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution' +import { expect, test } from 'vitest' + +test('countNodes', () => { + expect(countNodes(createTreeNode([1, 2, 3, 4, 5, 6]))).toEqual(6) +}) + +test('countNodes2', () => { + expect(countNodes(createTreeNode([]))).toEqual(0) +}) + +test('countNodes3', () => { + expect(countNodes(createTreeNode([1]))).toEqual(1) +}) diff --git a/src/test/ts/g0201_0300/s0224_basic_calculator/solution.test.ts b/src/test/ts/g0201_0300/s0224_basic_calculator/solution.test.ts new file mode 100644 index 0000000..dfab961 --- /dev/null +++ b/src/test/ts/g0201_0300/s0224_basic_calculator/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { calculate } from 'src/main/ts/g0201_0300/s0224_basic_calculator/solution' +import { expect, test } from 'vitest' + +test('calculate', () => { + expect(calculate('1 + 1')).toEqual(2) +}) + +test('calculate2', () => { + expect(calculate(' 2-1 + 2 ')).toEqual(3) +}) + +test('calculate3', () => { + expect(calculate('(1+(4+5+2)-3)+(6+8)')).toEqual(23) +}) diff --git a/src/test/ts/g0201_0300/s0228_summary_ranges/solution.test.ts b/src/test/ts/g0201_0300/s0228_summary_ranges/solution.test.ts new file mode 100644 index 0000000..d70b76e --- /dev/null +++ b/src/test/ts/g0201_0300/s0228_summary_ranges/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { summaryRanges } from 'src/main/ts/g0201_0300/s0228_summary_ranges/solution' +import { expect, test } from 'vitest' + +test('summaryRanges', () => { + expect(summaryRanges([0, 1, 2, 4, 5, 7])).toEqual(['0->2', '4->5', '7']) +}) + +test('summaryRanges2', () => { + expect(summaryRanges([0, 2, 3, 4, 6, 8, 9])).toEqual(['0', '2->4', '6', '8->9']) +}) diff --git a/src/test/ts/g0201_0300/s0242_valid_anagram/solution.test.ts b/src/test/ts/g0201_0300/s0242_valid_anagram/solution.test.ts new file mode 100644 index 0000000..99c010f --- /dev/null +++ b/src/test/ts/g0201_0300/s0242_valid_anagram/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { isAnagram } from 'src/main/ts/g0201_0300/s0242_valid_anagram/solution' +import { expect, test } from 'vitest' + +test('isAnagram', () => { + expect(isAnagram('anagram', 'nagaram')).toEqual(true) +}) + +test('isAnagram2', () => { + expect(isAnagram('rat', 'car')).toEqual(false) +}) diff --git a/src/test/ts/g0201_0300/s0274_h_index/solution.test.ts b/src/test/ts/g0201_0300/s0274_h_index/solution.test.ts new file mode 100644 index 0000000..3e0fb9a --- /dev/null +++ b/src/test/ts/g0201_0300/s0274_h_index/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { hIndex } from 'src/main/ts/g0201_0300/s0274_h_index/solution' +import { expect, test } from 'vitest' + +test('hIndex', () => { + expect(hIndex([3, 0, 6, 1, 5])).toEqual(3) +}) + +test('hIndex2', () => { + expect(hIndex([1, 3, 1])).toEqual(1) +}) diff --git a/src/test/ts/g0201_0300/s0289_game_of_life/solution.test.ts b/src/test/ts/g0201_0300/s0289_game_of_life/solution.test.ts new file mode 100644 index 0000000..03f4c33 --- /dev/null +++ b/src/test/ts/g0201_0300/s0289_game_of_life/solution.test.ts @@ -0,0 +1,31 @@ +// tslint:disable:no-magic-numbers +import { gameOfLife } from 'src/main/ts/g0201_0300/s0289_game_of_life/solution' +import { expect, test } from 'vitest' + +test('gameOfLife', () => { + const board = [ + [0, 1, 0], + [0, 0, 1], + [1, 1, 1], + [0, 0, 0], + ] + gameOfLife(board) + expect(board).toEqual([ + [0, 0, 0], + [1, 0, 1], + [0, 1, 1], + [0, 1, 0], + ]) +}) + +test('gameOfLife2', () => { + const board = [ + [1, 1], + [1, 0], + ] + gameOfLife(board) + expect(board).toEqual([ + [1, 1], + [1, 1], + ]) +}) diff --git a/src/test/ts/g0201_0300/s0290_word_pattern/solution.test.ts b/src/test/ts/g0201_0300/s0290_word_pattern/solution.test.ts new file mode 100644 index 0000000..5a45dda --- /dev/null +++ b/src/test/ts/g0201_0300/s0290_word_pattern/solution.test.ts @@ -0,0 +1,27 @@ +// tslint:disable:no-magic-numbers +import { wordPattern } from 'src/main/ts/g0201_0300/s0290_word_pattern/solution' +import { expect, test } from 'vitest' + +test('wordPattern', () => { + expect(wordPattern('abba', 'dog cat cat dog')).toEqual(true) +}) + +test('wordPattern2', () => { + expect(wordPattern('abba', 'dog cat cat fish')).toEqual(false) +}) + +test('wordPattern3', () => { + expect(wordPattern('aaaa', 'dog cat cat dog')).toEqual(false) +}) + +test('wordPattern4', () => { + expect(wordPattern('a', 'dog cat')).toEqual(false) +}) + +test('wordPattern5', () => { + expect(wordPattern('a', 'dog')).toEqual(true) +}) + +test('wordPattern6', () => { + expect(wordPattern('ab', 'dog dog')).toEqual(false) +}) diff --git a/src/test/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.test.ts b/src/test/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.test.ts new file mode 100644 index 0000000..3d634d4 --- /dev/null +++ b/src/test/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.test.ts @@ -0,0 +1,18 @@ +// tslint:disable:no-magic-numbers +import { kSmallestPairs } from 'src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution' +import { expect, test } from 'vitest' + +test('kSmallestPairs', () => { + expect(kSmallestPairs([1, 7, 11], [2, 4, 6], 3)).toEqual([ + [1, 2], + [1, 4], + [1, 6], + ]) +}) + +test('kSmallestPairs2', () => { + expect(kSmallestPairs([1, 1, 2], [1, 2, 3], 2)).toEqual([ + [1, 1], + [1, 1], + ]) +}) diff --git a/src/test/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.test.ts b/src/test/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.test.ts new file mode 100644 index 0000000..d025ba4 --- /dev/null +++ b/src/test/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.test.ts @@ -0,0 +1,25 @@ +// tslint:disable:no-magic-numbers +import { RandomizedSet } from 'src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution' +import { expect, test } from 'vitest' + +test('randomizedSet', () => { + const result: string[] = [] + let randomizedSet: RandomizedSet | null = null + result.push(randomizedSet + '') + randomizedSet = new RandomizedSet() + result.push(randomizedSet.insert(1) + '') + result.push(randomizedSet.remove(2) + '') + result.push(randomizedSet.insert(2) + '') + const random = randomizedSet.getRandom() + result.push(random + '') + result.push(randomizedSet.remove(1) + '') + result.push(randomizedSet.insert(2) + '') + result.push(randomizedSet.getRandom() + '') + const expected = ['null', 'true', 'false', 'true', '1', 'true', 'false', '2'] + const expected2 = ['null', 'true', 'false', 'true', '2', 'true', 'false', '2'] + if (random === 1) { + expect(result).toEqual(expected) + } else { + expect(result).toEqual(expected2) + } +}) diff --git a/src/test/ts/g0301_0400/s0383_ransom_note/solution.test.ts b/src/test/ts/g0301_0400/s0383_ransom_note/solution.test.ts new file mode 100644 index 0000000..809b0bb --- /dev/null +++ b/src/test/ts/g0301_0400/s0383_ransom_note/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { canConstruct } from 'src/main/ts/g0301_0400/s0383_ransom_note/solution' +import { expect, test } from 'vitest' + +test('canConstruct', () => { + expect(canConstruct('a', 'b')).toEqual(false) +}) + +test('canConstruct2', () => { + expect(canConstruct('aa', 'ab')).toEqual(false) +}) + +test('canConstruct3', () => { + expect(canConstruct('aa', 'aab')).toEqual(true) +}) diff --git a/src/test/ts/g0301_0400/s0392_is_subsequence/solution.test.ts b/src/test/ts/g0301_0400/s0392_is_subsequence/solution.test.ts new file mode 100644 index 0000000..8940a9e --- /dev/null +++ b/src/test/ts/g0301_0400/s0392_is_subsequence/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { isSubsequence } from 'src/main/ts/g0301_0400/s0392_is_subsequence/solution' +import { expect, test } from 'vitest' + +test('isSubsequence', () => { + expect(isSubsequence('abc', 'ahbgdc')).toEqual(true) +}) + +test('isSubsequence2', () => { + expect(isSubsequence('axc', 'ahbgdc')).toEqual(false) +}) diff --git a/src/test/ts/g0301_0400/s0399_evaluate_division/solution.test.ts b/src/test/ts/g0301_0400/s0399_evaluate_division/solution.test.ts new file mode 100644 index 0000000..9b22724 --- /dev/null +++ b/src/test/ts/g0301_0400/s0399_evaluate_division/solution.test.ts @@ -0,0 +1,50 @@ +// tslint:disable:no-magic-numbers +import { calcEquation } from 'src/main/ts/g0301_0400/s0399_evaluate_division/solution' +import { expect, test } from 'vitest' + +test('calcEquation', () => { + const equations = [ + ['a', 'b'], + ['b', 'c'], + ] as [string, string][] + const values = [2.0, 3.0] + const queries = [ + ['a', 'c'], + ['b', 'a'], + ['a', 'e'], + ['a', 'a'], + ['x', 'x'], + ] as [string, string][] + const expected = [6.0, 0.5, -1.0, 1.0, -1.0] + expect(calcEquation(equations, values, queries)).toEqual(expected) +}) + +test('calcEquation2', () => { + const equations = [ + ['a', 'b'], + ['b', 'c'], + ['bc', 'cd'], + ] as [string, string][] + const values = [1.5, 2.5, 5.0] + const queries = [ + ['a', 'c'], + ['c', 'b'], + ['bc', 'cd'], + ['cd', 'bc'], + ] as [string, string][] + const expected = [3.75, 0.4, 5.0, 0.2] + expect(calcEquation(equations, values, queries)).toEqual(expected) +}) + +test('calcEquation3', () => { + const equations = [['a', 'b']] as [string, string][] + const values = [0.5] + const queries = [ + ['a', 'b'], + ['b', 'a'], + ['a', 'c'], + ['x', 'y'], + ] as [string, string][] + const expected = [0.5, 2.0, -1.0, -1.0] + expect(calcEquation(equations, values, queries)).toEqual(expected) +}) diff --git a/src/test/ts/g0401_0500/s0427_construct_quad_tree/solution.test.ts b/src/test/ts/g0401_0500/s0427_construct_quad_tree/solution.test.ts new file mode 100644 index 0000000..604cee7 --- /dev/null +++ b/src/test/ts/g0401_0500/s0427_construct_quad_tree/solution.test.ts @@ -0,0 +1,27 @@ +// tslint:disable:no-magic-numbers +import { construct } from 'src/main/ts/g0401_0500/s0427_construct_quad_tree/solution' +import { expect, test } from 'vitest' + +test('construct', () => { + expect( + construct([ + [0, 1], + [1, 0], + ])?.toString(), + ).toEqual('[0,1][1,0][1,1][1,1][1,0]') +}) + +test('construct2', () => { + expect( + construct([ + [1, 1, 1, 1, 0, 0, 0, 0], + [1, 1, 1, 1, 0, 0, 0, 0], + [1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 0, 0, 0, 0], + [1, 1, 1, 1, 0, 0, 0, 0], + [1, 1, 1, 1, 0, 0, 0, 0], + [1, 1, 1, 1, 0, 0, 0, 0], + ])?.toString(), + ).toEqual('[0,1][1,1][0,1][1,1][1,0]') +}) diff --git a/src/test/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.test.ts b/src/test/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.test.ts new file mode 100644 index 0000000..a4c03da --- /dev/null +++ b/src/test/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { minMutation } from 'src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution' +import { expect, test } from 'vitest' + +test('minMutation', () => { + expect(minMutation('AACCGGTT', 'AACCGGTA', ['AACCGGTA'])).toEqual(1) +}) + +test('minMutation2', () => { + expect(minMutation('AACCGGTT', 'AAACGGTA', ['AACCGGTA', 'AACCGCTA', 'AAACGGTA'])).toEqual(2) +}) diff --git a/src/test/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.test.ts b/src/test/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.test.ts new file mode 100644 index 0000000..c9e97e6 --- /dev/null +++ b/src/test/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution.test.ts @@ -0,0 +1,36 @@ +// tslint:disable:no-magic-numbers +import { findMinArrowShots } from 'src/main/ts/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/solution' +import { expect, test } from 'vitest' + +test('findMinArrowShots', () => { + expect( + findMinArrowShots([ + [10, 16], + [2, 8], + [1, 6], + [7, 12], + ]), + ).toEqual(2) +}) + +test('findMinArrowShots2', () => { + expect( + findMinArrowShots([ + [1, 2], + [3, 4], + [5, 6], + [7, 8], + ]), + ).toEqual(4) +}) + +test('findMinArrowShots3', () => { + expect( + findMinArrowShots([ + [1, 2], + [2, 3], + [3, 4], + [4, 5], + ]), + ).toEqual(2) +}) diff --git a/src/test/ts/g0501_0600/s0502_ipo/solution.test.ts b/src/test/ts/g0501_0600/s0502_ipo/solution.test.ts new file mode 100644 index 0000000..6423e12 --- /dev/null +++ b/src/test/ts/g0501_0600/s0502_ipo/solution.test.ts @@ -0,0 +1,11 @@ +// tslint:disable:no-magic-numbers +import { findMaximizedCapital } from 'src/main/ts/g0501_0600/s0502_ipo/solution' +import { expect, test } from 'vitest' + +test('findMaximizedCapital', () => { + expect(findMaximizedCapital(2, 0, [1, 2, 3], [0, 1, 1])).toEqual(4) +}) + +test('findMaximizedCapital2', () => { + expect(findMaximizedCapital(3, 0, [1, 2, 3], [0, 1, 2])).toEqual(6) +}) diff --git a/src/test/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.test.ts b/src/test/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.test.ts new file mode 100644 index 0000000..04a0a20 --- /dev/null +++ b/src/test/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { getMinimumDifference } from 'src/main/ts/g0501_0600/s0530_minimum_absolute_difference_in_bst/solution' +import { expect, test } from 'vitest' + +test('getMinimumDifference', () => { + expect(getMinimumDifference(createTreeNode([4, 2, 6, 1, 3]))).toEqual(1) +}) + +test('getMinimumDifference2', () => { + expect(getMinimumDifference(createTreeNode([1, 0, 48, null, null, 12, 49]))).toEqual(1) +}) diff --git a/src/test/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.test.ts b/src/test/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.test.ts new file mode 100644 index 0000000..3babc73 --- /dev/null +++ b/src/test/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution.test.ts @@ -0,0 +1,12 @@ +// tslint:disable:no-magic-numbers +import { createTreeNode } from 'src/main/ts/com_github_leetcode/treenode' +import { averageOfLevels } from 'src/main/ts/g0601_0700/s0637_average_of_levels_in_binary_tree/solution' +import { expect, test } from 'vitest' + +test('averageOfLevels', () => { + expect(averageOfLevels(createTreeNode([3, 9, 20, null, null, 15, 7]))).toEqual([3.0, 14.5, 11.0]) +}) + +test('averageOfLevels2', () => { + expect(averageOfLevels(createTreeNode([3, 9, 20, 15, 7]))).toEqual([3.0, 14.5, 11.0]) +}) diff --git a/src/test/ts/g0901_1000/s0909_snakes_and_ladders/solution.test.ts b/src/test/ts/g0901_1000/s0909_snakes_and_ladders/solution.test.ts new file mode 100644 index 0000000..baf9e6d --- /dev/null +++ b/src/test/ts/g0901_1000/s0909_snakes_and_ladders/solution.test.ts @@ -0,0 +1,25 @@ +// tslint:disable:no-magic-numbers +import { snakesAndLadders } from 'src/main/ts/g0901_1000/s0909_snakes_and_ladders/solution' +import { expect, test } from 'vitest' + +test('snakesAndLadders', () => { + expect( + snakesAndLadders([ + [-1, -1, -1, -1, -1, -1], + [-1, -1, -1, -1, -1, -1], + [-1, -1, -1, -1, -1, -1], + [-1, 35, -1, -1, 13, -1], + [-1, -1, -1, -1, -1, -1], + [-1, 15, -1, -1, -1, -1], + ]), + ).toEqual(4) +}) + +test('snakesAndLadders2', () => { + expect( + snakesAndLadders([ + [-1, -1], + [-1, 3], + ]), + ).toEqual(1) +}) diff --git a/src/test/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.test.ts b/src/test/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.test.ts new file mode 100644 index 0000000..90b10c6 --- /dev/null +++ b/src/test/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution.test.ts @@ -0,0 +1,15 @@ +// tslint:disable:no-magic-numbers +import { maxSubarraySumCircular } from 'src/main/ts/g0901_1000/s0918_maximum_sum_circular_subarray/solution' +import { expect, test } from 'vitest' + +test('maxSubarraySumCircular', () => { + expect(maxSubarraySumCircular([1, -2, 3, -2])).toEqual(3) +}) + +test('maxSubarraySumCircular2', () => { + expect(maxSubarraySumCircular([5, -3, 5])).toEqual(10) +}) + +test('maxSubarraySumCircular2', () => { + expect(maxSubarraySumCircular([-3, -2, -3])).toEqual(-2) +})