diff --git a/README.md b/README.md index 2d60ed9c9..7346c573f 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,6 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.27' > ["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) ## -* [SQL I](#sql-i) -* [Level 1](#level-1) * [Level 2](#level-2) * [Udemy](#udemy) * [Data Structure I](#data-structure-i) @@ -48,198 +46,8 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.27' * [Programming Skills I](#programming-skills-i) * [Programming Skills II](#programming-skills-ii) * [Graph Theory I](#graph-theory-i) - -### SQL I - -#### Day 1 Select - -| | | | | | -|-|-|-|-|-|- -| 0595 |[Big Countries](src/main/kotlin/g0501_0600/s0595_big_countries/script.sql)| Easy | Database | 417 | 56.09 -| 1757 |[Recyclable and Low Fat Products](src/main/kotlin/g1701_1800/s1757_recyclable_and_low_fat_products/script.sql)| Easy | Database | 1237 | 34.20 -| 0584 |[Find Customer Referee](src/main/kotlin/g0501_0600/s0584_find_customer_referee/script.sql)| Easy | Database | 779 | 43.48 -| 0183 |[Customers Who Never Order](src/main/kotlin/g0101_0200/s0183_customers_who_never_order/script.sql)| Easy | Database | 712 | 33.67 - -#### Day 2 Select and Order - -| | | | | | -|-|-|-|-|-|- -| 1873 |[Calculate Special Bonus](src/main/kotlin/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database | 1321 | 33.12 -| 0627 |[Swap Salary](src/main/kotlin/g0601_0700/s0627_swap_salary/script.sql)| Easy | Database | 400 | 51.04 -| 0196 |[Delete Duplicate Emails](src/main/kotlin/g0101_0200/s0196_delete_duplicate_emails/script.sql)| Easy | Database | 593 | 94.17 - -#### Day 3 String Processing Functions - -| | | | | | -|-|-|-|-|-|- -| 1667 |[Fix Names in a Table](src/main/kotlin/g1601_1700/s1667_fix_names_in_a_table/script.sql)| Easy | Database | 1196 | 61.40 -| 1484 |[Group Sold Products By The Date](src/main/kotlin/g1401_1500/s1484_group_sold_products_by_the_date/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 899 | 40.76 -| 1527 |[Patients With a Condition](src/main/kotlin/g1501_1600/s1527_patients_with_a_condition/script.sql)| Easy | Database | 708 | 48.23 - -#### Day 4 Union and Select - -| | | | | | -|-|-|-|-|-|- -| 1965 |[Employees With Missing Information](src/main/kotlin/g1901_2000/s1965_employees_with_missing_information/script.sql)| Easy | Database | 949 | 88.66 -| 1795 |[Rearrange Products Table](src/main/kotlin/g1701_1800/s1795_rearrange_products_table/script.sql)| Easy | Database | 1027 | 67.57 -| 0608 |[Tree Node](src/main/kotlin/g0601_0700/s0608_tree_node/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 794 | 48.38 -| 0176 |[Second Highest Salary](src/main/kotlin/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database | 219 | 92.54 - -#### Day 5 Union - -| | | | | | -|-|-|-|-|-|- -| 0175 |[Combine Two Tables](src/main/kotlin/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database | 473 | 54.97 -| 1581 |[Customer Who Visited but Did Not Make Any Transactions](src/main/kotlin/g1501_1600/s1581_customer_who_visited_but_did_not_make_any_transactions/script.sql)| Easy | Database | 2771 | 54.68 -| 1148 |[Article Views I](src/main/kotlin/g1101_1200/s1148_article_views_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 806 | 54.41 - -#### Day 6 Union - -| | | | | | -|-|-|-|-|-|- -| 0197 |[Rising Temperature](src/main/kotlin/g0101_0200/s0197_rising_temperature/script.sql)| Easy | Database | 394 | 94.15 -| 0607 |[Sales Person](src/main/kotlin/g0601_0700/s0607_sales_person/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 2142 | 44.56 - -#### Day 7 Function - -| | | | | | -|-|-|-|-|-|- -| 1141 |[User Activity for the Past 30 Days I](src/main/kotlin/g1101_1200/s1141_user_activity_for_the_past_30_days_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 790 | 87.11 -| 1693 |[Daily Leads and Partners](src/main/kotlin/g1601_1700/s1693_daily_leads_and_partners/script.sql)| Easy | Database | 1115 | 52.84 -| 1729 |[Find Followers Count](src/main/kotlin/g1701_1800/s1729_find_followers_count/script.sql)| Easy | Database | 1228 | 38.04 - -#### Day 8 Function - -| | | | | | -|-|-|-|-|-|- -| 0586 |[Customer Placing the Largest Number of Orders](src/main/kotlin/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 768 | 44.85 -| 0511 |[Game Play Analysis I](src/main/kotlin/g0501_0600/s0511_game_play_analysis_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 790 | 45.04 -| 1890 |[The Latest Login in 2020](src/main/kotlin/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database | 1280 | 43.62 -| 1741 |[Find Total Time Spent by Each Employee](src/main/kotlin/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql)| Easy | Database | 1101 | 51.40 - -#### Day 9 Control of Flow - -| | | | | | -|-|-|-|-|-|- -| 1393 |[Capital Gain/Loss](src/main/kotlin/g1301_1400/s1393_capital_gainloss/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 990 | 47.36 -| 1407 |[Top Travellers](src/main/kotlin/g1401_1500/s1407_top_travellers/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1394 | 98.43 -| 1158 |[Market Analysis I](src/main/kotlin/g1101_1200/s1158_market_analysis_i/script.sql)| Medium | Database | 2470 | 44.76 - -#### Day 10 Where - -| | | | | | -|-|-|-|-|-|- -| 0182 |[Duplicate Emails](src/main/kotlin/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database | 396 | 68.40 -| 1050 |[Actors and Directors Who Cooperated At Least Three Times](src/main/kotlin/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 629 | 81.02 -| 1587 |[Bank Account Summary II](src/main/kotlin/g1501_1600/s1587_bank_account_summary_ii/script.sql)| Easy | Database | 1582 | 52.96 -| 1084 |[Sales Analysis III](src/main/kotlin/g1001_1100/s1084_sales_analysis_iii/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1881 | 79.36 - -### Level 1 - -#### Day 1 Prefix Sum - -| | | | | | -|-|-|-|-|-|- -| 1480 |[Running Sum of 1d Array](src/main/kotlin/g1401_1500/s1480_running_sum_of_1d_array/Solution.kt)| Easy | Array, Prefix_Sum | 161 | 84.80 -| 0724 |[Find Pivot Index](src/main/kotlin/g0701_0800/s0724_find_pivot_index/Solution.kt)| Easy | Array, Prefix_Sum | 255 | 88.92 - -#### Day 2 String - -| | | | | | -|-|-|-|-|-|- -| 0205 |[Isomorphic Strings](src/main/kotlin/g0201_0300/s0205_isomorphic_strings/Solution.kt)| Easy | String, Hash_Table | 278 | 79.96 -| 0392 |[Is Subsequence](src/main/kotlin/g0301_0400/s0392_is_subsequence/Solution.kt)| Easy | String, Dynamic_Programming, Two_Pointers | 156 | 87.74 - -#### Day 3 Linked List - -| | | | | | -|-|-|-|-|-|- -| 0021 |[Merge Two Sorted Lists](src/main/kotlin/g0001_0100/s0021_merge_two_sorted_lists/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 157 | 92.24 -| 0206 |[Reverse Linked List](src/main/kotlin/g0201_0300/s0206_reverse_linked_list/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 279 | 45.78 - -#### Day 4 Linked List - -| | | | | | -|-|-|-|-|-|- -| 0876 |[Middle of the Linked List](src/main/kotlin/g0801_0900/s0876_middle_of_the_linked_list/Solution.kt)| Easy | Two_Pointers, Linked_List | 136 | 76.52 -| 0142 |[Linked List Cycle II](src/main/kotlin/g0101_0200/s0142_linked_list_cycle_ii/Solution.kt)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 192 | 63.39 - -#### Day 5 Greedy - -| | | | | | -|-|-|-|-|-|- -| 0121 |[Best Time to Buy and Sell Stock](src/main/kotlin/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 609 | 94.06 -| 0409 |[Longest Palindrome](src/main/kotlin/g0401_0500/s0409_longest_palindrome/Solution.kt)| Easy | String, Hash_Table, Greedy | 259 | 60.71 - -#### Day 6 Tree - -| | | | | | -|-|-|-|-|-|- -| 0589 |[N-ary Tree Preorder Traversal](src/main/kotlin/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.kt)| Easy | Depth_First_Search, Tree, Stack | 233 | 84.02 -| 0102 |[Binary Tree Level Order Traversal](src/main/kotlin/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 198 | 95.14 - -#### Day 7 Binary Search - -| | | | | | -|-|-|-|-|-|- -| 0704 |[Binary Search](src/main/kotlin/g0701_0800/s0704_binary_search/Solution.kt)| Easy | Top_100_Liked_Questions, Array, Binary_Search | 261 | 77.91 -| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version/Solution.kt)| Easy | Binary_Search, Interactive | 349 | 76.86 - -#### Day 8 Binary Search Tree - -| | | | | | -|-|-|-|-|-|- -| 0098 |[Validate Binary Search Tree](src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree/Solution.kt)| 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)) | 190 | 61.62 -| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/kotlin/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.kt)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 404 | 75.59 - -#### Day 9 Graph/BFS/DFS - -| | | | | | -|-|-|-|-|-|- -| 0733 |[Flood Fill](src/main/kotlin/g0701_0800/s0733_flood_fill/Solution.kt)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 230 | 97.76 -| 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands/Solution.kt)| 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) | 252 | 95.41 - -#### Day 10 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0509 |[Fibonacci Number](src/main/kotlin/g0501_0600/s0509_fibonacci_number/Solution.kt)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 139 | 82.72 -| 0070 |[Climbing Stairs](src/main/kotlin/g0001_0100/s0070_climbing_stairs/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 124 | 71.98 - -#### Day 11 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0746 |[Min Cost Climbing Stairs](src/main/kotlin/g0701_0800/s0746_min_cost_climbing_stairs/Solution.kt)| Easy | Array, Dynamic_Programming | 171 | 96.76 -| 0062 |[Unique Paths](src/main/kotlin/g0001_0100/s0062_unique_paths/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 118 | 94.65 - -#### Day 12 Sliding Window/Two Pointer - -| | | | | | -|-|-|-|-|-|- -| 0438 |[Find All Anagrams in a String](src/main/kotlin/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 561 | 54.68 -| 0424 |[Longest Repeating Character Replacement](src/main/kotlin/g0401_0500/s0424_longest_repeating_character_replacement/Solution.kt)| Medium | String, Hash_Table, Sliding_Window | 288 | 84.38 - -#### Day 13 Hashmap - -| | | | | | -|-|-|-|-|-|- -| 0001 |[Two Sum](src/main/kotlin/g0001_0100/s0001_two_sum/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 202 | 91.18 -| 0299 |[Bulls and Cows](src/main/kotlin/g0201_0300/s0299_bulls_and_cows/Solution.kt)| Medium | String, Hash_Table, Counting | 254 | 84.82 - -#### Day 14 Stack - -| | | | | | -|-|-|-|-|-|- -| 0844 |[Backspace String Compare](src/main/kotlin/g0801_0900/s0844_backspace_string_compare/Solution.kt)| Easy | String, Two_Pointers, Stack, Simulation | 126 | 98.31 -| 0394 |[Decode String](src/main/kotlin/g0301_0400/s0394_decode_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 224 | 64.86 - -#### Day 15 Heap - -| | | | | | -|-|-|-|-|-|- -| 1046 |[Last Stone Weight](src/main/kotlin/g1001_1100/s1046_last_stone_weight/Solution.kt)| Easy | Array, Heap_Priority_Queue | 123 | 100.00 -| 0692 |[Top K Frequent Words](src/main/kotlin/g0601_0700/s0692_top_k_frequent_words/Solution.kt)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 239 | 81.10 +* [SQL I](#sql-i) +* [Level 1](#level-1) ### Level 2 @@ -1844,6 +1652,198 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.27' | 0886 |[Possible Bipartition](src/main/kotlin/g0801_0900/s0886_possible_bipartition/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 397 | 100.00 | 0785 |[Is Graph Bipartite?](src/main/kotlin/g0701_0800/s0785_is_graph_bipartite/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 215 | 82.35 +### SQL I + +#### Day 1 Select + +| | | | | | +|-|-|-|-|-|- +| 0595 |[Big Countries](src/main/kotlin/g0501_0600/s0595_big_countries/script.sql)| Easy | Database | 417 | 56.09 +| 1757 |[Recyclable and Low Fat Products](src/main/kotlin/g1701_1800/s1757_recyclable_and_low_fat_products/script.sql)| Easy | Database | 1237 | 34.20 +| 0584 |[Find Customer Referee](src/main/kotlin/g0501_0600/s0584_find_customer_referee/script.sql)| Easy | Database | 779 | 43.48 +| 0183 |[Customers Who Never Order](src/main/kotlin/g0101_0200/s0183_customers_who_never_order/script.sql)| Easy | Database | 712 | 33.67 + +#### Day 2 Select and Order + +| | | | | | +|-|-|-|-|-|- +| 1873 |[Calculate Special Bonus](src/main/kotlin/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database | 1321 | 33.12 +| 0627 |[Swap Salary](src/main/kotlin/g0601_0700/s0627_swap_salary/script.sql)| Easy | Database | 400 | 51.04 +| 0196 |[Delete Duplicate Emails](src/main/kotlin/g0101_0200/s0196_delete_duplicate_emails/script.sql)| Easy | Database | 593 | 94.17 + +#### Day 3 String Processing Functions + +| | | | | | +|-|-|-|-|-|- +| 1667 |[Fix Names in a Table](src/main/kotlin/g1601_1700/s1667_fix_names_in_a_table/script.sql)| Easy | Database | 1196 | 61.40 +| 1484 |[Group Sold Products By The Date](src/main/kotlin/g1401_1500/s1484_group_sold_products_by_the_date/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 899 | 40.76 +| 1527 |[Patients With a Condition](src/main/kotlin/g1501_1600/s1527_patients_with_a_condition/script.sql)| Easy | Database | 708 | 48.23 + +#### Day 4 Union and Select + +| | | | | | +|-|-|-|-|-|- +| 1965 |[Employees With Missing Information](src/main/kotlin/g1901_2000/s1965_employees_with_missing_information/script.sql)| Easy | Database | 949 | 88.66 +| 1795 |[Rearrange Products Table](src/main/kotlin/g1701_1800/s1795_rearrange_products_table/script.sql)| Easy | Database | 1027 | 67.57 +| 0608 |[Tree Node](src/main/kotlin/g0601_0700/s0608_tree_node/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 794 | 48.38 +| 0176 |[Second Highest Salary](src/main/kotlin/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database | 219 | 92.54 + +#### Day 5 Union + +| | | | | | +|-|-|-|-|-|- +| 0175 |[Combine Two Tables](src/main/kotlin/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database | 473 | 54.97 +| 1581 |[Customer Who Visited but Did Not Make Any Transactions](src/main/kotlin/g1501_1600/s1581_customer_who_visited_but_did_not_make_any_transactions/script.sql)| Easy | Database | 2771 | 54.68 +| 1148 |[Article Views I](src/main/kotlin/g1101_1200/s1148_article_views_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 806 | 54.41 + +#### Day 6 Union + +| | | | | | +|-|-|-|-|-|- +| 0197 |[Rising Temperature](src/main/kotlin/g0101_0200/s0197_rising_temperature/script.sql)| Easy | Database | 394 | 94.15 +| 0607 |[Sales Person](src/main/kotlin/g0601_0700/s0607_sales_person/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 2142 | 44.56 + +#### Day 7 Function + +| | | | | | +|-|-|-|-|-|- +| 1141 |[User Activity for the Past 30 Days I](src/main/kotlin/g1101_1200/s1141_user_activity_for_the_past_30_days_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 790 | 87.11 +| 1693 |[Daily Leads and Partners](src/main/kotlin/g1601_1700/s1693_daily_leads_and_partners/script.sql)| Easy | Database | 1115 | 52.84 +| 1729 |[Find Followers Count](src/main/kotlin/g1701_1800/s1729_find_followers_count/script.sql)| Easy | Database | 1228 | 38.04 + +#### Day 8 Function + +| | | | | | +|-|-|-|-|-|- +| 0586 |[Customer Placing the Largest Number of Orders](src/main/kotlin/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 768 | 44.85 +| 0511 |[Game Play Analysis I](src/main/kotlin/g0501_0600/s0511_game_play_analysis_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 790 | 45.04 +| 1890 |[The Latest Login in 2020](src/main/kotlin/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database | 1280 | 43.62 +| 1741 |[Find Total Time Spent by Each Employee](src/main/kotlin/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql)| Easy | Database | 1101 | 51.40 + +#### Day 9 Control of Flow + +| | | | | | +|-|-|-|-|-|- +| 1393 |[Capital Gain/Loss](src/main/kotlin/g1301_1400/s1393_capital_gainloss/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 990 | 47.36 +| 1407 |[Top Travellers](src/main/kotlin/g1401_1500/s1407_top_travellers/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1394 | 98.43 +| 1158 |[Market Analysis I](src/main/kotlin/g1101_1200/s1158_market_analysis_i/script.sql)| Medium | Database | 2470 | 44.76 + +#### Day 10 Where + +| | | | | | +|-|-|-|-|-|- +| 0182 |[Duplicate Emails](src/main/kotlin/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database | 396 | 68.40 +| 1050 |[Actors and Directors Who Cooperated At Least Three Times](src/main/kotlin/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 629 | 81.02 +| 1587 |[Bank Account Summary II](src/main/kotlin/g1501_1600/s1587_bank_account_summary_ii/script.sql)| Easy | Database | 1582 | 52.96 +| 1084 |[Sales Analysis III](src/main/kotlin/g1001_1100/s1084_sales_analysis_iii/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1881 | 79.36 + +### Level 1 + +#### Day 1 Prefix Sum + +| | | | | | +|-|-|-|-|-|- +| 1480 |[Running Sum of 1d Array](src/main/kotlin/g1401_1500/s1480_running_sum_of_1d_array/Solution.kt)| Easy | Array, Prefix_Sum | 161 | 84.80 +| 0724 |[Find Pivot Index](src/main/kotlin/g0701_0800/s0724_find_pivot_index/Solution.kt)| Easy | Array, Prefix_Sum | 255 | 88.92 + +#### Day 2 String + +| | | | | | +|-|-|-|-|-|- +| 0205 |[Isomorphic Strings](src/main/kotlin/g0201_0300/s0205_isomorphic_strings/Solution.kt)| Easy | String, Hash_Table | 278 | 79.96 +| 0392 |[Is Subsequence](src/main/kotlin/g0301_0400/s0392_is_subsequence/Solution.kt)| Easy | String, Dynamic_Programming, Two_Pointers | 156 | 87.74 + +#### Day 3 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0021 |[Merge Two Sorted Lists](src/main/kotlin/g0001_0100/s0021_merge_two_sorted_lists/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 157 | 92.24 +| 0206 |[Reverse Linked List](src/main/kotlin/g0201_0300/s0206_reverse_linked_list/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 279 | 45.78 + +#### Day 4 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0876 |[Middle of the Linked List](src/main/kotlin/g0801_0900/s0876_middle_of_the_linked_list/Solution.kt)| Easy | Two_Pointers, Linked_List | 136 | 76.52 +| 0142 |[Linked List Cycle II](src/main/kotlin/g0101_0200/s0142_linked_list_cycle_ii/Solution.kt)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 192 | 63.39 + +#### Day 5 Greedy + +| | | | | | +|-|-|-|-|-|- +| 0121 |[Best Time to Buy and Sell Stock](src/main/kotlin/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 609 | 94.06 +| 0409 |[Longest Palindrome](src/main/kotlin/g0401_0500/s0409_longest_palindrome/Solution.kt)| Easy | String, Hash_Table, Greedy | 259 | 60.71 + +#### Day 6 Tree + +| | | | | | +|-|-|-|-|-|- +| 0589 |[N-ary Tree Preorder Traversal](src/main/kotlin/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.kt)| Easy | Depth_First_Search, Tree, Stack | 233 | 84.02 +| 0102 |[Binary Tree Level Order Traversal](src/main/kotlin/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 198 | 95.14 + +#### Day 7 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0704 |[Binary Search](src/main/kotlin/g0701_0800/s0704_binary_search/Solution.kt)| Easy | Top_100_Liked_Questions, Array, Binary_Search | 261 | 77.91 +| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version/Solution.kt)| Easy | Binary_Search, Interactive | 349 | 76.86 + +#### Day 8 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- +| 0098 |[Validate Binary Search Tree](src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree/Solution.kt)| 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)) | 190 | 61.62 +| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/kotlin/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.kt)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 404 | 75.59 + +#### Day 9 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- +| 0733 |[Flood Fill](src/main/kotlin/g0701_0800/s0733_flood_fill/Solution.kt)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 230 | 97.76 +| 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands/Solution.kt)| 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) | 252 | 95.41 + +#### Day 10 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0509 |[Fibonacci Number](src/main/kotlin/g0501_0600/s0509_fibonacci_number/Solution.kt)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 139 | 82.72 +| 0070 |[Climbing Stairs](src/main/kotlin/g0001_0100/s0070_climbing_stairs/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 124 | 71.98 + +#### Day 11 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0746 |[Min Cost Climbing Stairs](src/main/kotlin/g0701_0800/s0746_min_cost_climbing_stairs/Solution.kt)| Easy | Array, Dynamic_Programming | 171 | 96.76 +| 0062 |[Unique Paths](src/main/kotlin/g0001_0100/s0062_unique_paths/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 118 | 94.65 + +#### Day 12 Sliding Window/Two Pointer + +| | | | | | +|-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](src/main/kotlin/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 561 | 54.68 +| 0424 |[Longest Repeating Character Replacement](src/main/kotlin/g0401_0500/s0424_longest_repeating_character_replacement/Solution.kt)| Medium | String, Hash_Table, Sliding_Window | 288 | 84.38 + +#### Day 13 Hashmap + +| | | | | | +|-|-|-|-|-|- +| 0001 |[Two Sum](src/main/kotlin/g0001_0100/s0001_two_sum/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 202 | 91.18 +| 0299 |[Bulls and Cows](src/main/kotlin/g0201_0300/s0299_bulls_and_cows/Solution.kt)| Medium | String, Hash_Table, Counting | 254 | 84.82 + +#### Day 14 Stack + +| | | | | | +|-|-|-|-|-|- +| 0844 |[Backspace String Compare](src/main/kotlin/g0801_0900/s0844_backspace_string_compare/Solution.kt)| Easy | String, Two_Pointers, Stack, Simulation | 126 | 98.31 +| 0394 |[Decode String](src/main/kotlin/g0301_0400/s0394_decode_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 224 | 64.86 + +#### Day 15 Heap + +| | | | | | +|-|-|-|-|-|- +| 1046 |[Last Stone Weight](src/main/kotlin/g1001_1100/s1046_last_stone_weight/Solution.kt)| Easy | Array, Heap_Priority_Queue | 123 | 100.00 +| 0692 |[Top K Frequent Words](src/main/kotlin/g0601_0700/s0692_top_k_frequent_words/Solution.kt)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 239 | 81.10 + ## Contributing Your ideas/fixes/algorithms are more than welcome! diff --git a/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/Solution.kt b/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/Solution.kt new file mode 100644 index 000000000..de1c65fcb --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/Solution.kt @@ -0,0 +1,18 @@ +package g3201_3300.s3232_find_if_digit_game_can_be_won + +// #Easy #Array #Math #2024_08_03_Time_194_ms_(36.00%)_Space_40_MB_(5.33%) + +class Solution { + fun canAliceWin(nums: IntArray): Boolean { + var sdSum = 0 + var ddSum = 0 + for (num in nums) { + if (num / 10 == 0) { + sdSum += num + } else { + ddSum += num + } + } + return sdSum != ddSum + } +} diff --git a/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/readme.md b/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/readme.md new file mode 100644 index 000000000..491cf3a63 --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/readme.md @@ -0,0 +1,44 @@ +3232\. Find if Digit Game Can Be Won + +Easy + +You are given an array of **positive** integers `nums`. + +Alice and Bob are playing a game. In the game, Alice can choose **either** all single-digit numbers or all double-digit numbers from `nums`, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is **strictly greater** than the sum of Bob's numbers. + +Return `true` if Alice can win this game, otherwise, return `false`. + +**Example 1:** + +**Input:** nums = [1,2,3,4,10] + +**Output:** false + +**Explanation:** + +Alice cannot win by choosing either single-digit or double-digit numbers. + +**Example 2:** + +**Input:** nums = [1,2,3,4,5,14] + +**Output:** true + +**Explanation:** + +Alice can win by choosing single-digit numbers which have a sum equal to 15. + +**Example 3:** + +**Input:** nums = [5,5,5,25] + +**Output:** true + +**Explanation:** + +Alice can win by choosing double-digit numbers which have a sum equal to 25. + +**Constraints:** + +* `1 <= nums.length <= 100` +* `1 <= nums[i] <= 99` \ No newline at end of file diff --git a/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/Solution.kt b/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/Solution.kt new file mode 100644 index 000000000..d3d684af5 --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/Solution.kt @@ -0,0 +1,49 @@ +package g3201_3300.s3233_find_the_count_of_numbers_which_are_not_special + +// #Medium #Array #Math #Number_Theory #2024_08_03_Time_215_ms_(76.19%)_Space_36.9_MB_(61.90%) + +import kotlin.math.sqrt + +class Solution { + fun nonSpecialCount(l: Int, r: Int): Int { + val primes = sieveOfEratosthenes(sqrt(r.toDouble()).toInt()) + var specialCount = 0 + + for (prime in primes) { + val primeSquare = prime.toLong() * prime + if (primeSquare in l..r) { + specialCount++ + } + } + + val totalNumbersInRange = r - l + 1 + return totalNumbersInRange - specialCount + } + + private fun sieveOfEratosthenes(n: Int): List { + val isPrime = BooleanArray(n + 1) + for (i in 2..n) { + isPrime[i] = true + } + + var p = 2 + while (p * p <= n) { + if (isPrime[p]) { + var i = p * p + while (i <= n) { + isPrime[i] = false + i += p + } + } + p++ + } + + val primes: MutableList = ArrayList() + for (i in 2..n) { + if (isPrime[i]) { + primes.add(i) + } + } + return primes + } +} diff --git a/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/readme.md b/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/readme.md new file mode 100644 index 000000000..f7fe205aa --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/readme.md @@ -0,0 +1,36 @@ +3233\. Find the Count of Numbers Which Are Not Special + +Medium + +You are given 2 **positive** integers `l` and `r`. For any number `x`, all positive divisors of `x` _except_ `x` are called the **proper divisors** of `x`. + +A number is called **special** if it has exactly 2 **proper divisors**. For example: + +* The number 4 is _special_ because it has proper divisors 1 and 2. +* The number 6 is _not special_ because it has proper divisors 1, 2, and 3. + +Return the count of numbers in the range `[l, r]` that are **not** **special**. + +**Example 1:** + +**Input:** l = 5, r = 7 + +**Output:** 3 + +**Explanation:** + +There are no special numbers in the range `[5, 7]`. + +**Example 2:** + +**Input:** l = 4, r = 16 + +**Output:** 11 + +**Explanation:** + +The special numbers in the range `[4, 16]` are 4 and 9. + +**Constraints:** + +* 1 <= l <= r <= 109 \ No newline at end of file diff --git a/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/Solution.kt b/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/Solution.kt new file mode 100644 index 000000000..b64b94f1a --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/Solution.kt @@ -0,0 +1,33 @@ +package g3201_3300.s3234_count_the_number_of_substrings_with_dominant_ones + +// #Medium #String #Sliding_Window #Enumeration +// #2024_08_03_Time_356_ms_(100.00%)_Space_38_MB_(76.92%) + +import kotlin.math.min + +class Solution { + fun numberOfSubstrings(s: String): Int { + val zero: MutableList = ArrayList() + zero.add(-1) + var result = 0 + for (i in s.indices) { + if (s[i] == '0') { + zero.add(i) + } else { + result += i - zero[zero.size - 1] + } + for (j in 1 until zero.size) { + val len = j * (j + 1) + if (len > i + 1) { + break + } + val prev = zero[zero.size - j - 1] + val from = min((i - len + 1), zero[zero.size - j]) + if (from > prev) { + result += from - prev + } + } + } + return result + } +} diff --git a/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/readme.md b/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/readme.md new file mode 100644 index 000000000..815b7e720 --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/readme.md @@ -0,0 +1,52 @@ +3234\. Count the Number of Substrings With Dominant Ones + +Medium + +You are given a binary string `s`. + +Return the number of substrings with **dominant** ones. + +A string has **dominant** ones if the number of ones in the string is **greater than or equal to** the **square** of the number of zeros in the string. + +**Example 1:** + +**Input:** s = "00011" + +**Output:** 5 + +**Explanation:** + +The substrings with dominant ones are shown in the table below. + +| i | j | s[i..j] | Number of Zeros | Number of Ones | +|---|---|---------|-----------------|----------------| +| 3 | 3 | 1 | 0 | 1 | +| 4 | 4 | 1 | 0 | 1 | +| 2 | 3 | 01 | 1 | 1 | +| 3 | 4 | 11 | 0 | 2 | +| 2 | 4 | 011 | 1 | 2 | + +**Example 2:** + +**Input:** s = "101101" + +**Output:** 16 + +**Explanation:** + +The substrings with **non-dominant** ones are shown in the table below. + +Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones. + +| i | j | s[i..j] | Number of Zeros | Number of Ones | +|---|---|---------|-----------------|----------------| +| 1 | 1 | 0 | 1 | 0 | +| 4 | 4 | 0 | 1 | 0 | +| 1 | 4 | 0110 | 2 | 2 | +| 0 | 4 | 10110 | 2 | 3 | +| 1 | 5 | 01101 | 2 | 3 | + +**Constraints:** + +* 1 <= s.length <= 4 * 104 +* `s` consists only of characters `'0'` and `'1'`. \ No newline at end of file diff --git a/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/Solution.kt b/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/Solution.kt new file mode 100644 index 000000000..ae90dabe4 --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/Solution.kt @@ -0,0 +1,122 @@ +package g3201_3300.s3235_check_if_the_rectangle_corner_is_reachable + +// #Hard #Array #Math #Depth_First_Search #Breadth_First_Search #Union_Find #Geometry +// #2024_08_03_Time_612_ms_(66.67%)_Space_50.5_MB_(88.89%) + +import kotlin.math.pow +import kotlin.math.sqrt + +class Solution { + fun canReachCorner(x: Int, y: Int, circles: Array): Boolean { + val n = circles.size + val ds = DisjointSet(n + 5) + + // Special nodes for boundaries + val leftBoundary = n + 3 + val topBoundary = n + val rightBoundary = n + 1 + val bottomBoundary = n + 2 + + var i = 0 + for (it in circles) { + val xi = it[0] + val yi = it[1] + val ri = it[2] + if (yi - ri >= y || xi - ri >= x) { + continue + } + if (((xi > (x + y) || yi > y) && (xi > x || yi > x + y))) { + continue + } + if (xi <= ri) { + ds.dsu(i, leftBoundary) + } + if (yi <= ri) { + ds.dsu(i, topBoundary) + } + if (x - xi <= ri) { + ds.dsu(i, rightBoundary) + } + if (y - yi <= ri) { + ds.dsu(i, bottomBoundary) + } + i++ + } + + // Union circles that overlap + i = 0 + while (i < n) { + val x1 = circles[i][0] + val y1 = circles[i][1] + val r1 = circles[i][2] + if (y1 - r1 >= y || x1 - r1 >= x) { + i++ + continue + } + if (((x1 > (x + y) || y1 > y) && (x1 > x || y1 > x + y))) { + i++ + continue + } + + for (j in i + 1 until n) { + val x2 = circles[j][0] + val y2 = circles[j][1] + val r2 = circles[j][2] + val dist = sqrt( + (x1 - x2.toDouble()).pow(2.0) + (y1 - y2.toDouble()).pow(2.0) + ) + if (dist <= (r1 + r2)) { + ds.dsu(i, j) + } + } + i++ + } + + // Check if left is connected to right or top is connected to bottom + if (ds.findUpar(leftBoundary) == ds.findUpar(rightBoundary) || + ds.findUpar(leftBoundary) == ds.findUpar(topBoundary) + ) { + return false + } + return ( + ds.findUpar(bottomBoundary) != ds.findUpar(rightBoundary) && + ds.findUpar(bottomBoundary) != ds.findUpar(topBoundary) + ) + } + + private class DisjointSet(n: Int) { + private val parent: IntArray + private val size = IntArray(n + 1) + + init { + size.fill(1) + parent = IntArray(n + 1) + for (i in 0..n) { + parent[i] = i + } + } + + fun findUpar(u: Int): Int { + if (u == parent[u]) { + return u + } + parent[u] = findUpar(parent[u]) + return parent[u] + } + + fun dsu(u: Int, v: Int) { + val ulpu = findUpar(u) + val ulpv = findUpar(v) + if (ulpv == ulpu) { + return + } + if (size[ulpu] < size[ulpv]) { + parent[ulpu] = ulpv + size[ulpv] += size[ulpu] + } else { + parent[ulpv] = ulpu + size[ulpu] += size[ulpv] + } + } + } +} diff --git a/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/readme.md b/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/readme.md new file mode 100644 index 000000000..d9c000a24 --- /dev/null +++ b/src/main/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/readme.md @@ -0,0 +1,62 @@ +3235\. Check if the Rectangle Corner Is Reachable + +Hard + +You are given two positive integers `X` and `Y`, and a 2D array `circles`, where circles[i] = [xi, yi, ri] denotes a circle with center at (xi, yi) and radius ri. + +There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate `(X, Y)`. You need to check whether there is a path from the bottom left corner to the top right corner such that the **entire path** lies inside the rectangle, **does not** touch or lie inside **any** circle, and touches the rectangle **only** at the two corners. + +Return `true` if such a path exists, and `false` otherwise. + +**Example 1:** + +**Input:** X = 3, Y = 4, circles = [[2,1,1]] + +**Output:** true + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/05/18/example2circle1.png) + +The black curve shows a possible path between `(0, 0)` and `(3, 4)`. + +**Example 2:** + +**Input:** X = 3, Y = 3, circles = [[1,1,2]] + +**Output:** false + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/05/18/example1circle.png) + +No path exists from `(0, 0)` to `(3, 3)`. + +**Example 3:** + +**Input:** X = 3, Y = 3, circles = [[2,1,1],[1,2,1]] + +**Output:** false + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/05/18/example0circle.png) + +No path exists from `(0, 0)` to `(3, 3)`. + +**Example 4:** + +**Input:** X = 4, Y = 4, circles = [[5,5,1]] + +**Output:** true + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/07/31/rectangleexample5.png) + +**Constraints:** + +* 3 <= X, Y <= 109 +* `1 <= circles.length <= 1000` +* `circles[i].length == 3` +* 1 <= xi, yi, ri <= 109 \ No newline at end of file diff --git a/src/test/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/SolutionTest.kt b/src/test/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/SolutionTest.kt new file mode 100644 index 000000000..a3e0eacb4 --- /dev/null +++ b/src/test/kotlin/g3201_3300/s3232_find_if_digit_game_can_be_won/SolutionTest.kt @@ -0,0 +1,22 @@ +package g3201_3300.s3232_find_if_digit_game_can_be_won + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun canAliceWin() { + assertThat(Solution().canAliceWin(intArrayOf(1, 2, 3, 4, 10)), equalTo(false)) + } + + @Test + fun canAliceWin2() { + assertThat(Solution().canAliceWin(intArrayOf(1, 2, 3, 4, 5, 14)), equalTo(true)) + } + + @Test + fun canAliceWin3() { + assertThat(Solution().canAliceWin(intArrayOf(5, 5, 5, 25)), equalTo(true)) + } +} diff --git a/src/test/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/SolutionTest.kt b/src/test/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/SolutionTest.kt new file mode 100644 index 000000000..7407c20a2 --- /dev/null +++ b/src/test/kotlin/g3201_3300/s3233_find_the_count_of_numbers_which_are_not_special/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3201_3300.s3233_find_the_count_of_numbers_which_are_not_special + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun nonSpecialCount() { + assertThat(Solution().nonSpecialCount(5, 7), equalTo(3)) + } + + @Test + fun nonSpecialCount2() { + assertThat(Solution().nonSpecialCount(4, 16), equalTo(11)) + } +} diff --git a/src/test/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/SolutionTest.kt b/src/test/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/SolutionTest.kt new file mode 100644 index 000000000..44470c2d3 --- /dev/null +++ b/src/test/kotlin/g3201_3300/s3234_count_the_number_of_substrings_with_dominant_ones/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3201_3300.s3234_count_the_number_of_substrings_with_dominant_ones + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun numberOfSubstrings() { + assertThat(Solution().numberOfSubstrings("00011"), equalTo(5)) + } + + @Test + fun numberOfSubstrings2() { + assertThat(Solution().numberOfSubstrings("101101"), equalTo(16)) + } +} diff --git a/src/test/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/SolutionTest.kt b/src/test/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/SolutionTest.kt new file mode 100644 index 000000000..f44a63874 --- /dev/null +++ b/src/test/kotlin/g3201_3300/s3235_check_if_the_rectangle_corner_is_reachable/SolutionTest.kt @@ -0,0 +1,39 @@ +package g3201_3300.s3235_check_if_the_rectangle_corner_is_reachable + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun canReachCorner() { + assertThat( + Solution().canReachCorner(3, 4, arrayOf(intArrayOf(2, 1, 1))), + equalTo(true) + ) + } + + @Test + fun canReachCorner2() { + assertThat( + Solution().canReachCorner(3, 3, arrayOf(intArrayOf(1, 1, 2))), + equalTo(false) + ) + } + + @Test + fun canReachCorner3() { + assertThat( + Solution().canReachCorner(3, 3, arrayOf(intArrayOf(2, 1, 1), intArrayOf(1, 2, 1))), + equalTo(false) + ) + } + + @Test + fun canReachCorner4() { + assertThat( + Solution().canReachCorner(4, 4, arrayOf(intArrayOf(5, 5, 1))), + equalTo(true) + ) + } +}