From 187520f2d2fb59e3cfbd1aff3e20736202bbbb09 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sat, 1 Nov 2025 16:21:07 +0200 Subject: [PATCH 01/21] Updated readme --- README.md | 176 +++++++++++++++++++++++++++--------------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 3b1e82222..e67e978c8 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ implementation 'com.github.javadev:leetcode-in-java:1.49' > ["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) @@ -49,91 +48,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.49' * [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/java/g0501_0600/s0595_big_countries/script.sql)| Easy | Database | 262 | 84.64 -| 1757 |[Recyclable and Low Fat Products](src/main/java/g1701_1800/s1757_recyclable_and_low_fat_products/script.sql)| Easy | Database | 475 | 71.54 -| 0584 |[Find Customer Referee](src/main/java/g0501_0600/s0584_find_customer_referee/script.sql)| Easy | Database | 531 | 58.63 -| 0183 |[Customers Who Never Order](src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql)| Easy | Database | 376 | 98.73 - -#### Day 2 Select and Order - -| | | | | | -|-|-|-|-|-|- -| 1873 |[Calculate Special Bonus](src/main/java/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database | 543 | 71.60 -| 0627 |[Swap Salary](src/main/java/g0601_0700/s0627_swap_salary/script.sql)| Easy | Database | 191 | 96.89 -| 0196 |[Delete Duplicate Emails](src/main/java/g0101_0200/s0196_delete_duplicate_emails/script.sql)| Easy | Database | 903 | 48.10 - -#### Day 3 String Processing Functions - -| | | | | | -|-|-|-|-|-|- -| 1667 |[Fix Names in a Table](src/main/java/g1601_1700/s1667_fix_names_in_a_table/script.sql)| Easy | Database | 559 | 80.29 -| 1484 |[Group Sold Products By The Date](src/main/java/g1401_1500/s1484_group_sold_products_by_the_date/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 395 | 77.20 -| 1527 |[Patients With a Condition](src/main/java/g1501_1600/s1527_patients_with_a_condition/script.sql)| Easy | Database | 308 | 66.93 - -#### Day 4 Union and Select - -| | | | | | -|-|-|-|-|-|- -| 1965 |[Employees With Missing Information](src/main/java/g1901_2000/s1965_employees_with_missing_information/script.sql)| Easy | Database | 617 | 30.40 -| 1795 |[Rearrange Products Table](src/main/java/g1701_1800/s1795_rearrange_products_table/script.sql)| Easy | Database | 497 | 64.83 -| 0608 |[Tree Node](src/main/java/g0601_0700/s0608_tree_node/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 347 | 95.17 -| 0176 |[Second Highest Salary](src/main/java/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database | 225 | 73.10 - -#### Day 5 Union - -| | | | | | -|-|-|-|-|-|- -| 0175 |[Combine Two Tables](src/main/java/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database | 491 | 32.30 -| 1581 |[Customer Who Visited but Did Not Make Any Transactions](src/main/java/g1501_1600/s1581_customer_who_visited_but_did_not_make_any_transactions/script.sql)| Easy | Database | 1039 | 76.99 -| 1148 |[Article Views I](src/main/java/g1101_1200/s1148_article_views_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 783 | 64.09 - -#### Day 6 Union - -| | | | | | -|-|-|-|-|-|- -| 0197 |[Rising Temperature](src/main/java/g0101_0200/s0197_rising_temperature/script.sql)| Easy | Database | 342 | 93.76 -| 0607 |[Sales Person](src/main/java/g0601_0700/s0607_sales_person/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1046 | 86.04 - -#### Day 7 Function - -| | | | | | -|-|-|-|-|-|- -| 1141 |[User Activity for the Past 30 Days I](src/main/java/g1101_1200/s1141_user_activity_for_the_past_30_days_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 849 | 72.54 -| 1693 |[Daily Leads and Partners](src/main/java/g1601_1700/s1693_daily_leads_and_partners/script.sql)| Easy | Database | 463 | 78.98 -| 1729 |[Find Followers Count](src/main/java/g1701_1800/s1729_find_followers_count/script.sql)| Easy | Database | 456 | 88.39 - -#### Day 8 Function - -| | | | | | -|-|-|-|-|-|- -| 0586 |[Customer Placing the Largest Number of Orders](src/main/java/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 484 | 66.42 -| 0511 |[Game Play Analysis I](src/main/java/g0501_0600/s0511_game_play_analysis_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 586 | 56.94 -| 1890 |[The Latest Login in 2020](src/main/java/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database | 571 | 73.59 -| 1741 |[Find Total Time Spent by Each Employee](src/main/java/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql)| Easy | Database | 414 | 93.27 - -#### Day 9 Control of Flow - -| | | | | | -|-|-|-|-|-|- -| 1393 |[Capital Gain/Loss](src/main/java/g1301_1400/s1393_capital_gainloss/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 428 | 92.01 -| 1407 |[Top Travellers](src/main/java/g1401_1500/s1407_top_travellers/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 682 | 70.16 -| 1158 |[Market Analysis I](src/main/java/g1101_1200/s1158_market_analysis_i/script.sql)| Medium | Database | 2511 | 78.92 - -#### Day 10 Where - -| | | | | | -|-|-|-|-|-|- -| 0182 |[Duplicate Emails](src/main/java/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database | 303 | 92.08 -| 1050 |[Actors and Directors Who Cooperated At Least Three Times](src/main/java/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 344 | 76.48 -| 1587 |[Bank Account Summary II](src/main/java/g1501_1600/s1587_bank_account_summary_ii/script.sql)| Easy | Database | 630 | 60.32 -| 1084 |[Sales Analysis III](src/main/java/g1001_1100/s1084_sales_analysis_iii/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1066 | 69.71 +* [SQL I](#sql-i) ### Level 1 @@ -631,7 +546,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.49' | 0014 |[Longest Common Prefix](src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java)| Easy | Top_Interview_Questions, String, Big_O_Time_O(n\*m)_Space_O(m) | 0 | 100.00 | 0151 |[Reverse Words in a String](src/main/java/g0101_0200/s0151_reverse_words_in_a_string/Solution.java)| Medium | String, Two_Pointers, LeetCode_75_Array/String | 2 | 99.69 | 0006 |[Zigzag Conversion](src/main/java/g0001_0100/s0006_zigzag_conversion/Solution.java)| Medium | String, Big_O_Time_O(n)_Space_O(n) | 2 | 99.71 -| 0028 |[Implement strStr()](src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 +| 0028 |[Find the Index of the First Occurrence in a String](src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 | 0068 |[Text Justification](src/main/java/g0001_0100/s0068_text_justification/Solution.java)| Hard | Array, String, Simulation | 0 | 100.00 #### Top Interview 150 Two Pointers @@ -1872,7 +1787,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.49' | | | | | | |-|-|-|-|-|- | 0896 |[Monotonic Array](src/main/java/g0801_0900/s0896_monotonic_array/Solution.java)| Easy | Array | 2 | 86.21 -| 0028 |[Implement strStr()](src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 +| 0028 |[Find the Index of the First Occurrence in a String](src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00 #### Day 2 @@ -2112,6 +2027,91 @@ implementation 'com.github.javadev:leetcode-in-java:1.49' | 0886 |[Possible Bipartition](src/main/java/g0801_0900/s0886_possible_bipartition/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 20 | 80.12 | 0785 |[Is Graph Bipartite?](src/main/java/g0701_0800/s0785_is_graph_bipartite/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 0 | 100.00 +### SQL I + +#### Day 1 Select + +| | | | | | +|-|-|-|-|-|- +| 0595 |[Big Countries](src/main/java/g0501_0600/s0595_big_countries/script.sql)| Easy | Database | 262 | 84.64 +| 1757 |[Recyclable and Low Fat Products](src/main/java/g1701_1800/s1757_recyclable_and_low_fat_products/script.sql)| Easy | Database | 475 | 71.54 +| 0584 |[Find Customer Referee](src/main/java/g0501_0600/s0584_find_customer_referee/script.sql)| Easy | Database | 531 | 58.63 +| 0183 |[Customers Who Never Order](src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql)| Easy | Database | 376 | 98.73 + +#### Day 2 Select and Order + +| | | | | | +|-|-|-|-|-|- +| 1873 |[Calculate Special Bonus](src/main/java/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database | 543 | 71.60 +| 0627 |[Swap Salary](src/main/java/g0601_0700/s0627_swap_salary/script.sql)| Easy | Database | 191 | 96.89 +| 0196 |[Delete Duplicate Emails](src/main/java/g0101_0200/s0196_delete_duplicate_emails/script.sql)| Easy | Database | 903 | 48.10 + +#### Day 3 String Processing Functions + +| | | | | | +|-|-|-|-|-|- +| 1667 |[Fix Names in a Table](src/main/java/g1601_1700/s1667_fix_names_in_a_table/script.sql)| Easy | Database | 559 | 80.29 +| 1484 |[Group Sold Products By The Date](src/main/java/g1401_1500/s1484_group_sold_products_by_the_date/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 395 | 77.20 +| 1527 |[Patients With a Condition](src/main/java/g1501_1600/s1527_patients_with_a_condition/script.sql)| Easy | Database | 308 | 66.93 + +#### Day 4 Union and Select + +| | | | | | +|-|-|-|-|-|- +| 1965 |[Employees With Missing Information](src/main/java/g1901_2000/s1965_employees_with_missing_information/script.sql)| Easy | Database | 617 | 30.40 +| 1795 |[Rearrange Products Table](src/main/java/g1701_1800/s1795_rearrange_products_table/script.sql)| Easy | Database | 497 | 64.83 +| 0608 |[Tree Node](src/main/java/g0601_0700/s0608_tree_node/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 347 | 95.17 +| 0176 |[Second Highest Salary](src/main/java/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database | 225 | 73.10 + +#### Day 5 Union + +| | | | | | +|-|-|-|-|-|- +| 0175 |[Combine Two Tables](src/main/java/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database | 491 | 32.30 +| 1581 |[Customer Who Visited but Did Not Make Any Transactions](src/main/java/g1501_1600/s1581_customer_who_visited_but_did_not_make_any_transactions/script.sql)| Easy | Database | 1039 | 76.99 +| 1148 |[Article Views I](src/main/java/g1101_1200/s1148_article_views_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 783 | 64.09 + +#### Day 6 Union + +| | | | | | +|-|-|-|-|-|- +| 0197 |[Rising Temperature](src/main/java/g0101_0200/s0197_rising_temperature/script.sql)| Easy | Database | 342 | 93.76 +| 0607 |[Sales Person](src/main/java/g0601_0700/s0607_sales_person/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1046 | 86.04 + +#### Day 7 Function + +| | | | | | +|-|-|-|-|-|- +| 1141 |[User Activity for the Past 30 Days I](src/main/java/g1101_1200/s1141_user_activity_for_the_past_30_days_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 849 | 72.54 +| 1693 |[Daily Leads and Partners](src/main/java/g1601_1700/s1693_daily_leads_and_partners/script.sql)| Easy | Database | 463 | 78.98 +| 1729 |[Find Followers Count](src/main/java/g1701_1800/s1729_find_followers_count/script.sql)| Easy | Database | 456 | 88.39 + +#### Day 8 Function + +| | | | | | +|-|-|-|-|-|- +| 0586 |[Customer Placing the Largest Number of Orders](src/main/java/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 484 | 66.42 +| 0511 |[Game Play Analysis I](src/main/java/g0501_0600/s0511_game_play_analysis_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 586 | 56.94 +| 1890 |[The Latest Login in 2020](src/main/java/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database | 571 | 73.59 +| 1741 |[Find Total Time Spent by Each Employee](src/main/java/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql)| Easy | Database | 414 | 93.27 + +#### Day 9 Control of Flow + +| | | | | | +|-|-|-|-|-|- +| 1393 |[Capital Gain/Loss](src/main/java/g1301_1400/s1393_capital_gainloss/script.sql)| Medium | LeetCode_Curated_SQL_70, Database | 428 | 92.01 +| 1407 |[Top Travellers](src/main/java/g1401_1500/s1407_top_travellers/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 682 | 70.16 +| 1158 |[Market Analysis I](src/main/java/g1101_1200/s1158_market_analysis_i/script.sql)| Medium | Database | 2511 | 78.92 + +#### Day 10 Where + +| | | | | | +|-|-|-|-|-|- +| 0182 |[Duplicate Emails](src/main/java/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database | 303 | 92.08 +| 1050 |[Actors and Directors Who Cooperated At Least Three Times](src/main/java/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 344 | 76.48 +| 1587 |[Bank Account Summary II](src/main/java/g1501_1600/s1587_bank_account_summary_ii/script.sql)| Easy | Database | 630 | 60.32 +| 1084 |[Sales Analysis III](src/main/java/g1001_1100/s1084_sales_analysis_iii/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1066 | 69.71 + ## Contributing Your ideas/fixes/algorithms are more than welcome! From 35d93df222aad166b4ed5cef65dcb44715ea4f2b Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:30:41 +0700 Subject: [PATCH 02/21] Updated tasks 134-169 --- .../java/g0101_0200/s0134_gas_station/readme.md | 8 ++++---- .../java/g0101_0200/s0136_single_number/readme.md | 6 +++--- .../s0138_copy_list_with_random_pointer/readme.md | 10 +--------- .../readme.md | 13 +++++++++---- .../s0151_reverse_words_in_a_string/readme.md | 12 ------------ .../s0152_maximum_product_subarray/readme.md | 8 ++++---- .../readme.md | 2 +- src/main/java/g0101_0200/s0155_min_stack/readme.md | 9 ++++----- .../readme.md | 10 +++++++--- .../g0101_0200/s0162_find_peak_element/readme.md | 4 ++-- .../readme.md | 10 ++++++---- .../g0101_0200/s0169_majority_element/readme.md | 2 +- 12 files changed, 42 insertions(+), 52 deletions(-) diff --git a/src/main/java/g0101_0200/s0134_gas_station/readme.md b/src/main/java/g0101_0200/s0134_gas_station/readme.md index 18c57df57..fd0955e42 100644 --- a/src/main/java/g0101_0200/s0134_gas_station/readme.md +++ b/src/main/java/g0101_0200/s0134_gas_station/readme.md @@ -6,7 +6,7 @@ There are `n` gas stations along a circular route, where the amount of gas at th 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** +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:** @@ -41,7 +41,7 @@ Given two integer arrays `gas` and `cost`, return _the starting gas station's in **Constraints:** -* `gas.length == n` -* `cost.length == n` +* `n == gas.length == cost.length` * 1 <= n <= 105 -* 0 <= gas[i], cost[i] <= 104 \ No newline at end of file +* 0 <= gas[i], cost[i] <= 104 +* The input is generated such that the answer is unique. \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0136_single_number/readme.md b/src/main/java/g0101_0200/s0136_single_number/readme.md index c8d377bc7..5246177bb 100644 --- a/src/main/java/g0101_0200/s0136_single_number/readme.md +++ b/src/main/java/g0101_0200/s0136_single_number/readme.md @@ -10,19 +10,19 @@ You must implement a solution with a linear runtime complexity and use only cons **Input:** nums = [2,2,1] -**Output:** 1 +**Output:** 1 **Example 2:** **Input:** nums = [4,1,2,1,2] -**Output:** 4 +**Output:** 4 **Example 3:** **Input:** nums = [1] -**Output:** 1 +**Output:** 1 **Constraints:** diff --git a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md index 4a2316baa..031f4e738 100644 --- a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md +++ b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md @@ -41,18 +41,10 @@ Your code will **only** be given the `head` of the original linked list. **Output:** [[3,null],[3,0],[3,null]] -**Example 4:** - -**Input:** head = [] - -**Output:** [] - -**Explanation:** The given linked list is empty (null pointer), so return null. - **Constraints:** * `0 <= n <= 1000` -* `-10000 <= Node.val <= 10000` +* -104 <= Node.val <= 104 * `Node.random` is `null` or is pointing to some node in the linked list. To solve the "Copy List with Random Pointer" problem in Java with a `Solution` class, we'll use a HashMap to maintain a mapping between the original nodes and their corresponding copied nodes. Below are the steps: diff --git a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md index a16fe93e2..07842fae1 100644 --- a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md +++ b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md @@ -2,13 +2,18 @@ Medium -Evaluate the value of an arithmetic expression in [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). +You are given an array of strings `tokens` that represents an arithmetic expression in a [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). -Valid operators are `+`, `-`, `*`, and `/`. Each operand may be an integer or another expression. +Evaluate the expression. Return _an integer that represents the value of the expression_. -**Note** that division between two integers should truncate toward zero. +**Note** that: -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. +* The valid operators are `'+'`, `'-'`, `'*'`, and `'/'`. +* Each operand may be an integer or another expression. +* The division between two integers always **truncates toward zero**. +* There will not be any division by zero. +* The input represents a valid arithmetic expression in a reverse polish notation. +* The answer and all the intermediate calculations can be represented in a **32-bit** integer. **Example 1:** diff --git a/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md index 8817deca4..22a72116e 100644 --- a/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md +++ b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md @@ -32,18 +32,6 @@ Return _a string of the words in reverse order concatenated by a single space._ **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 diff --git a/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md b/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md index 13f4e9510..eb71aaece 100644 --- a/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md +++ b/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md @@ -2,11 +2,11 @@ Medium -Given an integer array `nums`, find a contiguous non-empty subarray within the array that has the largest product, and return _the product_. +Given an integer array `nums`, find a **non-empty subarrays** that has the largest product, and return _the product_. -It is **guaranteed** that the answer will fit in a **32-bit** integer. +The test cases are generated so that the answer will fit in a **32-bit** integer. -A **subarray** is a contiguous subsequence of the array. +**Note** that the product of an array with a single element is the value of that element. **Example 1:** @@ -28,4 +28,4 @@ A **subarray** is a contiguous subsequence of the array. * 1 <= nums.length <= 2 * 104 * `-10 <= nums[i] <= 10` -* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. \ No newline at end of file +* The product of any subarray of `nums` is **guaranteed** to fit in a **32-bit** integer. \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md index db0231d64..d343dafdf 100644 --- a/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md +++ b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md @@ -11,7 +11,7 @@ Notice that **rotating** an array `[a[0], a[1], a[2], ..., a[n-1]]` 1 time resul Given the sorted rotated array `nums` of **unique** elements, return _the minimum element of this array_. -You must write an algorithm that runs in `O(log n) time.` +You must write an algorithm that runs in `O(log n) time`. **Example 1:** diff --git a/src/main/java/g0101_0200/s0155_min_stack/readme.md b/src/main/java/g0101_0200/s0155_min_stack/readme.md index f3a3af2aa..b170fcca6 100644 --- a/src/main/java/g0101_0200/s0155_min_stack/readme.md +++ b/src/main/java/g0101_0200/s0155_min_stack/readme.md @@ -1,6 +1,6 @@ 155\. Min Stack -Easy +Medium Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. @@ -12,12 +12,11 @@ Implement the `MinStack` class: * `int top()` gets the top element of the stack. * `int getMin()` retrieves the minimum element in the stack. -**Example 1:** +You must implement a solution with `O(1)` time complexity for each function. -**Input** +**Example 1:** - ["MinStack","push","push","push","getMin","pop","top","getMin"] - [[],[-2],[0],[-3],[],[],[],[]] +**Input** ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] **Output:** [null,null,null,null,-3,null,0,-2] diff --git a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md index de0e1d801..a1a20f2ea 100644 --- a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md +++ b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md @@ -32,7 +32,11 @@ The judge will then create the linked structure based on these inputs and pass t **Output:** Intersected at '8' -**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. +**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). + +From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. + +- Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2nd node in A and 3rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3rd node in A and 4th node in B) point to the same location in memory. **Example 2:** @@ -58,11 +62,11 @@ The judge will then create the linked structure based on these inputs and pass t * The number of nodes of `listA` is in the `m`. * The number of nodes of `listB` is in the `n`. -* 0 <= m, n <= 3 * 104 +* 1 <= m, n <= 3 * 104 * 1 <= Node.val <= 105 * `0 <= skipA <= m` * `0 <= skipB <= n` * `intersectVal` is `0` if `listA` and `listB` do not intersect. * `intersectVal == listA[skipA] == listB[skipB]` if `listA` and `listB` intersect. -**Follow up:** Could you write a solution that runs in `O(n)` time and use only `O(1)` memory? \ No newline at end of file +**Follow up:** Could you write a solution that runs in `O(m + n)` time and use only `O(1)` memory? diff --git a/src/main/java/g0101_0200/s0162_find_peak_element/readme.md b/src/main/java/g0101_0200/s0162_find_peak_element/readme.md index 06b668448..fd90613ae 100644 --- a/src/main/java/g0101_0200/s0162_find_peak_element/readme.md +++ b/src/main/java/g0101_0200/s0162_find_peak_element/readme.md @@ -4,9 +4,9 @@ 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**. +Given a **0-indexed** 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 may imagine that `nums[-1] = nums[n] = -∞`. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array. You must write an algorithm that runs in `O(log n)` time. diff --git a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md index 81d951f60..712971aa0 100644 --- a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md +++ b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md @@ -1,6 +1,6 @@ 167\. Two Sum II - Input Array Is Sorted -Easy +Medium 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. @@ -8,9 +8,11 @@ Return _the indices of the two numbers,_ index1 _and_ 2,7,11,15], target = 9 **Output:** [1,2] @@ -18,7 +20,7 @@ The tests are generated such that there is **exactly one solution**. You **may n **Example 2:** -**Input:** numbers = [2,3,4], target = 6 +**Input:** numbers = [2,3,4], target = 6 **Output:** [1,3] @@ -26,7 +28,7 @@ The tests are generated such that there is **exactly one solution**. You **may n **Example 3:** -**Input:** numbers = [\-1,0], target = -1 +**Input:** numbers = [\-1,0], target = -1 **Output:** [1,2] diff --git a/src/main/java/g0101_0200/s0169_majority_element/readme.md b/src/main/java/g0101_0200/s0169_majority_element/readme.md index 5ea5071e8..b4c103567 100644 --- a/src/main/java/g0101_0200/s0169_majority_element/readme.md +++ b/src/main/java/g0101_0200/s0169_majority_element/readme.md @@ -22,6 +22,6 @@ The majority element is the element that appears more than `⌊n / 2⌋` times. * `n == nums.length` * 1 <= n <= 5 * 104 -* -231 <= nums[i] <= 231 - 1 +* -109 <= nums[i] <= 109 **Follow-up:** Could you solve the problem in linear time and in `O(1)` space? \ No newline at end of file From e1aabc9869e4a0d98b8069531bbcdf80d6c303e2 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:40:31 +0700 Subject: [PATCH 03/21] Updated tasks 172-215 --- .../readme.md | 6 +-- .../g0101_0200/s0189_rotate_array/readme.md | 2 +- .../g0101_0200/s0190_reverse_bits/readme.md | 44 ++++++++++++++----- .../s0191_number_of_1_bits/readme.md | 29 ++++++------ .../readme.md | 24 +++++++--- .../s0205_isomorphic_strings/readme.md | 17 +++++-- .../s0207_course_schedule/readme.md | 2 +- .../s0209_minimum_size_subarray_sum/readme.md | 4 +- .../s0210_course_schedule_ii/readme.md | 10 +---- .../readme.md | 9 ++-- .../readme.md | 4 +- 11 files changed, 96 insertions(+), 55 deletions(-) diff --git a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md index db592c56c..092d32c77 100644 --- a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md +++ b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md @@ -4,7 +4,7 @@ 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. +Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). @@ -26,6 +26,6 @@ Find the maximum profit you can achieve. You may complete at most `k` transactio **Constraints:** -* `0 <= k <= 100` -* `0 <= prices.length <= 1000` +* `1 <= k <= 100` +* `1 <= prices.length <= 1000` * `0 <= prices[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0189_rotate_array/readme.md b/src/main/java/g0101_0200/s0189_rotate_array/readme.md index 390f2692e..7b85b1dcd 100644 --- a/src/main/java/g0101_0200/s0189_rotate_array/readme.md +++ b/src/main/java/g0101_0200/s0189_rotate_array/readme.md @@ -2,7 +2,7 @@ Medium -Given an array, rotate the array to the right by `k` steps, where `k` is non-negative. +Given an integer array `nums`, rotate the array to the right by `k` steps, where `k` is non-negative. **Example 1:** diff --git a/src/main/java/g0101_0200/s0190_reverse_bits/readme.md b/src/main/java/g0101_0200/s0190_reverse_bits/readme.md index cd57e6556..ebe579022 100644 --- a/src/main/java/g0101_0200/s0190_reverse_bits/readme.md +++ b/src/main/java/g0101_0200/s0190_reverse_bits/readme.md @@ -2,31 +2,51 @@ Easy -Reverse bits of a given 32 bits unsigned integer. +Reverse bits of a given 32 bits signed integer. -**Note:** +**Example 1:** -* 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`. +**Input:** n = 43261596 -**Example 1:** +**Output:** 964176192 + +**Explanation:** + +Integer + +Binary + +43261596 -**Input:** n = 00000010100101000001111010011100 +00000010100101000001111010011100 -**Output:** 964176192 (00111001011110000010100101000000) +964176192 -**Explanation:** The input binary string **00000010100101000001111010011100** represents the unsigned integer 43261596, so return 964176192 which its binary representation is **00111001011110000010100101000000**. +00111001011110000010100101000000 **Example 2:** -**Input:** n = 11111111111111111111111111111101 +**Input:** n = 2147483644 + +**Output:** 1073741822 + +**Explanation:** + +Integer + +Binary + +2147483644 + +01111111111111111111111111111100 -**Output:** 3221225471 (10111111111111111111111111111111) +1073741822 -**Explanation:** The input binary string **11111111111111111111111111111101** represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is **10111111111111111111111111111111**. +00111111111111111111111111111110 **Constraints:** -* The input must be a **binary string** of length `32` +* 0 <= n <= 231 - 2 +* `n` is even. **Follow up:** If this function is called many times, how would you optimize it? \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md b/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md index 2237b5c87..7db6444f3 100644 --- a/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md +++ b/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md @@ -2,39 +2,40 @@ 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`. +Given a positive integer `n`, write a function that returns the number of set bits in its binary representation (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)). **Example 1:** -**Input:** n = 00000000000000000000000000001011 +**Input:** n = 11 **Output:** 3 -**Explanation:** The input binary string **00000000000000000000000000001011** has a total of three '1' bits. +**Explanation:** + +The input binary string **1011** has a total of three set bits. **Example 2:** -**Input:** n = 00000000000000000000000010000000 +**Input:** n = 128 **Output:** 1 -**Explanation:** The input binary string **00000000000000000000000010000000** has a total of one '1' bit. +**Explanation:** + +The input binary string **10000000** has a total of one set bit. **Example 3:** -**Input:** n = 11111111111111111111111111111101 +**Input:** n = 2147483645 + +**Output:** 30 -**Output:** 31 +**Explanation:** -**Explanation:** The input binary string **11111111111111111111111111111101** has a total of thirty one '1' bits. +The input binary string **1111111111111111111111111111101** has a total of thirty set bits. **Constraints:** -* The input must be a **binary string** of length `32`. +* 1 <= n <= 231 - 1 **Follow up:** If this function is called many times, how would you optimize it? \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md index cce1fc176..e2b9590ab 100644 --- a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md +++ b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md @@ -6,23 +6,35 @@ Given the `root` of a binary tree, imagine yourself standing on the **right side **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] +**Output:** [1,3,4] + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/11/24/tmpd5jn43fs-1.png) **Example 2:** -**Input:** root = [1,null,3] +**Input:** root = [1,2,3,4,null,null,null,5] + +**Output:** [1,3,4,5] -**Output:** [1,3] +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/11/24/tmpkpe40xeh-1.png) **Example 3:** +**Input:** root = [1,null,3] + +**Output:** [1,3] + +**Example 4:** + **Input:** root = [] -**Output:** [] +**Output:** [] **Constraints:** diff --git a/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md b/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md index 24fe5c526..d57bc1250 100644 --- a/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md +++ b/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md @@ -12,19 +12,30 @@ All occurrences of a character must be replaced with another character while pre **Input:** s = "egg", t = "add" -**Output:** true +**Output:** true + +**Explanation:** + +The strings `s` and `t` can be made identical by: + +* Mapping `'e'` to `'a'`. +* Mapping `'g'` to `'d'`. **Example 2:** **Input:** s = "foo", t = "bar" -**Output:** false +**Output:** false + +**Explanation:** + +The strings `s` and `t` can not be made identical as `'o'` needs to be mapped to both `'a'` and `'r'`. **Example 3:** **Input:** s = "paper", t = "title" -**Output:** true +**Output:** true **Constraints:** diff --git a/src/main/java/g0201_0300/s0207_course_schedule/readme.md b/src/main/java/g0201_0300/s0207_course_schedule/readme.md index a7b1e9c70..2be17e8f0 100644 --- a/src/main/java/g0201_0300/s0207_course_schedule/readme.md +++ b/src/main/java/g0201_0300/s0207_course_schedule/readme.md @@ -26,7 +26,7 @@ Return `true` if you can finish all courses. Otherwise, return `false`. **Constraints:** -* 1 <= numCourses <= 105 +* `1 <= numCourses <= 2000` * `0 <= prerequisites.length <= 5000` * `prerequisites[i].length == 2` * 0 <= ai, bi < numCourses diff --git a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md index bc5d1b070..15f80a0b2 100644 --- a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md +++ b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md @@ -2,7 +2,7 @@ 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. +Given an array of positive integers `nums` and a positive integer `target`, return _the **minimal length** of a_ **non-empty subarrays** _whose sum is greater than or equal to_ `target`. If there is no such subarray, return `0` instead. **Example 1:** @@ -28,6 +28,6 @@ Given an array of positive integers `nums` and a positive integer `target`, retu * 1 <= target <= 109 * 1 <= nums.length <= 105 -* 1 <= nums[i] <= 105 +* 1 <= nums[i] <= 104 **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))`. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md b/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md index 5b8dc5ee6..32ef6b760 100644 --- a/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md +++ b/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md @@ -14,10 +14,7 @@ Return _the ordering of courses you should take to finish all courses_. If there **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]. +**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:** @@ -25,10 +22,7 @@ Return _the ordering of courses you should take to finish all courses_. If there **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]. +**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:** diff --git a/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md index 940cb2f1a..d16d16268 100644 --- a/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md +++ b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md @@ -33,7 +33,8 @@ Implement the `WordDictionary` class: **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`. +* `1 <= word.length <= 25` +* `word` in `addWord` consists of lowercase English letters. +* `word` in `search` consist of `'.'` or lowercase English letters. +* There will be at most `2` dots in `word` for `search` queries. +* At most 104 calls will be made to `addWord` and `search`. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md index c4c64cba0..aa5b5682a 100644 --- a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md +++ b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md @@ -6,6 +6,8 @@ Given an integer array `nums` and an integer `k`, return _the_ kthkth largest element in the sorted order, not the kth distinct element. +Can you solve it without sorting? + **Example 1:** **Input:** nums = [3,2,1,5,6,4], k = 2 @@ -20,5 +22,5 @@ Note that it is the kth largest element in the sorted or **Constraints:** -* 1 <= k <= nums.length <= 104 +* 1 <= k <= nums.length <= 105 * -104 <= nums[i] <= 104 \ No newline at end of file From 9cb2f5036b912fbe1591b60ef6faab38474e814c Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 2 Nov 2025 22:06:07 +0700 Subject: [PATCH 04/21] Updated asks 219-300 --- .../s0219_contains_duplicate_ii/readme.md | 2 +- .../s0222_count_complete_tree_nodes/readme.md | 2 +- .../g0201_0300/s0228_summary_ranges/readme.md | 20 ++------------ .../s0234_palindrome_linked_list/readme.md | 2 +- .../readme.md | 4 +-- .../s0239_sliding_window_maximum/readme.md | 18 ------------- .../s0240_search_a_2d_matrix_ii/readme.md | 2 +- .../g0201_0300/s0242_valid_anagram/readme.md | 6 ++--- .../java/g0201_0300/s0274_h_index/readme.md | 13 +++------ .../s0287_find_the_duplicate_number/readme.md | 12 +++------ .../g0201_0300/s0289_game_of_life/readme.md | 10 ++++--- .../g0201_0300/s0290_word_pattern/readme.md | 27 +++++++++++-------- .../readme.md | 2 +- .../readme.md | 4 +-- 14 files changed, 43 insertions(+), 81 deletions(-) diff --git a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md index 227015fc0..3ac510266 100644 --- a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md +++ b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md @@ -2,7 +2,7 @@ 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`. +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:** diff --git a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md index 60b870acc..52180e015 100644 --- a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md +++ b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md @@ -1,6 +1,6 @@ 222\. Count Complete Tree Nodes -Medium +Easy Given the `root` of a **complete** binary tree, return the number of the nodes in the tree. diff --git a/src/main/java/g0201_0300/s0228_summary_ranges/readme.md b/src/main/java/g0201_0300/s0228_summary_ranges/readme.md index d7c4ae981..e0dd913e9 100644 --- a/src/main/java/g0201_0300/s0228_summary_ranges/readme.md +++ b/src/main/java/g0201_0300/s0228_summary_ranges/readme.md @@ -4,6 +4,8 @@ Easy You are given a **sorted unique** integer array `nums`. +A **range** `[a,b]` is the set of all integers from `a` to `b` (inclusive). + 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: @@ -27,24 +29,6 @@ Each range `[a,b]` in the list should be output as: **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` diff --git a/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md b/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md index 096f4015e..0293ad232 100644 --- a/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md +++ b/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md @@ -2,7 +2,7 @@ Easy -Given the `head` of a singly linked list, return `true` if it is a palindrome. +Given the `head` of a singly linked list, return `true` _if it is a_ _palindrome_ _or_ `false` _otherwise_. **Example 1:** diff --git a/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md b/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md index aad514d63..33cd79e48 100644 --- a/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md +++ b/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md @@ -24,6 +24,6 @@ You must write an algorithm that runs in `O(n)` time and without using the divis * 2 <= nums.length <= 105 * `-30 <= nums[i] <= 30` -* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. +* The input is generated such that `answer[i]` is **guaranteed** to fit in a **32-bit** integer. -**Follow up:** Can you solve the problem in `O(1) `extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) \ No newline at end of file +**Follow up:** Can you solve the problem in `O(1)` extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md b/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md index e56687482..ff6f98e93 100644 --- a/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md +++ b/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md @@ -29,24 +29,6 @@ Return _the max sliding window_. **Output:** [1] -**Example 3:** - -**Input:** nums = [1,-1], k = 1 - -**Output:** [1,-1] - -**Example 4:** - -**Input:** nums = [9,11], k = 2 - -**Output:** [11] - -**Example 5:** - -**Input:** nums = [4,-2], k = 2 - -**Output:** [4] - **Constraints:** * 1 <= nums.length <= 105 diff --git a/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md index 2e111b7c6..113883ea3 100644 --- a/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md +++ b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md @@ -2,7 +2,7 @@ Medium -Write an efficient algorithm that searches for a `target` value in an `m x n` integer `matrix`. The `matrix` has the following properties: +Write an efficient algorithm that searches for a value `target` in an `m x n` integer matrix `matrix`. This matrix has the following properties: * Integers in each row are sorted in ascending from left to right. * Integers in each column are sorted in ascending from top to bottom. diff --git a/src/main/java/g0201_0300/s0242_valid_anagram/readme.md b/src/main/java/g0201_0300/s0242_valid_anagram/readme.md index ec6cd2c0d..5e596297e 100644 --- a/src/main/java/g0201_0300/s0242_valid_anagram/readme.md +++ b/src/main/java/g0201_0300/s0242_valid_anagram/readme.md @@ -2,19 +2,19 @@ Easy -Given two strings `s` and `t`, return `true` _if_ `t` _is an anagram of_ `s`_, and_ `false` _otherwise_. +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 +**Output:** true **Example 2:** **Input:** s = "rat", t = "car" -**Output:** false +**Output:** false **Constraints:** diff --git a/src/main/java/g0201_0300/s0274_h_index/readme.md b/src/main/java/g0201_0300/s0274_h_index/readme.md index 73d5909ae..54674df27 100644 --- a/src/main/java/g0201_0300/s0274_h_index/readme.md +++ b/src/main/java/g0201_0300/s0274_h_index/readme.md @@ -2,11 +2,9 @@ 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**. +Given an array of integers `citations` where `citations[i]` is the number of citations a researcher received for their ith paper, return _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**. +According to the [definition of h-index on Wikipedia](https://en.wikipedia.org/wiki/H-index): The h-index is defined as the maximum value of `h` such that the given researcher has published at least `h` papers that have each been cited at least `h` times. **Example 1:** @@ -14,10 +12,7 @@ If there are several possible values for `h`, the maximum one is taken as the `h **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. +**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:** @@ -29,4 +24,4 @@ If there are several possible values for `h`, the maximum one is taken as the `h * `n == citations.length` * `1 <= n <= 5000` -* `0 <= citations[i] <= 1000` +* `0 <= citations[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md index fddfbbb90..80f34a277 100644 --- a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md +++ b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md @@ -6,7 +6,7 @@ Given an array of integers `nums` containing `n + 1` integers where each integer There is only **one repeated number** in `nums`, return _this repeated number_. -You must solve the problem **without** modifying the array `nums` and uses only constant extra space. +You must solve the problem **without** modifying the array `nums` and using only constant extra space. **Example 1:** @@ -22,15 +22,9 @@ You must solve the problem **without** modifying the array `nums` and uses only **Example 3:** -**Input:** nums = [1,1] +**Input:** nums = [3,3,3,3,3] -**Output:** 1 - -**Example 4:** - -**Input:** nums = [1,1,2] - -**Output:** 1 +**Output:** 3 **Constraints:** diff --git a/src/main/java/g0201_0300/s0289_game_of_life/readme.md b/src/main/java/g0201_0300/s0289_game_of_life/readme.md index f54ef7a0b..2f7da08ad 100644 --- a/src/main/java/g0201_0300/s0289_game_of_life/readme.md +++ b/src/main/java/g0201_0300/s0289_game_of_life/readme.md @@ -11,7 +11,11 @@ The board is made up of an `m x n` grid of cells, where each cell has an initial 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_. +The next state of the board is determined by applying the above rules simultaneously to every cell in the current state of the `m x n` grid `board`. In this process, births and deaths occur **simultaneously**. + +Given the current state of the `board`, **update** the `board` to reflect its next state. + +**Note** that you do not need to return anything. **Example 1:** @@ -19,7 +23,7 @@ The next state is created by applying the above rules simultaneously to every ce **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]] +**Output:** [[0,0,0],[1,0,1],[0,1,1],[0,1,0]] **Example 2:** @@ -27,7 +31,7 @@ The next state is created by applying the above rules simultaneously to every ce **Input:** board = [[1,1],[1,0]] -**Output:** [[1,1],[1,1]] +**Output:** [[1,1],[1,1]] **Constraints:** diff --git a/src/main/java/g0201_0300/s0290_word_pattern/readme.md b/src/main/java/g0201_0300/s0290_word_pattern/readme.md index b0a003116..0d8303693 100644 --- a/src/main/java/g0201_0300/s0290_word_pattern/readme.md +++ b/src/main/java/g0201_0300/s0290_word_pattern/readme.md @@ -4,37 +4,42 @@ 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`. +Here **follow** means a full match, such that there is a bijection between a letter in `pattern` and a **non-empty** word in `s`. Specifically: + +* Each letter in `pattern` maps to **exactly** one unique word in `s`. +* Each unique word in `s` maps to **exactly** one letter in `pattern`. +* No two letters map to the same word, and no two words map to the same letter. **Example 1:** **Input:** pattern = "abba", s = "dog cat cat dog" -**Output:** true +**Output:** true + +**Explanation:** + +The bijection can be established as: + +* `'a'` maps to `"dog"`. +* `'b'` maps to `"cat"`. **Example 2:** **Input:** pattern = "abba", s = "dog cat cat fish" -**Output:** false +**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 +**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` contains only lowercase English letters and spaces `' '`. * `s` **does not contain** any leading or trailing spaces. * All the words in `s` are separated by a **single space**. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md index 3928225f2..e7f1e8cb5 100644 --- a/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md +++ b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md @@ -2,7 +2,7 @@ Hard -The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. +The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. * For example, for `arr = [2,3,4]`, the median is `3`. * For example, for `arr = [2,3]`, the median is `(2 + 3) / 2 = 2.5`. diff --git a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md index 4b09231aa..90f97daec 100644 --- a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md +++ b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md @@ -2,9 +2,7 @@ Medium -Given an integer array `nums`, return the length of the longest strictly increasing subsequence. - -A **subsequence** is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, `[3,6,2,7]` is a subsequence of the array `[0,3,1,6,2,2,7]`. +Given an integer array `nums`, return _the length of the longest **strictly increasing**_ **subsequences**. **Example 1:** From 1665a9292929ef8270bb69c7c0364fecf74dc938 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Mon, 3 Nov 2025 20:42:46 +0700 Subject: [PATCH 05/21] Updated tasks 322-1143 --- .../s0347_top_k_frequent_elements/readme.md | 7 +++++++ .../readme.md | 19 ++++++------------ .../readme.md | 2 +- .../g0301_0400/s0383_ransom_note/readme.md | 8 ++++---- .../g0301_0400/s0392_is_subsequence/readme.md | 6 +++--- .../g0301_0400/s0394_decode_string/readme.md | 10 ++-------- .../s0399_evaluate_division/readme.md | 6 ++++-- .../readme.md | 2 +- .../s0427_construct_quad_tree/readme.md | 10 ++++------ .../s0433_minimum_genetic_mutation/readme.md | 20 ++++++------------- .../readme.md | 6 ++---- .../s0560_subarray_sum_equals_k/readme.md | 4 +++- .../readme.md | 4 ++-- .../s0763_partition_labels/readme.md | 10 ++++------ .../s0909_snakes_and_ladders/readme.md | 12 +++++------ 15 files changed, 55 insertions(+), 71 deletions(-) diff --git a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md index 9e5239fd7..57fa49510 100644 --- a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md +++ b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md @@ -16,9 +16,16 @@ Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequen **Output:** [1] +**Example 3:** + +**Input:** nums = [1,2,1,2,1,2,3,1,3,2], k = 2 + +**Output:** [1,2] + **Constraints:** * 1 <= nums.length <= 105 +* -104 <= nums[i] <= 104 * `k` is in the range `[1, the number of unique elements in the array]`. * It is **guaranteed** that the answer is **unique**. diff --git a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md index eba0c310d..0b08c05a3 100644 --- a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md +++ b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md @@ -2,7 +2,7 @@ Medium -You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`. +You are given two integer arrays `nums1` and `nums2` sorted in **non-decreasing 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. @@ -14,7 +14,7 @@ Return _the_ `k` _pairs_ (u1, v1), (u2, v **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] +**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:** @@ -22,19 +22,12 @@ Return _the_ `k` _pairs_ (u1, v1), (u2, v **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] +**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] **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` \ No newline at end of file +* `nums1` and `nums2` both are sorted in **non-decreasing order**. +* 1 <= k <= 104 +* `k <= nums1.length * nums2.length` \ No newline at end of file diff --git a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md index 7e2c59116..63a824c0d 100644 --- a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md +++ b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md @@ -35,4 +35,4 @@ You must implement the functions of the class such that each function works in * * -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. +* There will be **at least one** element in the data structure when `getRandom` is called. \ No newline at end of file diff --git a/src/main/java/g0301_0400/s0383_ransom_note/readme.md b/src/main/java/g0301_0400/s0383_ransom_note/readme.md index 63348ff02..57f5e85d6 100644 --- a/src/main/java/g0301_0400/s0383_ransom_note/readme.md +++ b/src/main/java/g0301_0400/s0383_ransom_note/readme.md @@ -2,7 +2,7 @@ Easy -Given two stings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed from `magazine` and `false` otherwise. +Given two strings `ransomNote` and `magazine`, return `true` _if_ `ransomNote` _can be constructed by using the letters from_ `magazine` _and_ `false` _otherwise_. Each letter in `magazine` can only be used once in `ransomNote`. @@ -10,19 +10,19 @@ Each letter in `magazine` can only be used once in `ransomNote`. **Input:** ransomNote = "a", magazine = "b" -**Output:** false +**Output:** false **Example 2:** **Input:** ransomNote = "aa", magazine = "ab" -**Output:** false +**Output:** false **Example 3:** **Input:** ransomNote = "aa", magazine = "aab" -**Output:** true +**Output:** true **Constraints:** diff --git a/src/main/java/g0301_0400/s0392_is_subsequence/readme.md b/src/main/java/g0301_0400/s0392_is_subsequence/readme.md index a002fe06d..526536c97 100644 --- a/src/main/java/g0301_0400/s0392_is_subsequence/readme.md +++ b/src/main/java/g0301_0400/s0392_is_subsequence/readme.md @@ -4,19 +4,19 @@ 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). +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 +**Output:** true **Example 2:** **Input:** s = "axc", t = "ahbgdc" -**Output:** false +**Output:** false **Constraints:** diff --git a/src/main/java/g0301_0400/s0394_decode_string/readme.md b/src/main/java/g0301_0400/s0394_decode_string/readme.md index 7c0a9e7f4..56bc3294b 100644 --- a/src/main/java/g0301_0400/s0394_decode_string/readme.md +++ b/src/main/java/g0301_0400/s0394_decode_string/readme.md @@ -6,9 +6,9 @@ Given an encoded string, return its decoded string. The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer. -You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc. +You may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there will not be input like `3a` or `2[4]`. -Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there won't be input like `3a` or `2[4]`. +The test cases are generated so that the length of the output will never exceed 105. **Example 1:** @@ -28,12 +28,6 @@ Furthermore, you may assume that the original data does not contain any digits a **Output:** "abcabccdcdcdef" -**Example 4:** - -**Input:** s = "abc3[cd]xyz" - -**Output:** "abccdcdcdxyz" - **Constraints:** * `1 <= s.length <= 30` diff --git a/src/main/java/g0301_0400/s0399_evaluate_division/readme.md b/src/main/java/g0301_0400/s0399_evaluate_division/readme.md index 18a83c514..bbf9ca85d 100644 --- a/src/main/java/g0301_0400/s0399_evaluate_division/readme.md +++ b/src/main/java/g0301_0400/s0399_evaluate_division/readme.md @@ -10,6 +10,8 @@ Return _the answers to all queries_. If a single answer cannot be determined, re **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. +**Note:** The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them. + **Example 1:** **Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] @@ -28,13 +30,13 @@ return: [6.0, 0.5, -1.0, 1.0, -1.0 ] **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] +**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] +**Output:** [0.50000,2.00000,-1.00000,-1.00000] **Constraints:** diff --git a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md index 56f915ce5..ec00c4fc4 100644 --- a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md +++ b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md @@ -2,7 +2,7 @@ Medium -Given a **non-empty** array `nums` containing **only positive integers**, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. +Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_. **Example 1:** diff --git a/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md b/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md index 9e9dd3d1f..67ee6a948 100644 --- a/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md +++ b/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md @@ -2,11 +2,9 @@ Medium -Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent the `grid` with a Quad-Tree. +Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent `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. +Return _the root of the Quad-Tree representing_ `grid`. A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: @@ -34,7 +32,7 @@ If you want to know more about the Quad-Tree, you can refer to the [wiki](https: **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. +You don't need to read this section for solving the problem. This is only if you want to understand the output format here. 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]`. @@ -75,4 +73,4 @@ If the value of `isLeaf` or `val` is True we represent it as **1** in the list ` **Constraints:** * `n == grid.length == grid[i].length` -* n == 2x where `0 <= x <= 6` +* n == 2x where `0 <= x <= 6` \ No newline at end of file diff --git a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md index fa7b3817b..d41f976b3 100644 --- a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md +++ b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md @@ -4,38 +4,30 @@ 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. +Suppose we need to investigate a mutation from a gene string `startGene` to a gene string `endGene` 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`. +Given the two gene strings `startGene` and `endGene` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `startGene` _to_ `endGene`. 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"] +**Input:** startGene = "AACCGGTT", endGene = "AACCGGTA", bank = ["AACCGGTA"] **Output:** 1 **Example 2:** -**Input:** start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"] +**Input:** startGene = "AACCGGTT", endGene = "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']`. \ No newline at end of file +* `startGene.length == endGene.length == bank[i].length == 8` +* `startGene`, `endGene`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`. \ No newline at end of file diff --git a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md index f3bc0a87e..2e062e94b 100644 --- a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md +++ b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md @@ -2,9 +2,7 @@ Medium -Given two strings `s` and `p`, return _an array of all the start indices of_ `p`_'s anagrams in_ `s`. You may return the answer in **any order**. - -An **Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. +Given two strings `s` and `p`, return an array of all the start indices of `p`'s anagrams in `s`. You may return the answer in **any order**. **Example 1:** @@ -32,4 +30,4 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ **Constraints:** * 1 <= s.length, p.length <= 3 * 104 -* `s` and `p` consist of lowercase English letters. +* `s` and `p` consist of lowercase English letters. \ No newline at end of file diff --git a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md index 4b437072e..ad4c2952b 100644 --- a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md +++ b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md @@ -2,7 +2,9 @@ Medium -Given an array of integers `nums` and an integer `k`, return _the total number of continuous subarrays whose sum equals to `k`_. +Given an array of integers `nums` and an integer `k`, return _the total number of subarrays whose sum equals to_ `k`. + +A subarray is a contiguous **non-empty** sequence of elements within an array. **Example 1:** diff --git a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md index 8bae0a477..1099bb2bd 100644 --- a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md +++ b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md @@ -10,7 +10,7 @@ Given the `root` of a binary tree, return _the average value of the nodes on eac **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]. +**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:** @@ -18,7 +18,7 @@ Given the `root` of a binary tree, return _the average value of the nodes on eac **Input:** root = [3,9,20,15,7] -**Output:** [3.00000,14.50000,11.00000] +**Output:** [3.00000,14.50000,11.00000] **Constraints:** diff --git a/src/main/java/g0701_0800/s0763_partition_labels/readme.md b/src/main/java/g0701_0800/s0763_partition_labels/readme.md index 143aa81a6..1b3a56057 100644 --- a/src/main/java/g0701_0800/s0763_partition_labels/readme.md +++ b/src/main/java/g0701_0800/s0763_partition_labels/readme.md @@ -2,7 +2,9 @@ Medium -You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. +You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string `"ababcc"` can be partitioned into `["abab", "cc"]`, but partitions such as `["aba", "bcc"]` or `["ab", "ab", "cc"]` are invalid. + +Note that the partition is done so that after concatenating all the parts in order, the resultant string should be `s`. Return _a list of integers representing the size of these parts_. @@ -12,11 +14,7 @@ Return _a list of integers representing the size of these parts_. **Output:** [9,7,8] -**Explanation:** - - The partition is "ababcbaca", "defegde", "hijhklij". - This is a partition so that each letter appears in at most one part. - A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts. +**Explanation:** The partition is "ababcbaca", "defegde", "hijhklij". This is a partition so that each letter appears in at most one part. A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts. **Example 2:** diff --git a/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md b/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md index f143794a6..1f64f55ae 100644 --- a/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md +++ b/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md @@ -11,13 +11,13 @@ You start on square `1` of the board. In each move, starting from square `curr`, * 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. +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 are not the starting points of any 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. +Note that you only take a snake or ladder at most once per dice roll. 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`. +Return _the least number of dice rolls required to reach the square_ n2_. If it is not possible to reach the square, return_ `-1`. **Example 1:** @@ -45,11 +45,11 @@ This is the lowest possible number of moves to reach the last square, so return **Input:** board = [[-1,-1],[-1,3]] -**Output:** 1 +**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. \ No newline at end of file +* `board[i][j]` is either `-1` or in the range [1, n2]. +* The squares labeled `1` and n2 are not the starting points of any snake or ladder. \ No newline at end of file From feb366137e97e170bb88f38c4fc700d60e7cd30d Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Tue, 4 Nov 2025 11:25:03 +0200 Subject: [PATCH 06/21] Gradle 9.2.0 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e1113280..bad7c2462 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 90abc44ecf4108aa1e39353e42d24d393bf8f237 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Wed, 5 Nov 2025 18:36:29 +0200 Subject: [PATCH 07/21] Added tasks 3731-3734 --- .../s3731_find_missing_elements/Solution.java | 32 ++ .../s3731_find_missing_elements/readme.md | 46 +++ .../Solution.java | 21 ++ .../readme.md | 51 +++ .../Solution.java | 47 +++ .../readme.md | 53 +++ .../Solution.java | 91 ++++++ .../readme.md | 55 ++++ .../SolutionTest.java | 24 ++ .../SolutionTest.java | 23 ++ .../SolutionTest.java | 23 ++ .../SolutionTest.java | 308 ++++++++++++++++++ 12 files changed, 774 insertions(+) create mode 100644 src/main/java/g3701_3800/s3731_find_missing_elements/Solution.java create mode 100644 src/main/java/g3701_3800/s3731_find_missing_elements/readme.md create mode 100644 src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/Solution.java create mode 100644 src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/readme.md create mode 100644 src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/Solution.java create mode 100644 src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/readme.md create mode 100644 src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/Solution.java create mode 100644 src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/readme.md create mode 100644 src/test/java/g3701_3800/s3731_find_missing_elements/SolutionTest.java create mode 100644 src/test/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/SolutionTest.java create mode 100644 src/test/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/SolutionTest.java create mode 100644 src/test/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/SolutionTest.java diff --git a/src/main/java/g3701_3800/s3731_find_missing_elements/Solution.java b/src/main/java/g3701_3800/s3731_find_missing_elements/Solution.java new file mode 100644 index 000000000..868f197cf --- /dev/null +++ b/src/main/java/g3701_3800/s3731_find_missing_elements/Solution.java @@ -0,0 +1,32 @@ +package g3701_3800.s3731_find_missing_elements; + +// #Easy #Array #Hash_Table #Sorting #Weekly_Contest_474 +// #2025_11_05_Time_2_ms_(94.89%)_Space_46.54_MB_(95.16%) + +import java.util.ArrayList; +import java.util.List; + +public class Solution { + public List findMissingElements(int[] nums) { + int maxi = 0; + int mini = 101; + List list = new ArrayList<>(); + boolean[] array = new boolean[101]; + for (int num : nums) { + array[num] = true; + if (maxi < num) { + maxi = num; + } + if (mini > num) { + mini = num; + } + } + for (int index = mini + 1; index < maxi; index++) { + if (array[index]) { + continue; + } + list.add(index); + } + return list; + } +} diff --git a/src/main/java/g3701_3800/s3731_find_missing_elements/readme.md b/src/main/java/g3701_3800/s3731_find_missing_elements/readme.md new file mode 100644 index 000000000..e48870f98 --- /dev/null +++ b/src/main/java/g3701_3800/s3731_find_missing_elements/readme.md @@ -0,0 +1,46 @@ +3731\. Find Missing Elements + +Easy + +You are given an integer array `nums` consisting of **unique** integers. + +Originally, `nums` contained **every integer** within a certain range. However, some integers might have gone **missing** from the array. + +The **smallest** and **largest** integers of the original range are still present in `nums`. + +Return a **sorted** list of all the missing integers in this range. If no integers are missing, return an **empty** list. + +**Example 1:** + +**Input:** nums = [1,4,2,5] + +**Output:** [3] + +**Explanation:** + +The smallest integer is 1 and the largest is 5, so the full range should be `[1,2,3,4,5]`. Among these, only 3 is missing. + +**Example 2:** + +**Input:** nums = [7,8,6,9] + +**Output:** [] + +**Explanation:** + +The smallest integer is 6 and the largest is 9, so the full range is `[6,7,8,9]`. All integers are already present, so no integer is missing. + +**Example 3:** + +**Input:** nums = [5,1] + +**Output:** [2,3,4] + +**Explanation:** + +The smallest integer is 1 and the largest is 5, so the full range should be `[1,2,3,4,5]`. The missing integers are 2, 3, and 4. + +**Constraints:** + +* `2 <= nums.length <= 100` +* `1 <= nums[i] <= 100` \ No newline at end of file diff --git a/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/Solution.java b/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/Solution.java new file mode 100644 index 000000000..1f5a7f916 --- /dev/null +++ b/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/Solution.java @@ -0,0 +1,21 @@ +package g3701_3800.s3732_maximum_product_of_three_elements_after_one_replacement; + +// #Medium #Array #Math #Sorting #Greedy #Weekly_Contest_474 +// #2025_11_05_Time_4_ms_(95.32%)_Space_97.32_MB_(28.84%) + +public class Solution { + public long maxProduct(int[] nums) { + long a = 0; + long b = 0; + for (int x : nums) { + long ax = Math.abs(x); + if (ax >= a) { + b = a; + a = ax; + } else if (ax > b) { + b = ax; + } + } + return 100000L * a * b; + } +} diff --git a/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/readme.md b/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/readme.md new file mode 100644 index 000000000..48ad50d93 --- /dev/null +++ b/src/main/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/readme.md @@ -0,0 +1,51 @@ +3732\. Maximum Product of Three Elements After One Replacement + +Medium + +You are given an integer array `nums`. + +You **must** replace **exactly one** element in the array with **any** integer value in the range [-105, 105] (inclusive). + +After performing this single replacement, determine the **maximum possible product** of **any three** elements at **distinct indices** from the modified array. + +Return an integer denoting the **maximum product** achievable. + +**Example 1:** + +**Input:** nums = [-5,7,0] + +**Output:** 3500000 + +**Explanation:** + +Replacing 0 with -105 gives the array [-5, 7, -105], which has a product (-5) * 7 * (-105) = 3500000. The maximum product is 3500000. + +**Example 2:** + +**Input:** nums = [-4,-2,-1,-3] + +**Output:** 1200000 + +**Explanation:** + +Two ways to achieve the maximum product include: + +* `[-4, -2, -3]` → replace -2 with 105 → product = (-4) * 105 * (-3) = 1200000. +* `[-4, -1, -3]` → replace -1 with 105 → product = (-4) * 105 * (-3) = 1200000. + +The maximum product is 1200000. + +**Example 3:** + +**Input:** nums = [0,10,0] + +**Output:** 0 + +**Explanation:** + +There is no way to replace an element with another integer and not have a 0 in the array. Hence, the product of all three elements will always be 0, and the maximum product is 0. + +**Constraints:** + +* 3 <= nums.length <= 105 +* -105 <= nums[i] <= 105 \ No newline at end of file diff --git a/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/Solution.java b/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/Solution.java new file mode 100644 index 000000000..af52529e3 --- /dev/null +++ b/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/Solution.java @@ -0,0 +1,47 @@ +package g3701_3800.s3733_minimum_time_to_complete_all_deliveries; + +// #Medium #Math #Binary_Search #Weekly_Contest_474 +// #2025_11_05_Time_1_ms_(100.00%)_Space_44.16_MB_(55.61%) + +public class Solution { + private boolean pos(long k, long n1, long n2, int p1, int p2, long lVal) { + long kP1 = k / p1; + long kP2 = k / p2; + long kL = k / lVal; + long s1 = kP2 - kL; + long s2 = kP1 - kL; + long sB = k - kP1 - kP2 + kL; + long w1 = Math.max(0L, n1 - s1); + long w2 = Math.max(0L, n2 - s2); + return (w1 + w2) <= sB; + } + + private long findGcd(long a, long b) { + if (b == 0) { + return a; + } + return findGcd(b, a % b); + } + + public long minimumTime(int[] d, int[] r) { + long n1 = d[0]; + long n2 = d[1]; + int p1 = r[0]; + int p2 = r[1]; + long g = findGcd(p1, p2); + long l = (long) p1 * p2 / g; + long lo = n1 + n2; + long hi = (n1 + n2) * Math.max(p1, p2); + long res = hi; + while (lo <= hi) { + long mid = lo + (hi - lo) / 2; + if (pos(mid, n1, n2, p1, p2, l)) { + res = mid; + hi = mid - 1; + } else { + lo = mid + 1; + } + } + return res; + } +} diff --git a/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/readme.md b/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/readme.md new file mode 100644 index 000000000..4fbcff723 --- /dev/null +++ b/src/main/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/readme.md @@ -0,0 +1,53 @@ +3733\. Minimum Time to Complete All Deliveries + +Medium + +You are given two integer arrays of size 2: d = [d1, d2] and r = [r1, r2]. + +Two delivery drones are tasked with completing a specific number of deliveries. Drone `i` must complete di deliveries. + +Each delivery takes **exactly** one hour and **only one** drone can make a delivery at any given hour. + +Additionally, both drones require recharging at specific intervals during which they cannot make deliveries. Drone `i` must recharge every ri hours (i.e. at hours that are multiples of ri). + +Return an integer denoting the **minimum** total time (in hours) required to complete all deliveries. + +**Example 1:** + +**Input:** d = [3,1], r = [2,3] + +**Output:** 5 + +**Explanation:** + +* The first drone delivers at hours 1, 3, 5 (recharges at hours 2, 4). +* The second drone delivers at hour 2 (recharges at hour 3). + +**Example 2:** + +**Input:** d = [1,3], r = [2,2] + +**Output:** 7 + +**Explanation:** + +* The first drone delivers at hour 3 (recharges at hours 2, 4, 6). +* The second drone delivers at hours 1, 5, 7 (recharges at hours 2, 4, 6). + +**Example 3:** + +**Input:** d = [2,1], r = [3,4] + +**Output:** 3 + +**Explanation:** + +* The first drone delivers at hours 1, 2 (recharges at hour 3). +* The second drone delivers at hour 3. + +**Constraints:** + +* d = [d1, d2] +* 1 <= di <= 109 +* r = [r1, r2] +* 2 <= ri <= 3 * 104 \ No newline at end of file diff --git a/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/Solution.java b/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/Solution.java new file mode 100644 index 000000000..175a26c28 --- /dev/null +++ b/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/Solution.java @@ -0,0 +1,91 @@ +package g3701_3800.s3734_lexicographically_smallest_palindromic_permutation_greater_than_target; + +// #Hard #String #Two_Pointers #Enumeration #Weekly_Contest_474 +// #2025_11_05_Time_2_ms_(100.00%)_Space_46.34_MB_(84.73%) + +import java.util.Arrays; + +public class Solution { + boolean func(int i, String target, char[] ans, int l, int r, int[] freq, boolean end) { + if (l > r) { + return new String(ans).compareTo(target) > 0; + } + if (l == r) { + char left = '#'; + for (int k = 0; k < 26; k++) { + if (freq[k] > 0) { + left = (char) (k + 'a'); + } + } + freq[left - 'a']--; + ans[l] = left; + if (func(i + 1, target, ans, l + 1, r - 1, freq, end)) { + return true; + } + freq[left - 'a']++; + ans[l] = '#'; + return false; + } + if (end) { + for (int j = 0; j < 26; j++) { + if (freq[j] > 1) { + freq[j] -= 2; + ans[l] = ans[r] = (char) (j + 'a'); + if (func(i + 1, target, ans, l + 1, r - 1, freq, end)) { + return true; + } + ans[l] = ans[r] = '#'; + freq[j] += 2; + } + } + return false; + } + char curr = target.charAt(i); + char next = '1'; + for (int k = target.charAt(i) - 'a' + 1; k < 26; k++) { + if (freq[k] > 1) { + next = (char) (k + 'a'); + break; + } + } + if (freq[curr - 'a'] > 1) { + ans[l] = ans[r] = curr; + freq[curr - 'a'] -= 2; + if (func(i + 1, target, ans, l + 1, r - 1, freq, end)) { + return true; + } + freq[curr - 'a'] += 2; + } + if (next != '1') { + ans[l] = ans[r] = next; + freq[next - 'a'] -= 2; + if (func(i + 1, target, ans, l + 1, r - 1, freq, true)) { + return true; + } + } + ans[l] = ans[r] = '#'; + return false; + } + + public String lexPalindromicPermutation(String s, String target) { + int[] freq = new int[26]; + for (int i = 0; i < s.length(); i++) { + freq[s.charAt(i) - 'a']++; + } + int oddc = 0; + for (int i = 0; i < 26; i++) { + if (freq[i] % 2 == 1) { + oddc++; + } + } + if (oddc > 1) { + return ""; + } + char[] ans = new char[s.length()]; + Arrays.fill(ans, '#'); + if (func(0, target, ans, 0, s.length() - 1, freq, false)) { + return new String(ans); + } + return ""; + } +} diff --git a/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/readme.md b/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/readme.md new file mode 100644 index 000000000..fbf7ec289 --- /dev/null +++ b/src/main/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/readme.md @@ -0,0 +1,55 @@ +3734\. Lexicographically Smallest Palindromic Permutation Greater Than Target + +Hard + +You are given two strings `s` and `target`, each of length `n`, consisting of lowercase English letters. + +Return the **lexicographically smallest string** that is **both** a **palindromic permutation** of `s` and **strictly** greater than `target`. If no such permutation exists, return an empty string. + +**Example 1:** + +**Input:** s = "baba", target = "abba" + +**Output:** "baab" + +**Explanation:** + +* The palindromic permutations of `s` (in lexicographical order) are `"abba"` and `"baab"`. +* The lexicographically smallest permutation that is strictly greater than `target` is `"baab"`. + +**Example 2:** + +**Input:** s = "baba", target = "bbaa" + +**Output:** "" + +**Explanation:** + +* The palindromic permutations of `s` (in lexicographical order) are `"abba"` and `"baab"`. +* None of them is lexicographically strictly greater than `target`. Therefore, the answer is `""`. + +**Example 3:** + +**Input:** s = "abc", target = "abb" + +**Output:** "" + +**Explanation:** + +`s` has no palindromic permutations. Therefore, the answer is `""`. + +**Example 4:** + +**Input:** s = "aac", target = "abb" + +**Output:** "aca" + +**Explanation:** + +* The only palindromic permutation of `s` is `"aca"`. +* `"aca"` is strictly greater than `target`. Therefore, the answer is `"aca"`. + +**Constraints:** + +* `1 <= n == s.length == target.length <= 300` +* `s` and `target` consist of only lowercase English letters. \ No newline at end of file diff --git a/src/test/java/g3701_3800/s3731_find_missing_elements/SolutionTest.java b/src/test/java/g3701_3800/s3731_find_missing_elements/SolutionTest.java new file mode 100644 index 000000000..2d5436c5f --- /dev/null +++ b/src/test/java/g3701_3800/s3731_find_missing_elements/SolutionTest.java @@ -0,0 +1,24 @@ +package g3701_3800.s3731_find_missing_elements; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void findMissingElements() { + assertThat(new Solution().findMissingElements(new int[] {1, 4, 2, 5}), equalTo(List.of(3))); + } + + @Test + void findMissingElements2() { + assertThat(new Solution().findMissingElements(new int[] {7, 8, 6, 9}), equalTo(List.of())); + } + + @Test + void findMissingElements3() { + assertThat(new Solution().findMissingElements(new int[] {5, 1}), equalTo(List.of(2, 3, 4))); + } +} diff --git a/src/test/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/SolutionTest.java b/src/test/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/SolutionTest.java new file mode 100644 index 000000000..7a36d7bfd --- /dev/null +++ b/src/test/java/g3701_3800/s3732_maximum_product_of_three_elements_after_one_replacement/SolutionTest.java @@ -0,0 +1,23 @@ +package g3701_3800.s3732_maximum_product_of_three_elements_after_one_replacement; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maxProduct() { + assertThat(new Solution().maxProduct(new int[] {-5, 7, 0}), equalTo(3500000L)); + } + + @Test + void maxProduct2() { + assertThat(new Solution().maxProduct(new int[] {-4, -2, -1, -3}), equalTo(1200000L)); + } + + @Test + void maxProduct3() { + assertThat(new Solution().maxProduct(new int[] {0, 10, 0}), equalTo(0L)); + } +} diff --git a/src/test/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/SolutionTest.java b/src/test/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/SolutionTest.java new file mode 100644 index 000000000..3948372c7 --- /dev/null +++ b/src/test/java/g3701_3800/s3733_minimum_time_to_complete_all_deliveries/SolutionTest.java @@ -0,0 +1,23 @@ +package g3701_3800.s3733_minimum_time_to_complete_all_deliveries; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minimumTime() { + assertThat(new Solution().minimumTime(new int[] {3, 1}, new int[] {2, 3}), equalTo(5L)); + } + + @Test + void minimumTime2() { + assertThat(new Solution().minimumTime(new int[] {1, 3}, new int[] {2, 2}), equalTo(7L)); + } + + @Test + void minimumTime3() { + assertThat(new Solution().minimumTime(new int[] {2, 1}, new int[] {3, 4}), equalTo(3L)); + } +} diff --git a/src/test/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/SolutionTest.java b/src/test/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/SolutionTest.java new file mode 100644 index 000000000..c1f4cd339 --- /dev/null +++ b/src/test/java/g3701_3800/s3734_lexicographically_smallest_palindromic_permutation_greater_than_target/SolutionTest.java @@ -0,0 +1,308 @@ +package g3701_3800.s3734_lexicographically_smallest_palindromic_permutation_greater_than_target; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasLength; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void lexPalindromicPermutation() { + assertThat(new Solution().lexPalindromicPermutation("baba", "abba"), equalTo("baab")); + } + + @Test + void lexPalindromicPermutation2() { + assertThat(new Solution().lexPalindromicPermutation("baba", "bbaa"), equalTo("")); + } + + @Test + void lexPalindromicPermutation3() { + assertThat(new Solution().lexPalindromicPermutation("abc", "abb"), equalTo("")); + } + + @Test + void lexPalindromicPermutation4() { + assertThat(new Solution().lexPalindromicPermutation("aac", "abb"), equalTo("aca")); + } + + @Test + void lexPalindromicPermutation5() { + // Branch: oddc > 1 + String result = new Solution().lexPalindromicPermutation("abc", "a"); + assertThat(result, equalTo("")); + } + + @Test + void lexPalindromicPermutation6() { + // Branch: oddc = 1 + String result = new Solution().lexPalindromicPermutation("aab", "a"); + assertThat(result, allOf(not(equalTo("")), hasLength(3))); + } + + @Test + void lexPalindromicPermutation7() { + // Branch: oddc = 0 + String result = new Solution().lexPalindromicPermutation("aabb", "ab"); + assertThat(result, not(equalTo(""))); + } + + @Test + void lexPalindromicPermutation8() { + // Branch: func returns false + String result = new Solution().lexPalindromicPermutation("abc", "xyz"); + assertThat(result, equalTo("")); + } + + @Test + void lexPalindromicPermutation9() { + // Edge case: length = 1 + String result = new Solution().lexPalindromicPermutation("a", "a"); + assertThat(result, equalTo("")); + } + + @Test + void lexPalindromicPermutation10() { + // Branch: l > r and comparison result > 0 + String target = "a"; + int[] freq = new int[26]; + char[] ans = {'b', 'b'}; + + boolean result = new Solution().func(0, target, ans, 1, 0, freq, false); + assertThat(result, equalTo(true)); + } + + @Test + void lexPalindromicPermutation11() { + // Branch: l > r and comparison result <= 0 + String target = "z"; + int[] freq = new int[26]; + char[] ans = {'a', 'a'}; + + boolean result = new Solution().func(0, target, ans, 1, 0, freq, false); + assertThat(result, equalTo(false)); + } + + @Test + void lexPalindromicPermutation12() { + // Branch: l == r with available character + String target = "a"; + int[] freq = new int[26]; + // 'a' has frequency 1 + freq[0] = 1; + char[] ans = new char[1]; + + boolean result = new Solution().func(0, target, ans, 0, 0, freq, false); + assertThat(result, equalTo(false)); + assertThat(ans[0], equalTo('#')); + } + + @Test + void lexPalindromicPermutation13() { + // Branch: end = true, finds char with freq > 1 + String target = "ab"; + int[] freq = new int[26]; + // 'a' can form a pair + freq[0] = 2; + freq[1] = 0; + char[] ans = new char[2]; + + boolean result = new Solution().func(1, target, ans, 0, 1, freq, true); + assertThat(result, anyOf(equalTo(true), equalTo(false))); + // Frequency restored + assertThat(freq[0], equalTo(2)); + } + + @Test + void lexPalindromicPermutation14() { + // Branch: end = true, no char has freq > 1 + String target = "ab"; + int[] freq = new int[26]; + freq[0] = 1; + freq[1] = 1; + char[] ans = new char[2]; + + boolean result = new Solution().func(1, target, ans, 0, 1, freq, true); + assertThat(result, equalTo(false)); + } + + @Test + void lexPalindromicPermutation15() { + // Branch: end = true, tries different pairs + String target = "abc"; + int[] freq = new int[26]; + freq[0] = 2; + freq[1] = 2; + freq[2] = 2; + char[] ans = new char[3]; + + new Solution().func(1, target, ans, 0, 2, freq, true); + assertThat(freq[0], equalTo(0)); + assertThat(freq[1], equalTo(2)); + assertThat(freq[2], equalTo(1)); + } + + @Test + void lexPalindromicPermutation16() { + // Branch: end = false, curr has freq > 1 + String target = "a"; + int[] freq = new int[26]; + freq[0] = 2; + char[] ans = new char[2]; + + new Solution().func(0, target, ans, 0, 1, freq, false); + assertThat(freq[0], equalTo(0)); + } + + @Test + void lexPalindromicPermutation17() { + // Branch: end = false, curr has freq <= 1 + String target = "a"; + int[] freq = new int[26]; + freq[0] = 0; + char[] ans = new char[2]; + + new Solution().func(0, target, ans, 0, 1, freq, false); + assertThat(freq[0], equalTo(0)); + } + + @Test + void lexPalindromicPermutation18() { + // Branch: end = false, finds next char with freq > 1 + String target = "a"; + int[] freq = new int[26]; + freq[0] = 0; + freq[1] = 2; + char[] ans = new char[2]; + + new Solution().func(0, target, ans, 0, 1, freq, false); + assertThat(freq[0], equalTo(0)); + assertThat(freq[1], equalTo(0)); + } + + @Test + void lexPalindromicPermutation19() { + // Branch: end = false, no next char with freq > 1 + String target = "z"; + int[] freq = new int[26]; + freq[25] = 1; + char[] ans = new char[2]; + + boolean result = new Solution().func(0, target, ans, 0, 1, freq, false); + assertThat(result, equalTo(false)); + } + + @Test + void lexPalindromicPermutation20() { + // Branch: end = false transitions to end = true + String target = "ab"; + int[] freq = new int[26]; + freq[0] = 2; + freq[1] = 2; + char[] ans = new char[2]; + + new Solution().func(0, target, ans, 0, 1, freq, false); + + assertThat(freq[0], equalTo(2)); + assertThat(freq[1], equalTo(0)); + } + + @Test + void lexPalindromicPermutation21() { + // Verify result is always a palindrome + String result = new Solution().lexPalindromicPermutation("aabbcc", "abc"); + if (!result.isEmpty()) { + String reversed = new StringBuilder(result).reverse().toString(); + assertThat(result, equalTo(reversed)); + } + } + + @Test + void lexPalindromicPermutation22() { + // Verify character frequencies are preserved + String input = "aabbcc"; + String result = new Solution().lexPalindromicPermutation(input, "abc"); + + if (!result.isEmpty()) { + int[] inputFreq = new int[26]; + int[] resultFreq = new int[26]; + + for (char c : input.toCharArray()) { + inputFreq[c - 'a']++; + } + for (char c : result.toCharArray()) { + resultFreq[c - 'a']++; + } + + assertThat(resultFreq, equalTo(inputFreq)); + } + } + + @Test + void lexPalindromicPermutation23() { + // Result length should match input length + String input = "aabbccdd"; + String result = new Solution().lexPalindromicPermutation(input, "abcd"); + + if (!result.isEmpty()) { + assertThat(result.length(), equalTo(input.length())); + } + } + + @Test + void lexPalindromicPermutation24() { + // Result should be >= target in lexicographical order + String result = new Solution().lexPalindromicPermutation("aabbcc", "abc"); + + if (!result.isEmpty()) { + assertThat(result.compareTo("abc"), greaterThanOrEqualTo(0)); + } + } + + @Test + void lexPalindromicPermutation25() { + // Complex scenario with multiple characters + String result = new Solution().lexPalindromicPermutation("aabbccdd", "abcd"); + + assertThat( + result, + anyOf(equalTo(""), allOf(hasLength(8), containsString("a"), containsString("b")))); + } + + @Test + void lexPalindromicPermutation26() { + // Edge case: empty string (if applicable) + String result = new Solution().lexPalindromicPermutation("", ""); + assertThat(result, anyOf(equalTo(""), not(nullValue()))); + } + + @Test + void lexPalindromicPermutation27() { + // Verify frequency array is restored after recursion + String target = "aabb"; + int[] freq = new int[26]; + int[] freqCopy = freq.clone(); + + char[] ans = new char[4]; + new Solution().func(0, target, ans, 0, 3, freq, false); + + assertThat(freq, equalTo(freqCopy)); + } + + @Test + void lexPalindromicPermutation28() { + // Verify char array is properly initialized + String result = new Solution().lexPalindromicPermutation("aa", "a"); + + if (!result.isEmpty()) { + assertThat(result, not(containsString("#"))); + } + } +} From f28222579edcd0b214549b3e3a4c14befb31f502 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 7 Nov 2025 10:15:12 +0200 Subject: [PATCH 08/21] Improved task 2694 --- src/main/java/g2601_2700/s2694_event_emitter/solution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/g2601_2700/s2694_event_emitter/solution.ts b/src/main/java/g2601_2700/s2694_event_emitter/solution.ts index 5881f9b8a..9134edc54 100644 --- a/src/main/java/g2601_2700/s2694_event_emitter/solution.ts +++ b/src/main/java/g2601_2700/s2694_event_emitter/solution.ts @@ -14,7 +14,7 @@ class EventEmitter { subscribe(eventName: string, callback: Callback): Subscription { if (this.eventMap.has(eventName)) { - const set = this.eventMap.get(eventName)! + const set = this.eventMap.get(eventName) set.add(callback) this.eventMap.set(eventName, set) } else { From 8d7030bf387e40567580f5bb2b0577bde3dfabd0 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Mon, 10 Nov 2025 23:24:33 +0700 Subject: [PATCH 09/21] Added tests for tasks 335-3132 --- .../s0335_self_crossing/SolutionTest.java | 56 +++++++++++++++ .../MyCircularDequeTest.java | 71 +++++++++++++++++++ .../SolutionTest.java | 40 +++++++++++ .../s3024_type_of_triangle/SolutionTest.java | 66 +++++++++++++++++ .../SolutionTest.java | 38 ++++++++++ 5 files changed, 271 insertions(+) diff --git a/src/test/java/g0301_0400/s0335_self_crossing/SolutionTest.java b/src/test/java/g0301_0400/s0335_self_crossing/SolutionTest.java index 174f96dae..b23551045 100644 --- a/src/test/java/g0301_0400/s0335_self_crossing/SolutionTest.java +++ b/src/test/java/g0301_0400/s0335_self_crossing/SolutionTest.java @@ -35,4 +35,60 @@ void isSelfCrossing5() { void isSelfCrossing6() { assertThat(new Solution().isSelfCrossing(new int[] {1, 1, 1}), equalTo(false)); } + + @Test + void isSelfCrossing7() { + assertThat(new Solution().isSelfCrossing(new int[] {3, 3, 3, 2, 1, 1}), equalTo(false)); + } + + @Test + void isSelfCrossing8() { + assertThat(new Solution().isSelfCrossing(new int[] {2, 3, 4, 5, 6, 7}), equalTo(false)); + } + + @Test + void isSelfCrossing9() { + assertThat(new Solution().isSelfCrossing(new int[] {2, 2, 3, 2, 2}), equalTo(true)); + } + + @Test + void isSelfCrossing10() { + assertThat(new Solution().isSelfCrossing(new int[] {1, 1, 2, 1, 2, 1}), equalTo(true)); + } + + @Test + void isSelfCrossing11() { + assertThat(new Solution().isSelfCrossing(new int[] {10, 20, 30, 40, 50}), equalTo(false)); + } + + @Test + void isSelfCrossing12() { + assertThat(new Solution().isSelfCrossing(new int[] {3, 3, 4, 2, 2}), equalTo(false)); + } + + @Test + void isSelfCrossing13() { + assertThat(new Solution().isSelfCrossing(new int[] {2, 1, 2, 1}), equalTo(true)); + } + + @Test + void isSelfCrossing14() { + assertThat( + new Solution().isSelfCrossing(new int[] {1, 2, 3, 4, 5, 6, 7, 8}), equalTo(false)); + } + + @Test + void isSelfCrossing15() { + assertThat(new Solution().isSelfCrossing(new int[] {2, 2, 2, 2, 2, 2}), equalTo(true)); + } + + @Test + void isSelfCrossing16() { + assertThat(new Solution().isSelfCrossing(new int[] {1, 1, 2, 1, 1}), equalTo(true)); + } + + @Test + void isSelfCrossing17() { + assertThat(new Solution().isSelfCrossing(new int[] {1, 1, 2, 2, 1, 1}), equalTo(true)); + } } diff --git a/src/test/java/g0601_0700/s0641_design_circular_deque/MyCircularDequeTest.java b/src/test/java/g0601_0700/s0641_design_circular_deque/MyCircularDequeTest.java index 264096020..acf82780e 100644 --- a/src/test/java/g0601_0700/s0641_design_circular_deque/MyCircularDequeTest.java +++ b/src/test/java/g0601_0700/s0641_design_circular_deque/MyCircularDequeTest.java @@ -19,4 +19,75 @@ void myCircularDequeTest() { assertThat(myCircularDeque.insertFront(4), equalTo(true)); assertThat(myCircularDeque.getFront(), equalTo(4)); } + + @Test + void myCircularDequeTest2() { + MyCircularDeque deque = new MyCircularDeque(2); + assertThat(deque.insertFront(10), equalTo(true)); + assertThat(deque.insertFront(20), equalTo(true)); + assertThat(deque.insertFront(30), equalTo(false)); + assertThat(deque.getFront(), equalTo(20)); + assertThat(deque.deleteFront(), equalTo(true)); + assertThat(deque.getFront(), equalTo(10)); + } + + @Test + void myCircularDequeTest3() { + MyCircularDeque deque = new MyCircularDeque(1); + assertThat(deque.deleteFront(), equalTo(false)); + assertThat(deque.deleteLast(), equalTo(false)); + assertThat(deque.getFront(), equalTo(-1)); + assertThat(deque.getRear(), equalTo(-1)); + assertThat(deque.isEmpty(), equalTo(true)); + assertThat(deque.isFull(), equalTo(false)); + } + + @Test + void myCircularDequeTest4() { + MyCircularDeque deque = new MyCircularDeque(2); + assertThat(deque.insertLast(5), equalTo(true)); + assertThat(deque.insertFront(6), equalTo(true)); + assertThat(deque.isFull(), equalTo(true)); + assertThat(deque.insertFront(7), equalTo(false)); + assertThat(deque.getFront(), equalTo(6)); + assertThat(deque.getRear(), equalTo(5)); + } + + @Test + void myCircularDequeTest5() { + MyCircularDeque deque = new MyCircularDeque(3); + assertThat(deque.insertFront(10), equalTo(true)); + assertThat(deque.deleteFront(), equalTo(true)); + assertThat(deque.insertLast(20), equalTo(true)); + assertThat(deque.deleteLast(), equalTo(true)); + assertThat(deque.isEmpty(), equalTo(true)); + } + + @Test + void myCircularDequeTest6() { + MyCircularDeque deque = new MyCircularDeque(1); + assertThat(deque.insertFront(100), equalTo(true)); + assertThat(deque.isFull(), equalTo(true)); + assertThat(deque.getFront(), equalTo(100)); + assertThat(deque.getRear(), equalTo(100)); + assertThat(deque.deleteFront(), equalTo(true)); + assertThat(deque.isEmpty(), equalTo(true)); + } + + @Test + void myCircularDequeTest7() { + MyCircularDeque deque = new MyCircularDeque(5); + deque.insertFront(1); + deque.insertLast(2); + deque.insertFront(3); + deque.insertLast(4); + deque.insertFront(5); + assertThat(deque.isFull(), equalTo(true)); + deque.deleteFront(); + deque.deleteLast(); + assertThat(deque.insertFront(6), equalTo(true)); + assertThat(deque.insertLast(7), equalTo(true)); + assertThat(deque.getFront(), equalTo(6)); + assertThat(deque.getRear(), equalTo(7)); + } } diff --git a/src/test/java/g2801_2900/s2839_check_if_strings_can_be_made_equal_with_operations_i/SolutionTest.java b/src/test/java/g2801_2900/s2839_check_if_strings_can_be_made_equal_with_operations_i/SolutionTest.java index 3c1838249..8275a7373 100644 --- a/src/test/java/g2801_2900/s2839_check_if_strings_can_be_made_equal_with_operations_i/SolutionTest.java +++ b/src/test/java/g2801_2900/s2839_check_if_strings_can_be_made_equal_with_operations_i/SolutionTest.java @@ -15,4 +15,44 @@ void canBeEqual() { void canBeEqual2() { assertThat(new Solution().canBeEqual("abcd", "cdab"), equalTo(true)); } + + @Test + void canBeEqual3() { + assertThat(new Solution().canBeEqual("abcd", "abcd"), equalTo(true)); + } + + @Test + void canBeEqual4() { + assertThat(new Solution().canBeEqual("abcd", "cbad"), equalTo(true)); + } + + @Test + void canBeEqual5() { + assertThat(new Solution().canBeEqual("abcd", "adcb"), equalTo(true)); + } + + @Test + void canBeEqual6() { + assertThat(new Solution().canBeEqual("abcd", "abdc"), equalTo(false)); + } + + @Test + void canBeEqual7() { + assertThat(new Solution().canBeEqual("abcd", "wxyz"), equalTo(false)); + } + + @Test + void canBeEqual8() { + assertThat(new Solution().canBeEqual("aabb", "bbaa"), equalTo(true)); + } + + @Test + void canBeEqual9() { + assertThat(new Solution().canBeEqual("abcd", "cdab"), equalTo(true)); + } + + @Test + void canBeEqual10() { + assertThat(new Solution().canBeEqual("abba", "baab"), equalTo(true)); + } } diff --git a/src/test/java/g3001_3100/s3024_type_of_triangle/SolutionTest.java b/src/test/java/g3001_3100/s3024_type_of_triangle/SolutionTest.java index 531b47a4d..e3afffc02 100644 --- a/src/test/java/g3001_3100/s3024_type_of_triangle/SolutionTest.java +++ b/src/test/java/g3001_3100/s3024_type_of_triangle/SolutionTest.java @@ -15,4 +15,70 @@ void triangleType() { void triangleType2() { assertThat(new Solution().triangleType(new int[] {3, 4, 5}), equalTo("scalene")); } + + @Test + void triangleType3() { + assertThat(new Solution().triangleType(new int[] {5, 5, 3}), equalTo("isosceles")); + } + + @Test + void triangleType4() { + assertThat(new Solution().triangleType(new int[] {1, 2, 3}), equalTo("none")); + } + + @Test + void triangleType5() { + assertThat(new Solution().triangleType(new int[] {100, 100, 100}), equalTo("equilateral")); + } + + @Test + void triangleType6() { + assertThat(new Solution().triangleType(new int[] {7, 10, 7}), equalTo("isosceles")); + } + + @Test + void triangleType7() { + assertThat(new Solution().triangleType(new int[] {0, 4, 4}), equalTo("none")); + } + + @Test + void triangleType8() { + assertThat(new Solution().triangleType(new int[] {-3, 4, 5}), equalTo("none")); + } + + @Test + void triangleType9() { + // 2 + 3 = 5 → equals, not greater → invalid + assertThat(new Solution().triangleType(new int[] {2, 3, 5}), equalTo("none")); + } + + @Test + void triangleType10() { + assertThat(new Solution().triangleType(new int[] {5, 3, 4}), equalTo("scalene")); + } + + @Test + void triangleType11() { + assertThat(new Solution().triangleType(new int[] {4, 6, 6}), equalTo("isosceles")); + } + + @Test + void triangleType12() { + assertThat(new Solution().triangleType(new int[] {0, 0, 0}), equalTo("none")); + } + + @Test + void triangleType13() { + assertThat(new Solution().triangleType(new int[] {5, 5, 6}), equalTo("isosceles")); + } + + @Test + void triangleType14() { + assertThat(new Solution().triangleType(new int[] {10, 11, 12}), equalTo("scalene")); + } + + @Test + void triangleType15() { + assertThat(new Solution().triangleType(new int[] {1, 10, 12}), equalTo("none")); + } } diff --git a/src/test/java/g3101_3200/s3132_find_the_integer_added_to_array_ii/SolutionTest.java b/src/test/java/g3101_3200/s3132_find_the_integer_added_to_array_ii/SolutionTest.java index f42fb537d..40935efb7 100644 --- a/src/test/java/g3101_3200/s3132_find_the_integer_added_to_array_ii/SolutionTest.java +++ b/src/test/java/g3101_3200/s3132_find_the_integer_added_to_array_ii/SolutionTest.java @@ -20,4 +20,42 @@ void minimumAddedInteger2() { new Solution().minimumAddedInteger(new int[] {3, 5, 5, 3}, new int[] {7, 7}), equalTo(2)); } + + @Test + void minimumAddedInteger3() { + assertThat( + new Solution().minimumAddedInteger(new int[] {10, 20, 30, 40}, new int[] {35, 45}), + equalTo(5)); + } + + @Test + void minimumAddedInteger4() { + assertThat( + new Solution().minimumAddedInteger(new int[] {2, 5, 7, 8}, new int[] {9, 10}), + equalTo(2)); + } + + @Test + void minimumAddedInteger5() { + assertThat( + new Solution().minimumAddedInteger(new int[] {2, 2, 2, 4, 4}, new int[] {6, 6, 8}), + equalTo(4)); + } + + @Test + void minimumAddedInteger6() { + assertThat( + new Solution().minimumAddedInteger(new int[] {5, 5, 5, 5}, new int[] {5, 5}), + equalTo(0)); + } + + @Test + void minimumAddedInteger7() { + assertThat( + new Solution() + .minimumAddedInteger( + new int[] {1_000_000, 2_000_000, 3_000_000, 4_000_000}, + new int[] {3_000_002, 4_000_002}), + equalTo(2)); + } } From 0c847b5ff54c032a8461d9c76509f47ea89d906a Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Tue, 11 Nov 2025 23:39:22 +0700 Subject: [PATCH 10/21] Added tests for tasks 852-2549 --- .../SolutionTest.java | 26 ++++++++++++++ .../SolutionTest.java | 35 +++++++++++++++++++ .../SolutionTest.java | 20 +++++++++++ .../SolutionTest.java | 30 ++++++++++++++++ .../SolutionTest.java | 15 ++++++++ 5 files changed, 126 insertions(+) diff --git a/src/test/java/g0801_0900/s0852_peak_index_in_a_mountain_array/SolutionTest.java b/src/test/java/g0801_0900/s0852_peak_index_in_a_mountain_array/SolutionTest.java index 69553a2d9..b8e64e8e0 100644 --- a/src/test/java/g0801_0900/s0852_peak_index_in_a_mountain_array/SolutionTest.java +++ b/src/test/java/g0801_0900/s0852_peak_index_in_a_mountain_array/SolutionTest.java @@ -20,4 +20,30 @@ void peakIndexInMountainArray2() { void peakIndexInMountainArray3() { assertThat(new Solution().peakIndexInMountainArray(new int[] {0, 10, 5, 2}), equalTo(1)); } + + @Test + void peakIndexInMountainArray4() { + assertThat( + new Solution().peakIndexInMountainArray(new int[] {0, 1, 2, 3, 2, 1}), equalTo(3)); + } + + @Test + void peakIndexInMountainArray5() { + assertThat(new Solution().peakIndexInMountainArray(new int[] {5, 10, 7}), equalTo(1)); + } + + @Test + void peakIndexInMountainArray6() { + assertThat(new Solution().peakIndexInMountainArray(new int[] {5, 4, 3, 2, 1}), equalTo(1)); + } + + @Test + void peakIndexInMountainArray7() { + assertThat(new Solution().peakIndexInMountainArray(new int[] {1, 2, 3, 4, 5}), equalTo(-1)); + } + + @Test + void peakIndexInMountainArray8() { + assertThat(new Solution().peakIndexInMountainArray(new int[] {3, 3, 3, 3}), equalTo(-1)); + } } diff --git a/src/test/java/g1701_1800/s1736_latest_time_by_replacing_hidden_digits/SolutionTest.java b/src/test/java/g1701_1800/s1736_latest_time_by_replacing_hidden_digits/SolutionTest.java index 286e82dd0..6bfa98e8c 100644 --- a/src/test/java/g1701_1800/s1736_latest_time_by_replacing_hidden_digits/SolutionTest.java +++ b/src/test/java/g1701_1800/s1736_latest_time_by_replacing_hidden_digits/SolutionTest.java @@ -20,4 +20,39 @@ void maximumTime2() { void maximumTime3() { assertThat(new Solution().maximumTime("1?:22"), equalTo("19:22")); } + + @Test + void maximumTime4() { + assertThat(new Solution().maximumTime("?4:00"), equalTo("14:00")); + } + + @Test + void maximumTime5() { + assertThat(new Solution().maximumTime("??:??"), equalTo("23:59")); + } + + @Test + void maximumTime6() { + assertThat(new Solution().maximumTime("?3:15"), equalTo("23:15")); + } + + @Test + void maximumTime7() { + assertThat(new Solution().maximumTime("2?:45"), equalTo("23:45")); + } + + @Test + void maximumTime8() { + assertThat(new Solution().maximumTime("1?:??"), equalTo("19:59")); + } + + @Test + void maximumTime9() { + assertThat(new Solution().maximumTime("10:?7"), equalTo("10:57")); + } + + @Test + void maximumTime10() { + assertThat(new Solution().maximumTime("22:4?"), equalTo("22:49")); + } } diff --git a/src/test/java/g2301_2400/s2396_strictly_palindromic_number/SolutionTest.java b/src/test/java/g2301_2400/s2396_strictly_palindromic_number/SolutionTest.java index 54aa45d3d..5926e1f9b 100644 --- a/src/test/java/g2301_2400/s2396_strictly_palindromic_number/SolutionTest.java +++ b/src/test/java/g2301_2400/s2396_strictly_palindromic_number/SolutionTest.java @@ -20,4 +20,24 @@ void isStrictlyPalindromic2() { void isStrictlyPalindromic3() { assertThat(new Solution().isStrictlyPalindromic(9779), equalTo(false)); } + + @Test + void isStrictlyPalindromic4() { + assertThat(new Solution().isStrictlyPalindromic(3), equalTo(true)); + } + + @Test + void isStrictlyPalindromic5() { + assertThat(new Solution().isStrictlyPalindromic(2), equalTo(true)); + } + + @Test + void isStrictlyPalindromic6() { + assertThat(new Solution().isStrictlyPalindromic(1), equalTo(true)); + } + + @Test + void isStrictlyPalindromic7() { + assertThat(new Solution().isStrictlyPalindromic(10000), equalTo(false)); + } } diff --git a/src/test/java/g2501_2600/s2525_categorize_box_according_to_criteria/SolutionTest.java b/src/test/java/g2501_2600/s2525_categorize_box_according_to_criteria/SolutionTest.java index fbb1991f3..ada3a0687 100644 --- a/src/test/java/g2501_2600/s2525_categorize_box_according_to_criteria/SolutionTest.java +++ b/src/test/java/g2501_2600/s2525_categorize_box_according_to_criteria/SolutionTest.java @@ -15,4 +15,34 @@ void categorizeBox() { void categorizeBox2() { assertThat(new Solution().categorizeBox(200, 50, 800, 50), equalTo("Neither")); } + + @Test + void categorizeBox3() { + assertThat(new Solution().categorizeBox(10000, 1, 1, 10), equalTo("Bulky")); + } + + @Test + void categorizeBox4() { + assertThat(new Solution().categorizeBox(1000, 1000, 1000, 10), equalTo("Bulky")); + } + + @Test + void categorizeBox5() { + assertThat(new Solution().categorizeBox(10000, 10000, 1, 200), equalTo("Both")); + } + + @Test + void categorizeBox6() { + assertThat(new Solution().categorizeBox(9999, 9999, 1, 99), equalTo("Neither")); + } + + @Test + void categorizeBox7() { + assertThat(new Solution().categorizeBox(10000, 10000, 1, 100), equalTo("Both")); + } + + @Test + void categorizeBox8() { + assertThat(new Solution().categorizeBox(1000, 1000, 1000, 1), equalTo("Bulky")); + } } diff --git a/src/test/java/g2501_2600/s2549_count_distinct_numbers_on_board/SolutionTest.java b/src/test/java/g2501_2600/s2549_count_distinct_numbers_on_board/SolutionTest.java index 1c1de9faf..526463236 100644 --- a/src/test/java/g2501_2600/s2549_count_distinct_numbers_on_board/SolutionTest.java +++ b/src/test/java/g2501_2600/s2549_count_distinct_numbers_on_board/SolutionTest.java @@ -15,4 +15,19 @@ void distinctIntegers() { void distinctIntegers2() { assertThat(new Solution().distinctIntegers(3), equalTo(2)); } + + @Test + void distinctIntegers3() { + assertThat(new Solution().distinctIntegers(1), equalTo(1)); + } + + @Test + void distinctIntegers4() { + assertThat(new Solution().distinctIntegers(2), equalTo(1)); + } + + @Test + void distinctIntegers5() { + assertThat(new Solution().distinctIntegers(1000), equalTo(999)); + } } From 1d51e975dec187f1d0f864ed99b59d08660e05f6 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:18:55 +0700 Subject: [PATCH 11/21] Added tests for tasks 558-3548 --- .../SolutionTest.java | 48 +++++++++++ .../s0715_range_module/RangeModuleTest.java | 83 +++++++++++++++++++ .../SolutionTest.java | 43 ++++++++++ .../SolutionTest.java | 48 +++++++++++ .../SolutionTest.java | 44 ++++++++++ .../SolutionTest.java | 65 +++++++++++++++ 6 files changed, 331 insertions(+) diff --git a/src/test/java/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.java b/src/test/java/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.java index 28fb69e05..35fdd696b 100644 --- a/src/test/java/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.java +++ b/src/test/java/g0501_0600/s0558_logical_or_of_two_binary_grids_represented_as_quad_trees/SolutionTest.java @@ -26,4 +26,52 @@ void intersect() { new Solution().intersect(node1, node2).toString(), equalTo("[0,0][1,1][1,1][1,1][1,0]")); } + + @Test + void intersect2() { + Node n1 = new Node(true, true); + Node n2 = new Node(true, true); + assertThat(new Solution().intersect(n1, n2), equalTo(n1)); + } + + @Test + void intersect3() { + Node n1 = new Node(true, true); + Node n2 = new Node(false, false); + assertThat(new Solution().intersect(n1, n2), equalTo(n1)); + } + + @Test + void intersect4() { + Node n1 = new Node(false, false); + Node n2 = new Node(true, true); + assertThat(new Solution().intersect(n1, n2), equalTo(n2)); + } + + @Test + void intersect5() { + Node n1 = new Node(true, false); + Node n2 = new Node(true, true); + assertThat(new Solution().intersect(n1, n2), equalTo(n2)); + } + + @Test + void intersect6() { + Node a = new Node(true, true); + Node n1 = new Node(false, false); + n1.topLeft = a; + n1.topRight = a; + n1.bottomLeft = a; + n1.bottomRight = a; + + Node n2 = new Node(false, false); + n2.topLeft = new Node(true, true); + n2.topRight = new Node(true, true); + n2.bottomLeft = new Node(true, true); + n2.bottomRight = new Node(true, true); + + Node result = new Solution().intersect(n1, n2); + assertThat(result.isLeaf, equalTo(true)); + assertThat(result.val, equalTo(true)); + } } diff --git a/src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java b/src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java index 33b251b75..0e9d12fe6 100644 --- a/src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java +++ b/src/test/java/g0701_0800/s0715_range_module/RangeModuleTest.java @@ -15,4 +15,87 @@ void solutionTest() { assertThat(rangeModule.queryRange(13, 15), equalTo(false)); assertThat(rangeModule.queryRange(16, 17), equalTo(true)); } + + @Test + void solutionTest2() { + RangeModule rm = new RangeModule(); + rm.addRange(5, 10); + rm.addRange(10, 15); + assertThat(rm.queryRange(6, 14), equalTo(true)); + } + + @Test + void solutionTest3() { + RangeModule rm = new RangeModule(); + rm.addRange(1, 5); + rm.addRange(3, 7); + rm.addRange(6, 10); + assertThat(rm.queryRange(2, 9), equalTo(true)); + assertThat(rm.queryRange(0, 2), equalTo(false)); + } + + @Test + void solutionTest4() { + RangeModule rm = new RangeModule(); + rm.addRange(0, 10); + rm.removeRange(3, 7); + assertThat(rm.queryRange(1, 3), equalTo(true)); + assertThat(rm.queryRange(7, 9), equalTo(true)); + assertThat(rm.queryRange(4, 6), equalTo(false)); + } + + @Test + void solutionTest5() { + RangeModule rm = new RangeModule(); + rm.addRange(5, 8); + rm.removeRange(0, 20); + assertThat(rm.queryRange(5, 7), equalTo(false)); + } + + @Test + void solutionTest6() { + RangeModule rm = new RangeModule(); + rm.addRange(10, 20); + rm.removeRange(5, 12); + assertThat(rm.queryRange(10, 12), equalTo(false)); + assertThat(rm.queryRange(12, 15), equalTo(true)); + } + + @Test + void solutionTest7() { + RangeModule rm = new RangeModule(); + rm.addRange(10, 20); + rm.removeRange(18, 30); + assertThat(rm.queryRange(17, 18), equalTo(true)); + assertThat(rm.queryRange(18, 19), equalTo(false)); + } + + @Test + void solutionTest8() { + RangeModule rm = new RangeModule(); + rm.removeRange(5, 10); + assertThat(rm.queryRange(5, 6), equalTo(false)); + } + + @Test + void solutionTest9() { + RangeModule rm = new RangeModule(); + rm.addRange(5, 7); + rm.addRange(10, 12); + assertThat(rm.queryRange(6, 7), equalTo(true)); + assertThat(rm.queryRange(8, 9), equalTo(false)); + assertThat(rm.queryRange(11, 12), equalTo(true)); + } + + @Test + void solutionTest10() { + RangeModule rm = new RangeModule(); + rm.addRange(1, 5); + rm.addRange(10, 15); + rm.removeRange(3, 12); + + assertThat(rm.queryRange(2, 3), equalTo(true)); + assertThat(rm.queryRange(3, 4), equalTo(false)); + assertThat(rm.queryRange(12, 14), equalTo(true)); + } } diff --git a/src/test/java/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.java b/src/test/java/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.java index 5660871ae..af0189f7b 100644 --- a/src/test/java/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.java +++ b/src/test/java/g1501_1600/s1520_maximum_number_of_non_overlapping_substrings/SolutionTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import java.util.Arrays; +import java.util.Collections; import org.junit.jupiter.api.Test; class SolutionTest { @@ -20,4 +21,46 @@ void maxNumOfSubstrings2() { new Solution().maxNumOfSubstrings("abbaccd"), equalTo(Arrays.asList("bb", "cc", "d"))); } + + @Test + void maxNumOfSubstrings3() { + assertThat(new Solution().maxNumOfSubstrings("a"), equalTo(Arrays.asList("a"))); + } + + @Test + void maxNumOfSubstrings4() { + assertThat(new Solution().maxNumOfSubstrings("abc"), equalTo(Arrays.asList("a", "b", "c"))); + } + + @Test + void maxNumOfSubstrings5() { + assertThat(new Solution().maxNumOfSubstrings("abac"), equalTo(Arrays.asList("b", "c"))); + } + + @Test + void maxNumOfSubstrings6() { + assertThat(new Solution().maxNumOfSubstrings("bba"), equalTo(Arrays.asList("bb", "a"))); + } + + @Test + void maxNumOfSubstrings7() { + assertThat(new Solution().maxNumOfSubstrings("abcabc"), equalTo(Arrays.asList("abcabc"))); + } + + @Test + void maxNumOfSubstrings8() { + assertThat(new Solution().maxNumOfSubstrings("aaaa"), equalTo(Arrays.asList("aaaa"))); + } + + @Test + void maxNumOfSubstrings9() { + assertThat(new Solution().maxNumOfSubstrings(""), equalTo(Collections.emptyList())); + } + + @Test + void maxNumOfSubstrings10() { + assertThat( + new Solution().maxNumOfSubstrings("cabcccbaa"), + equalTo(Arrays.asList("cabcccbaa"))); + } } diff --git a/src/test/java/g2501_2600/s2540_minimum_common_value/SolutionTest.java b/src/test/java/g2501_2600/s2540_minimum_common_value/SolutionTest.java index 0835e3b48..622ab87d6 100644 --- a/src/test/java/g2501_2600/s2540_minimum_common_value/SolutionTest.java +++ b/src/test/java/g2501_2600/s2540_minimum_common_value/SolutionTest.java @@ -17,4 +17,52 @@ void getCommon2() { new Solution().getCommon(new int[] {1, 2, 3, 6}, new int[] {2, 3, 4, 5}), equalTo(2)); } + + @Test + void getCommon3() { + assertThat(new Solution().getCommon(new int[] {1, 2, 3}, new int[] {4, 5, 6}), equalTo(-1)); + } + + @Test + void getCommon4() { + assertThat( + new Solution().getCommon(new int[] {1, 3, 5, 7}, new int[] {0, 2, 4, 7}), + equalTo(7)); + } + + @Test + void getCommon5() { + assertThat(new Solution().getCommon(new int[] {2, 3, 4}, new int[] {2, 5, 6}), equalTo(2)); + } + + @Test + void getCommon6() { + assertThat(new Solution().getCommon(new int[] {5}, new int[] {5}), equalTo(5)); + } + + @Test + void getCommon7() { + assertThat(new Solution().getCommon(new int[] {5}, new int[] {6}), equalTo(-1)); + } + + @Test + void getCommon8() { + assertThat( + new Solution().getCommon(new int[] {1, 2, 3, 4}, new int[] {2, 3, 4}), equalTo(2)); + } + + @Test + void getCommon9() { + assertThat(new Solution().getCommon(new int[] {1, 2}, new int[] {100, 200}), equalTo(-1)); + } + + @Test + void getCommon10() { + assertThat(new Solution().getCommon(new int[] {50, 60}, new int[] {1, 2, 3}), equalTo(-1)); + } + + @Test + void getCommon11() { + assertThat(new Solution().getCommon(new int[] {1, 2, 5}, new int[] {3, 4, 6}), equalTo(-1)); + } } diff --git a/src/test/java/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.java b/src/test/java/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.java index f740a9b43..bf9de976b 100644 --- a/src/test/java/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.java +++ b/src/test/java/g2901_3000/s2905_find_indices_with_index_and_value_difference_ii/SolutionTest.java @@ -23,4 +23,48 @@ void findIndices3() { assertThat( new Solution().findIndices(new int[] {1, 2, 3}, 2, 4), equalTo(new int[] {-1, -1})); } + + @Test + void findIndices4() { + int[] big = new int[100000]; + assertThat( + new Solution().findIndices(big, 1, 1_000_000_000), + equalTo(new int[] {49998, 50000})); + } + + @Test + void findIndices5() { + int[] big = new int[100001]; + assertThat(new Solution().findIndices(big, 2, 100000), equalTo(new int[] {-1, -1})); + } + + @Test + void findIndices6() { + int[] big = new int[100001]; + assertThat(new Solution().findIndices(big, 5, 1_000_000_000), equalTo(new int[] {-1, -1})); + } + + @Test + void findIndices7() { + assertThat( + new Solution().findIndices(new int[] {1, 1, 10}, 1, 5), equalTo(new int[] {0, 2})); + } + + @Test + void findIndices8() { + assertThat( + new Solution().findIndices(new int[] {7, 7, 7}, 3, 1), equalTo(new int[] {-1, -1})); + } + + @Test + void findIndices9() { + assertThat( + new Solution().findIndices(new int[] {9, 3, 5}, 0, 0), equalTo(new int[] {0, 0})); + } + + @Test + void findIndices10() { + assertThat( + new Solution().findIndices(new int[] {3, 10, 3}, 1, 7), equalTo(new int[] {0, 1})); + } } diff --git a/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java b/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java index 424d87bc8..a80e0c66f 100644 --- a/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java +++ b/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java @@ -74,4 +74,69 @@ void canPartitionGrid11() { new int[][] {{2, 40, 2}, {4, 2, 3}, {5, 1, 6}, {7, 8, 9}}), equalTo(true)); } + + @Test + void canPartitionGrid12() { + assertThat( + new Solution().canPartitionGrid(new int[][] {{1, 5}, {2, 4}, {3, 3}}), + equalTo(false)); + } + + @Test + void canPartitionGrid13() { + assertThat(new Solution().canPartitionGrid(new int[][] {{1, 1}, {2, 0}}), equalTo(true)); + } + + @Test + void canPartitionGrid14() { + assertThat(new Solution().canPartitionGrid(new int[][] {{5, 2}, {1, 1}}), equalTo(true)); + } + + @Test + void canPartitionGrid15() { + assertThat(new Solution().canPartitionGrid(new int[][] {{4}, {1}, {3}}), equalTo(true)); + } + + @Test + void canPartitionGrid16() { + assertThat(new Solution().canPartitionGrid(new int[][] {{5}, {3}, {2}}), equalTo(true)); + } + + @Test + void canPartitionGrid17() { + assertThat(new Solution().canPartitionGrid(new int[][] {{2, 2, 4}}), equalTo(true)); + } + + @Test + void canPartitionGrid18() { + assertThat(new Solution().canPartitionGrid(new int[][] {{3, 3, 1}}), equalTo(false)); + } + + @Test + void canPartitionGrid19() { + int[][] grid = {{100000, 100000}, {100000, 100000}}; + assertThat(new Solution().canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid20() { + assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 6}}), equalTo(false)); + } + + @Test + void canPartitionGrid21() { + assertThat(new Solution().canPartitionGrid(new int[][] {{1, 2}, {4, 5}}), equalTo(true)); + } + + @Test + void canPartitionGrid22() { + assertThat(new Solution().canPartitionGrid(new int[][] {{9, 1, 8}}), equalTo(true)); + } + + @Test + void canPartitionGrid23() { + assertThat( + new Solution().canPartitionGrid(new int[][] {{2, 2}, {2, 2}, {1, 1}}), + equalTo(true)); + } } From fb002141b028ea7f20af64500d50962fe8895992 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:20:55 +0700 Subject: [PATCH 12/21] Added tests for tasks 564-2420 --- .../SolutionTest.java | 55 ++++++++++++ .../MyLinkedListTest.java | 84 +++++++++++++++++++ .../s0925_long_pressed_name/SolutionTest.java | 75 +++++++++++++++++ .../s1154_day_of_the_year/SolutionTest.java | 50 +++++++++++ .../SolutionTest.java | 54 ++++++++++++ 5 files changed, 318 insertions(+) diff --git a/src/test/java/g0501_0600/s0564_find_the_closest_palindrome/SolutionTest.java b/src/test/java/g0501_0600/s0564_find_the_closest_palindrome/SolutionTest.java index 88955f49a..991336e3c 100644 --- a/src/test/java/g0501_0600/s0564_find_the_closest_palindrome/SolutionTest.java +++ b/src/test/java/g0501_0600/s0564_find_the_closest_palindrome/SolutionTest.java @@ -15,4 +15,59 @@ void nearestPalindromic() { void nearestPalindromic2() { assertThat(new Solution().nearestPalindromic("1"), equalTo("0")); } + + @Test + void nearestPalindromic3() { + assertThat(new Solution().nearestPalindromic("121"), equalTo("111")); + } + + @Test + void nearestPalindromic4() { + assertThat(new Solution().nearestPalindromic("100"), equalTo("99")); + } + + @Test + void nearestPalindromic5() { + assertThat(new Solution().nearestPalindromic("2"), equalTo("1")); + } + + @Test + void nearestPalindromic6() { + assertThat(new Solution().nearestPalindromic("999"), equalTo("1001")); + } + + @Test + void nearestPalindromic7() { + assertThat(new Solution().nearestPalindromic("1221"), equalTo("1111")); + } + + @Test + void nearestPalindromic8() { + assertThat(new Solution().nearestPalindromic("12321"), equalTo("12221")); + } + + @Test + void nearestPalindromic9() { + assertThat(new Solution().nearestPalindromic("1000001"), equalTo("999999")); + } + + @Test + void nearestPalindromic10() { + assertThat(new Solution().nearestPalindromic("10"), equalTo("9")); + } + + @Test + void nearestPalindromic11() { + assertThat(new Solution().nearestPalindromic("11"), equalTo("9")); + } + + @Test + void nearestPalindromic12() { + assertThat(new Solution().nearestPalindromic("807"), equalTo("808")); + } + + @Test + void nearestPalindromic13() { + assertThat(new Solution().nearestPalindromic("1000"), equalTo("999")); + } } diff --git a/src/test/java/g0701_0800/s0707_design_linked_list/MyLinkedListTest.java b/src/test/java/g0701_0800/s0707_design_linked_list/MyLinkedListTest.java index 53ea179a7..4fddd0673 100644 --- a/src/test/java/g0701_0800/s0707_design_linked_list/MyLinkedListTest.java +++ b/src/test/java/g0701_0800/s0707_design_linked_list/MyLinkedListTest.java @@ -27,4 +27,88 @@ void myLinkedList2() { myLinkedList.deleteAtIndex(0); assertThat(myLinkedList.get(0), equalTo(2)); } + + @Test + void myLinkedList3() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtTail(2); + list.addAtIndex(5, 3); + assertThat(list.get(2), equalTo(-1)); + } + + @Test + void myLinkedList4() { + MyLinkedList list = new MyLinkedList(); + list.addAtIndex(0, 10); + assertThat(list.get(0), equalTo(10)); + } + + @Test + void myLinkedList5() { + MyLinkedList list = new MyLinkedList(); + list.addAtTail(5); + assertThat(list.get(0), equalTo(5)); + } + + @Test + void myLinkedList6() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.deleteAtIndex(5); + assertThat(list.get(0), equalTo(1)); + } + + @Test + void myLinkedList7() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtTail(2); + list.addAtTail(3); + list.deleteAtIndex(0); + assertThat(list.get(0), equalTo(2)); + list.deleteAtIndex(1); + assertThat(list.get(1), equalTo(-1)); + } + + @Test + void myLinkedList8() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtTail(2); + list.addAtTail(3); + list.deleteAtIndex(1); + assertThat(list.get(1), equalTo(3)); + } + + @Test + void myLinkedList9() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtTail(2); + assertThat(list.get(5), equalTo(-1)); + assertThat(list.get(-1), equalTo(2)); + } + + @Test + void myLinkedList10() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtTail(2); + list.addAtIndex(1, 3); + list.deleteAtIndex(0); + list.addAtTail(4); + assertThat(list.get(0), equalTo(3)); + assertThat(list.get(1), equalTo(2)); + assertThat(list.get(2), equalTo(4)); + } + + @Test + void myLinkedList11() { + MyLinkedList list = new MyLinkedList(); + list.addAtHead(1); + list.addAtHead(2); + assertThat(list.get(0), equalTo(2)); + assertThat(list.get(1), equalTo(1)); + } } diff --git a/src/test/java/g0901_1000/s0925_long_pressed_name/SolutionTest.java b/src/test/java/g0901_1000/s0925_long_pressed_name/SolutionTest.java index 438efb04c..9b66ed331 100644 --- a/src/test/java/g0901_1000/s0925_long_pressed_name/SolutionTest.java +++ b/src/test/java/g0901_1000/s0925_long_pressed_name/SolutionTest.java @@ -15,4 +15,79 @@ void isLongPressedName() { void isLongPressedName2() { assertThat(new Solution().isLongPressedName("saeed", "ssaaedd"), equalTo(false)); } + + @Test + void isLongPressedName3() { + assertThat(new Solution().isLongPressedName("alex", "ale"), equalTo(false)); + } + + @Test + void isLongPressedName4() { + assertThat(new Solution().isLongPressedName("alex", "alex"), equalTo(true)); + } + + @Test + void isLongPressedName5() { + assertThat(new Solution().isLongPressedName("alex", "alexxxxx"), equalTo(true)); + } + + @Test + void isLongPressedName6() { + assertThat(new Solution().isLongPressedName("alex", "alexy"), equalTo(false)); + } + + @Test + void isLongPressedName7() { + assertThat(new Solution().isLongPressedName("aabb", "aaabbb"), equalTo(true)); + } + + @Test + void isLongPressedName8() { + assertThat(new Solution().isLongPressedName("alex", "paalex"), equalTo(false)); + } + + @Test + void isLongPressedName9() { + assertThat(new Solution().isLongPressedName("alex", "allez"), equalTo(false)); + } + + @Test + void isLongPressedName10() { + assertThat(new Solution().isLongPressedName("a", "aaaaaa"), equalTo(true)); + } + + @Test + void isLongPressedName11() { + assertThat(new Solution().isLongPressedName("a", "b"), equalTo(false)); + } + + @Test + void isLongPressedName12() { + assertThat(new Solution().isLongPressedName("le", "leeex"), equalTo(false)); + } + + @Test + void isLongPressedName13() { + assertThat(new Solution().isLongPressedName("n", "nnnnn"), equalTo(true)); + } + + @Test + void isLongPressedName14() { + assertThat(new Solution().isLongPressedName("vtkgn", "vttkgnn"), equalTo(true)); + } + + @Test + void isLongPressedName15() { + assertThat(new Solution().isLongPressedName("ab", "aabb"), equalTo(true)); + } + + @Test + void isLongPressedName16() { + assertThat(new Solution().isLongPressedName("ab", "aa"), equalTo(false)); + } + + @Test + void isLongPressedName17() { + assertThat(new Solution().isLongPressedName("abc", "aab"), equalTo(false)); + } } diff --git a/src/test/java/g1101_1200/s1154_day_of_the_year/SolutionTest.java b/src/test/java/g1101_1200/s1154_day_of_the_year/SolutionTest.java index a497dfdc5..f58ff81fc 100644 --- a/src/test/java/g1101_1200/s1154_day_of_the_year/SolutionTest.java +++ b/src/test/java/g1101_1200/s1154_day_of_the_year/SolutionTest.java @@ -15,4 +15,54 @@ void dayOfYear() { void dayOfYear2() { assertThat(new Solution().dayOfYear("2019-02-10"), equalTo(41)); } + + @Test + void dayOfYear3() { + assertThat(new Solution().dayOfYear("2020-02-01"), equalTo(32)); + } + + @Test + void dayOfYear4() { + assertThat(new Solution().dayOfYear("2020-03-01"), equalTo(61)); + } + + @Test + void dayOfYear5() { + assertThat(new Solution().dayOfYear("2019-02-28"), equalTo(59)); + } + + @Test + void dayOfYear6() { + assertThat(new Solution().dayOfYear("2020-02-29"), equalTo(60)); + } + + @Test + void dayOfYear7() { + assertThat(new Solution().dayOfYear("2019-12-31"), equalTo(365)); + } + + @Test + void dayOfYear8() { + assertThat(new Solution().dayOfYear("2020-12-31"), equalTo(366)); + } + + @Test + void dayOfYear9() { + assertThat(new Solution().dayOfYear("2021-01-01"), equalTo(1)); + } + + @Test + void dayOfYear10() { + assertThat(new Solution().dayOfYear("2021-07-04"), equalTo(185)); + } + + @Test + void dayOfYear11() { + assertThat(new Solution().dayOfYear("2000-02-29"), equalTo(60)); + } + + @Test + void dayOfYear12() { + assertThat(new Solution().dayOfYear("1900-03-01"), equalTo(60)); + } } diff --git a/src/test/java/g2401_2500/s2420_find_all_good_indices/SolutionTest.java b/src/test/java/g2401_2500/s2420_find_all_good_indices/SolutionTest.java index 8c99ef121..258acaeed 100644 --- a/src/test/java/g2401_2500/s2420_find_all_good_indices/SolutionTest.java +++ b/src/test/java/g2401_2500/s2420_find_all_good_indices/SolutionTest.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.Test; class SolutionTest { @@ -21,4 +22,57 @@ void goodIndices2() { new Solution().goodIndices(new int[] {2, 1, 1, 2}, 2), equalTo(Collections.emptyList())); } + + @Test + void goodIndices3() { + assertThat( + new Solution().goodIndices(new int[] {5, 3, 4, 2, 1}, 1), + equalTo(Arrays.asList(1, 2, 3))); + } + + @Test + void goodIndices4() { + assertThat(new Solution().goodIndices(new int[] {5, 4, 3, 2, 1}, 2), equalTo(List.of())); + } + + @Test + void goodIndices5() { + assertThat( + new Solution().goodIndices(new int[] {1, 2, 3, 4, 5}, 2), + equalTo(Collections.emptyList())); + } + + @Test + void goodIndices6() { + assertThat( + new Solution().goodIndices(new int[] {1, 2}, 2), equalTo(Collections.emptyList())); + } + + @Test + void goodIndices7() { + assertThat( + new Solution().goodIndices(new int[] {5, 4, 4, 3, 2, 2, 3, 4, 4, 3, 2}, 2), + equalTo(Arrays.asList(3, 4, 5, 6))); + } + + @Test + void goodIndices8() { + assertThat( + new Solution().goodIndices(new int[] {3, 2, 1, 2, 3, 2, 1, 2, 3}, 2), + equalTo(Arrays.asList(2, 6))); + } + + @Test + void goodIndices9() { + assertThat( + new Solution().goodIndices(new int[] {3, 2, 1, 1, 2, 3}, 2), + equalTo(Arrays.asList(2, 3))); + } + + @Test + void goodIndices10() { + assertThat( + new Solution().goodIndices(new int[] {2, 2, 2, 2, 2}, 2), + equalTo(Arrays.asList(2))); + } } From 03752f717ced686267d7e48bc3cb8883a5bd76dd Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:22:14 +0700 Subject: [PATCH 13/21] Added tests for tasks 441-3040 --- .../s0441_arranging_coins/SolutionTest.java | 48 +++++++++++++++ .../s0836_rectangle_overlap/SolutionTest.java | 43 +++++++++++++ .../SolutionTest.java | 60 +++++++++++++++++++ .../SolutionTest.java | 36 +++++++++++ .../SolutionTest.java | 40 +++++++++++++ 5 files changed, 227 insertions(+) diff --git a/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java b/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java index cffac2461..bdca1898d 100644 --- a/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java +++ b/src/test/java/g0401_0500/s0441_arranging_coins/SolutionTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -15,4 +16,51 @@ void findKthNumber() { void arrangeCoins2() { assertThat(new Solution().arrangeCoins(8), equalTo(3)); } + + @Test + void arrangeCoins3() { + assertThat(new Solution().arrangeCoins(0), equalTo(0)); + } + + @Test + void arrangeCoins4() { + assertThat(new Solution().arrangeCoins(1), equalTo(1)); + } + + @Test + void arrangeCoins5() { + assertThat(new Solution().arrangeCoins(2), equalTo(1)); + } + + @Test + void arrangeCoins6() { + assertThat(new Solution().arrangeCoins(3), equalTo(2)); + } + + @Test + void arrangeCoins7() { + assertThat(new Solution().arrangeCoins(6), equalTo(3)); + } + + @Test + void arrangeCoins8() { + assertThat(new Solution().arrangeCoins(2147483647), equalTo(65535)); + } + + @Test + void arrangeCoins9() { + assertThat(new Solution().arrangeCoins(7), equalTo(3)); + } + + @Test + void arrangeCoins10() { + Solution solution = new Solution(); + + Exception exception = + assertThrows(IllegalArgumentException.class, () -> solution.arrangeCoins(-5)); + + assertThat( + exception.getMessage(), + equalTo("Input Number is invalid. Only positive numbers are allowed")); + } } diff --git a/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java b/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java index 48e7d22f8..617eafb6a 100644 --- a/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java +++ b/src/test/java/g0801_0900/s0836_rectangle_overlap/SolutionTest.java @@ -26,4 +26,47 @@ void isRectangleOverlap3() { new Solution().isRectangleOverlap(new int[] {0, 0, 1, 1}, new int[] {2, 2, 3, 3}), equalTo(false)); } + + @Test + void isRectangleOverlap4() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 2, 2}, new int[] {0, 2, 2, 4}), + equalTo(false)); + } + + @Test + void isRectangleOverlap5() { + assertThat( + new Solution().isRectangleOverlap(new int[] {1, 1, 3, 3}, new int[] {1, 0, 3, 1}), + equalTo(false)); + } + + @Test + void isRectangleOverlap6() { + assertThat( + new Solution() + .isRectangleOverlap(new int[] {-3, -3, -1, -1}, new int[] {-2, -2, 0, 0}), + equalTo(true)); + } + + @Test + void isRectangleOverlap7() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 4, 4}, new int[] {1, 1, 3, 3}), + equalTo(true)); + } + + @Test + void isRectangleOverlap8() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 2, 2}, new int[] {0, 0, 2, 2}), + equalTo(true)); + } + + @Test + void isRectangleOverlap9() { + assertThat( + new Solution().isRectangleOverlap(new int[] {0, 0, 1, 1}, new int[] {1, 1, 2, 2}), + equalTo(false)); + } } diff --git a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java index b8d0dcd73..dfc7c1d31 100644 --- a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java +++ b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java @@ -19,4 +19,64 @@ void numMagicSquaresInside() { void numMagicSquaresInside2() { assertThat(new Solution().numMagicSquaresInside(new int[][] {{8}}), equalTo(0)); } + + @Test + void numMagicSquaresInside3() { + assertThat(new Solution().numMagicSquaresInside(new int[][] {{1, 2}, {3, 4}}), equalTo(0)); + } + + @Test + void numMagicSquaresInside4() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {4, 3, 8, 4, 3}, + {9, 5, 1, 9, 5}, + {2, 7, 6, 2, 7}, + {4, 3, 8, 4, 3}, + {9, 5, 1, 9, 5} + }), + equalTo(1)); + } + + @Test + void numMagicSquaresInside5() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {10, 3, 8}, + {9, 5, 1}, + {2, 7, 6} + }), + equalTo(0)); + } + + @Test + void numMagicSquaresInside6() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {4, 3, 8, 4}, + {9, 5, 1, 9}, + {2, 7, 6, 2}, + {4, 3, 8, 4} + }), + equalTo(1)); + } + + @Test + void numMagicSquaresInside7() { + assertThat( + new Solution() + .numMagicSquaresInside( + new int[][] { + {2, 2, 2}, + {2, 2, 2}, + {2, 2, 2} + }), + equalTo(0)); + } } diff --git a/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java b/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java index 0ad390e13..7ab724137 100644 --- a/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java +++ b/src/test/java/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/SolutionTest.java @@ -32,4 +32,40 @@ void distanceK2() { 3), equalTo(Collections.emptyList())); } + + @Test + void distanceK3() { + TreeNode root = + TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4)); + assertThat( + new Solution().distanceK(root, new TreeNode(3), 2), + equalTo(Arrays.asList(6, 2, 0, 8))); + } + + @Test + void distanceK4() { + TreeNode root = + TreeUtils.constructBinaryTree(Arrays.asList(3, 5, 1, 6, 2, 0, 8, null, null, 7, 4)); + assertThat(new Solution().distanceK(root, new TreeNode(7), 1), equalTo(Arrays.asList(2))); + } + + @Test + void distanceK5() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3)); + assertThat(new Solution().distanceK(root, new TreeNode(2), 0), equalTo(Arrays.asList(2))); + } + + @Test + void distanceK6() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3)); + assertThat( + new Solution().distanceK(root, new TreeNode(1), 5), + equalTo(Collections.emptyList())); + } + + @Test + void distanceK7() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, null, 3, null, 4)); + assertThat(new Solution().distanceK(root, new TreeNode(2), 2), equalTo(Arrays.asList(4))); + } } diff --git a/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java b/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java index d4e9c939a..4120a1376 100644 --- a/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java +++ b/src/test/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/SolutionTest.java @@ -15,4 +15,44 @@ void maxOperations() { void maxOperations2() { assertThat(new Solution().maxOperations(new int[] {3, 2, 6, 1, 4}), equalTo(2)); } + + @Test + void maxOperations3() { + assertThat(new Solution().maxOperations(new int[] {1, 2}), equalTo(1)); + } + + @Test + void maxOperations4() { + assertThat(new Solution().maxOperations(new int[] {1, 1, 1}), equalTo(1)); + } + + @Test + void maxOperations5() { + assertThat(new Solution().maxOperations(new int[] {2, 2, 2, 2, 2, 2}), equalTo(3)); + } + + @Test + void maxOperations6() { + assertThat(new Solution().maxOperations(new int[] {1, 2, 3, 4, 5, 6}), equalTo(3)); + } + + @Test + void maxOperations7() { + assertThat(new Solution().maxOperations(new int[] {6, 5, 4, 3, 2, 1}), equalTo(3)); + } + + @Test + void maxOperations8() { + assertThat(new Solution().maxOperations(new int[] {1, 3, 2, 4, 1, 3}), equalTo(2)); + } + + @Test + void maxOperations9() { + assertThat(new Solution().maxOperations(new int[] {1, 2, 4, 5}), equalTo(2)); + } + + @Test + void maxOperations10() { + assertThat(new Solution().maxOperations(new int[] {5, 5}), equalTo(1)); + } } From 4ee679b33cc32e9b534b9b572dbba78d6861c7a3 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:23:25 +0700 Subject: [PATCH 14/21] Added tests for tasks 84-2425 --- .../SolutionTest.java | 40 ++++++++++++++++ .../MedianFinderTest.java | 46 +++++++++++++++++++ .../s0858_mirror_reflection/SolutionTest.java | 35 ++++++++++++++ .../SolutionTest.java | 43 +++++++++++++++++ .../SolutionTest.java | 30 ++++++++++++ 5 files changed, 194 insertions(+) diff --git a/src/test/java/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.java b/src/test/java/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.java index e3d2dcdba..a46c855d7 100644 --- a/src/test/java/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.java +++ b/src/test/java/g0001_0100/s0084_largest_rectangle_in_histogram/SolutionTest.java @@ -15,4 +15,44 @@ void largestRectangleArea() { void largestRectangleArea2() { assertThat(new Solution().largestRectangleArea(new int[] {2, 4}), equalTo(4)); } + + @Test + void largestRectangleArea3() { + assertThat(new Solution().largestRectangleArea(new int[] {}), equalTo(0)); + } + + @Test + void largestRectangleArea4() { + assertThat(new Solution().largestRectangleArea(new int[] {5}), equalTo(5)); + } + + @Test + void largestRectangleArea5() { + assertThat(new Solution().largestRectangleArea(new int[] {3, 6}), equalTo(6)); + } + + @Test + void largestRectangleArea6() { + assertThat(new Solution().largestRectangleArea(new int[] {2, 2, 2, 2}), equalTo(8)); + } + + @Test + void largestRectangleArea7() { + assertThat(new Solution().largestRectangleArea(new int[] {1, 2, 3, 4, 5}), equalTo(9)); + } + + @Test + void largestRectangleArea8() { + assertThat(new Solution().largestRectangleArea(new int[] {5, 4, 3, 2, 1}), equalTo(9)); + } + + @Test + void largestRectangleArea9() { + assertThat(new Solution().largestRectangleArea(new int[] {2, 1, 5, 6, 2, 3}), equalTo(10)); + } + + @Test + void largestRectangleArea10() { + assertThat(new Solution().largestRectangleArea(new int[] {1, 1, 1, 1}), equalTo(4)); + } } diff --git a/src/test/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinderTest.java b/src/test/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinderTest.java index 79e80cbd5..fb516e14f 100644 --- a/src/test/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinderTest.java +++ b/src/test/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinderTest.java @@ -29,4 +29,50 @@ void medianFinder2() { medianFinder.addNum(-1); assertThat(medianFinder.findMedian(), equalTo(1.0)); } + + @Test + void medianFinder3() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(42); + assertThat(medianFinder.findMedian(), equalTo(42.0)); + } + + @Test + void medianFinder4() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(5); + medianFinder.addNum(5); + medianFinder.addNum(5); + medianFinder.addNum(5); + assertThat(medianFinder.findMedian(), equalTo(5.0)); + } + + @Test + void medianFinder5() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(-5); + medianFinder.addNum(-10); + medianFinder.addNum(-3); + assertThat(medianFinder.findMedian(), equalTo(-5.0)); + } + + @Test + void medianFinder6() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(1000); + medianFinder.addNum(1); + medianFinder.addNum(500); + medianFinder.addNum(0); + assertThat(medianFinder.findMedian(), equalTo(250.5)); + } + + @Test + void medianFinder7() { + MedianFinder medianFinder = new MedianFinder(); + medianFinder.addNum(1); + medianFinder.addNum(2); + medianFinder.addNum(3); + medianFinder.addNum(4); + assertThat(medianFinder.findMedian(), equalTo(2.5)); + } } diff --git a/src/test/java/g0801_0900/s0858_mirror_reflection/SolutionTest.java b/src/test/java/g0801_0900/s0858_mirror_reflection/SolutionTest.java index b5c945380..937b3ea00 100644 --- a/src/test/java/g0801_0900/s0858_mirror_reflection/SolutionTest.java +++ b/src/test/java/g0801_0900/s0858_mirror_reflection/SolutionTest.java @@ -15,4 +15,39 @@ void mirrorReflection() { void mirrorReflection2() { assertThat(new Solution().mirrorReflection(3, 1), equalTo(1)); } + + @Test + void mirrorReflection3() { + assertThat(new Solution().mirrorReflection(4, 2), equalTo(2)); + } + + @Test + void mirrorReflection4() { + assertThat(new Solution().mirrorReflection(6, 3), equalTo(2)); + } + + @Test + void mirrorReflection5() { + assertThat(new Solution().mirrorReflection(5, 2), equalTo(0)); + } + + @Test + void mirrorReflection6() { + assertThat(new Solution().mirrorReflection(7, 3), equalTo(1)); + } + + @Test + void mirrorReflection7() { + assertThat(new Solution().mirrorReflection(1000, 250), equalTo(2)); + } + + @Test + void mirrorReflection8() { + assertThat(new Solution().mirrorReflection(4, 4), equalTo(1)); + } + + @Test + void mirrorReflection9() { + assertThat(new Solution().mirrorReflection(1, 1), equalTo(1)); + } } diff --git a/src/test/java/g1901_2000/s1901_find_a_peak_element_ii/SolutionTest.java b/src/test/java/g1901_2000/s1901_find_a_peak_element_ii/SolutionTest.java index 4124764a1..f9c4c2c96 100644 --- a/src/test/java/g1901_2000/s1901_find_a_peak_element_ii/SolutionTest.java +++ b/src/test/java/g1901_2000/s1901_find_a_peak_element_ii/SolutionTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -19,4 +20,46 @@ void findPeakGrid2() { new Solution().findPeakGrid(new int[][] {{10, 20, 15}, {21, 30, 14}, {7, 16, 32}}), equalTo(new int[] {1, 1})); } + + @Test + void findPeakGrid3() { + assertThat( + new Solution().findPeakGrid(new int[][] {{1, 3, 2, 4}}), equalTo(new int[] {0, 1})); + } + + @Test + void findPeakGrid4() { + assertThat( + new Solution().findPeakGrid(new int[][] {{1}, {3}, {2}, {4}}), + equalTo(new int[] {3, 0})); + } + + @Test + void findPeakGrid5() { + assertThat( + new Solution().findPeakGrid(new int[][] {{2, 2}, {2, 2}}), + equalTo(new int[] {0, 1})); + } + + @Test + void findPeakGrid6() { + int[][] mat = { + {1, 2, 3, 6}, + {5, 6, 7, 8}, + {4, 3, 2, 1} + }; + int[] peak = new Solution().findPeakGrid(mat); + assertTrue(peak[0] >= 0 && peak[1] >= 0); + int val = mat[peak[0]][peak[1]]; + int up = peak[0] > 0 ? mat[peak[0] - 1][peak[1]] : -1; + int down = peak[0] < mat.length - 1 ? mat[peak[0] + 1][peak[1]] : -1; + int left = peak[1] > 0 ? mat[peak[0]][peak[1] - 1] : -1; + int right = peak[1] < mat[0].length - 1 ? mat[peak[0]][peak[1] + 1] : -1; + assertTrue(val > up && val > down && val > left && val > right); + } + + @Test + void findPeakGrid7() { + assertThat(new Solution().findPeakGrid(new int[][] {{5}}), equalTo(new int[] {0, 0})); + } } diff --git a/src/test/java/g2401_2500/s2425_bitwise_xor_of_all_pairings/SolutionTest.java b/src/test/java/g2401_2500/s2425_bitwise_xor_of_all_pairings/SolutionTest.java index f9a293fd9..5da08baec 100644 --- a/src/test/java/g2401_2500/s2425_bitwise_xor_of_all_pairings/SolutionTest.java +++ b/src/test/java/g2401_2500/s2425_bitwise_xor_of_all_pairings/SolutionTest.java @@ -17,4 +17,34 @@ void xorAllNums() { void xorAllNums2() { assertThat(new Solution().xorAllNums(new int[] {1, 2}, new int[] {3, 4}), equalTo(0)); } + + @Test + void xorAllNums3() { + assertThat(new Solution().xorAllNums(new int[] {7}, new int[] {1, 2, 3}), equalTo(7)); + } + + @Test + void xorAllNums4() { + assertThat(new Solution().xorAllNums(new int[] {1, 2, 3}, new int[] {5}), equalTo(5)); + } + + @Test + void xorAllNums5() { + assertThat(new Solution().xorAllNums(new int[] {8}, new int[] {6}), equalTo(14)); + } + + @Test + void xorAllNums6() { + assertThat(new Solution().xorAllNums(new int[] {}, new int[] {1, 2, 3}), equalTo(0)); + } + + @Test + void xorAllNums7() { + assertThat(new Solution().xorAllNums(new int[] {4, 5, 6}, new int[] {}), equalTo(0)); + } + + @Test + void xorAllNums8() { + assertThat(new Solution().xorAllNums(new int[] {}, new int[] {}), equalTo(0)); + } } From ed492ec25a24d73c65ca183c72c93e797ab463ca Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:24:17 +0700 Subject: [PATCH 15/21] Added tests for tasks 101-2929 --- .../s0101_symmetric_tree/SolutionTest.java | 29 +++++++++ .../s0198_house_robber/SolutionTest.java | 30 +++++++++ .../MyQueueTest.java | 62 +++++++++++++++++++ .../SolutionTest.java | 32 ++++++++++ .../SolutionTest.java | 35 +++++++++++ 5 files changed, 188 insertions(+) diff --git a/src/test/java/g0101_0200/s0101_symmetric_tree/SolutionTest.java b/src/test/java/g0101_0200/s0101_symmetric_tree/SolutionTest.java index ee46a6774..83f7e2757 100644 --- a/src/test/java/g0101_0200/s0101_symmetric_tree/SolutionTest.java +++ b/src/test/java/g0101_0200/s0101_symmetric_tree/SolutionTest.java @@ -20,4 +20,33 @@ void symmetricTree2() { TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 2, null, 3, null, 3)); assertThat(new Solution().isSymmetric(root), equalTo(false)); } + + @Test + void symmetricTree3() { + assertThat(new Solution().isSymmetric(null), equalTo(true)); + } + + @Test + void symmetricTree4() { + TreeNode root = new TreeNode(1); + assertThat(new Solution().isSymmetric(root), equalTo(true)); + } + + @Test + void symmetricTree5() { + TreeNode root = new TreeNode(1, new TreeNode(2), null); + assertThat(new Solution().isSymmetric(root), equalTo(false)); + } + + @Test + void symmetricTree6() { + TreeNode root = new TreeNode(1, null, new TreeNode(2)); + assertThat(new Solution().isSymmetric(root), equalTo(false)); + } + + @Test + void symmetricTree7() { + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 2, 3, 4, 5, 3)); + assertThat(new Solution().isSymmetric(root), equalTo(false)); + } } diff --git a/src/test/java/g0101_0200/s0198_house_robber/SolutionTest.java b/src/test/java/g0101_0200/s0198_house_robber/SolutionTest.java index fa4c4257a..1e9c95aea 100644 --- a/src/test/java/g0101_0200/s0198_house_robber/SolutionTest.java +++ b/src/test/java/g0101_0200/s0198_house_robber/SolutionTest.java @@ -15,4 +15,34 @@ void rob() { void rob2() { assertThat(new Solution().rob(new int[] {2, 7, 9, 3, 1}), equalTo(12)); } + + @Test + void rob3() { + assertThat(new Solution().rob(new int[] {5}), equalTo(5)); + } + + @Test + void rob4() { + assertThat(new Solution().rob(new int[] {5, 10}), equalTo(10)); + } + + @Test + void rob5() { + assertThat(new Solution().rob(new int[] {2, 1, 1, 2}), equalTo(4)); + } + + @Test + void rob6() { + assertThat(new Solution().rob(new int[] {3, 3, 3, 3, 3}), equalTo(9)); + } + + @Test + void rob7() { + assertThat(new Solution().rob(new int[] {100, 1, 100, 1, 100}), equalTo(300)); + } + + @Test + void rob8() { + assertThat(new Solution().rob(new int[] {}), equalTo(0)); + } } diff --git a/src/test/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueueTest.java b/src/test/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueueTest.java index 85dc37981..b01834e78 100644 --- a/src/test/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueueTest.java +++ b/src/test/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueueTest.java @@ -15,4 +15,66 @@ void queueUsingStacks() { assertThat(myQueue.pop(), equalTo(1)); assertThat(myQueue.empty(), equalTo(false)); } + + @Test + void queuePushPopPeekMultiple() { + MyQueue myQueue = new MyQueue(); + myQueue.push(10); + myQueue.push(20); + myQueue.push(30); + + assertThat(myQueue.peek(), equalTo(10)); + assertThat(myQueue.pop(), equalTo(10)); + assertThat(myQueue.peek(), equalTo(20)); + assertThat(myQueue.pop(), equalTo(20)); + assertThat(myQueue.peek(), equalTo(30)); + assertThat(myQueue.pop(), equalTo(30)); + assertThat(myQueue.empty(), equalTo(true)); + } + + @Test + void queueEmptyInitially() { + MyQueue myQueue = new MyQueue(); + assertThat(myQueue.empty(), equalTo(true)); + } + + @Test + void queuePushAfterPopAll() { + MyQueue myQueue = new MyQueue(); + myQueue.push(1); + myQueue.push(2); + assertThat(myQueue.pop(), equalTo(1)); + assertThat(myQueue.pop(), equalTo(2)); + assertThat(myQueue.empty(), equalTo(true)); + + myQueue.push(3); + assertThat(myQueue.peek(), equalTo(3)); + assertThat(myQueue.empty(), equalTo(false)); + } + + @Test + void queuePeekDoesNotRemove() { + MyQueue myQueue = new MyQueue(); + myQueue.push(5); + myQueue.push(6); + assertThat(myQueue.peek(), equalTo(5)); + assertThat(myQueue.peek(), equalTo(5)); + assertThat(myQueue.pop(), equalTo(5)); + assertThat(myQueue.peek(), equalTo(6)); + } + + @Test + void pushAfterPopTriggersRightToLeft() { + MyQueue myQueue = new MyQueue(); + myQueue.push(1); + myQueue.push(2); + + assertThat(myQueue.pop(), equalTo(1)); + + myQueue.push(3); + + assertThat(myQueue.pop(), equalTo(2)); + assertThat(myQueue.pop(), equalTo(3)); + assertThat(myQueue.empty(), equalTo(true)); + } } diff --git a/src/test/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/SolutionTest.java b/src/test/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/SolutionTest.java index b65454b98..97898f451 100644 --- a/src/test/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/SolutionTest.java +++ b/src/test/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/SolutionTest.java @@ -42,4 +42,36 @@ void lowestCommonAncestor3() { .val, equalTo(2)); } + + @Test + void lowestCommonAncestor4() { + TreeNode root = new TreeNode(1); + assertThat( + new Solution().lowestCommonAncestor(root, new TreeNode(1), new TreeNode(1)).val, + equalTo(1)); + } + + @Test + void lowestCommonAncestor5() { + TreeNode root = new TreeNode(3, new TreeNode(1), new TreeNode(4)); + assertThat( + new Solution().lowestCommonAncestor(root, new TreeNode(1), new TreeNode(1)).val, + equalTo(1)); + } + + @Test + void lowestCommonAncestor6() { + TreeNode root = new TreeNode(3, new TreeNode(1), new TreeNode(4)); + assertThat( + new Solution().lowestCommonAncestor(root, new TreeNode(4), new TreeNode(4)).val, + equalTo(4)); + } + + @Test + void lowestCommonAncestor7() { + TreeNode root = new TreeNode(5, new TreeNode(3), new TreeNode(8)); + assertThat( + new Solution().lowestCommonAncestor(root, new TreeNode(3), new TreeNode(8)).val, + equalTo(5)); + } } diff --git a/src/test/java/g2901_3000/s2929_distribute_candies_among_children_ii/SolutionTest.java b/src/test/java/g2901_3000/s2929_distribute_candies_among_children_ii/SolutionTest.java index c94367e2f..064b00426 100644 --- a/src/test/java/g2901_3000/s2929_distribute_candies_among_children_ii/SolutionTest.java +++ b/src/test/java/g2901_3000/s2929_distribute_candies_among_children_ii/SolutionTest.java @@ -15,4 +15,39 @@ void distributeCandies() { void distributeCandies2() { assertThat(new Solution().distributeCandies(3, 3), equalTo(10L)); } + + @Test + void distributeCandies3() { + assertThat(new Solution().distributeCandies(2, 5), equalTo(6L)); + } + + @Test + void distributeCandies4() { + assertThat(new Solution().distributeCandies(4, 4), equalTo(15L)); + } + + @Test + void distributeCandies5() { + assertThat(new Solution().distributeCandies(7, 5), equalTo(27L)); + } + + @Test + void distributeCandies6() { + assertThat(new Solution().distributeCandies(12, 5), equalTo(10L)); + } + + @Test + void distributeCandies7() { + assertThat(new Solution().distributeCandies(20, 5), equalTo(0L)); + } + + @Test + void distributeCandies8() { + assertThat(new Solution().distributeCandies(10, 5), equalTo(21L)); + } + + @Test + void distributeCandies9() { + assertThat(new Solution().distributeCandies(15, 5), equalTo(1L)); + } } From b3273d753b570ec38bb1e7e672dace7c869e06e5 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Sun, 16 Nov 2025 14:49:36 +0700 Subject: [PATCH 16/21] Added tests for tasks 33-1036 --- .../SolutionTest.java | 60 +++++++++++++ .../MyCircularQueueTest.java | 74 ++++++++++++++++ .../SolutionTest.java | 68 +++++++++++++++ .../SolutionTest.java | 48 +++++++++++ .../SolutionTest.java | 84 +++++++++++++++++++ 5 files changed, 334 insertions(+) diff --git a/src/test/java/g0001_0100/s0033_search_in_rotated_sorted_array/SolutionTest.java b/src/test/java/g0001_0100/s0033_search_in_rotated_sorted_array/SolutionTest.java index bb8277bce..104eada21 100644 --- a/src/test/java/g0001_0100/s0033_search_in_rotated_sorted_array/SolutionTest.java +++ b/src/test/java/g0001_0100/s0033_search_in_rotated_sorted_array/SolutionTest.java @@ -20,4 +20,64 @@ void search2() { void search3() { assertThat(new Solution().search(new int[] {1}, 0), equalTo(-1)); } + + @Test + void search4() { + assertThat(new Solution().search(new int[] {1, 2, 3, 4, 5, 6}, 4), equalTo(3)); + } + + @Test + void search5() { + assertThat(new Solution().search(new int[] {1, 2, 3, 4, 5, 6}, 10), equalTo(-1)); + } + + @Test + void search6() { + assertThat(new Solution().search(new int[] {6, 7, 0, 1, 2, 3, 4}, 7), equalTo(1)); + } + + @Test + void search7() { + assertThat(new Solution().search(new int[] {6, 7, 0, 1, 2, 3, 4}, 3), equalTo(5)); + } + + @Test + void search8() { + assertThat(new Solution().search(new int[] {5, 1}, 1), equalTo(1)); + } + + @Test + void search9() { + assertThat(new Solution().search(new int[] {5, 1}, 2), equalTo(-1)); + } + + @Test + void search10() { + assertThat(new Solution().search(new int[] {4, 5, 6, 7, 0, 1, 2}, 4), equalTo(0)); + } + + @Test + void search11() { + assertThat(new Solution().search(new int[] {4, 5, 6, 7, 0, 1, 2}, 2), equalTo(6)); + } + + @Test + void search12() { + assertThat(new Solution().search(new int[] {2, 3, 4, 5, 6, 0, 1}, 0), equalTo(5)); + } + + @Test + void search13() { + assertThat(new Solution().search(new int[] {0, 1, 2, 3, 4, 5}, 3), equalTo(3)); + } + + @Test + void search14() { + assertThat(new Solution().search(new int[] {5, 6, 7, 0, 1, 2, 3}, 2), equalTo(5)); + } + + @Test + void search15() { + assertThat(new Solution().search(new int[] {5, 6, 7, 0, 1, 2, 3}, 6), equalTo(1)); + } } diff --git a/src/test/java/g0601_0700/s0622_design_circular_queue/MyCircularQueueTest.java b/src/test/java/g0601_0700/s0622_design_circular_queue/MyCircularQueueTest.java index d9e815813..2a36181a4 100644 --- a/src/test/java/g0601_0700/s0622_design_circular_queue/MyCircularQueueTest.java +++ b/src/test/java/g0601_0700/s0622_design_circular_queue/MyCircularQueueTest.java @@ -19,4 +19,78 @@ void myCircularQueue() { assertThat(myCircularQueue.enQueue(4), equalTo(true)); assertThat(myCircularQueue.rear(), equalTo(4)); } + + @Test + void myCircularQueue2() { + MyCircularQueue q = new MyCircularQueue(3); + assertThat(q.enQueue(1), equalTo(true)); + assertThat(q.enQueue(2), equalTo(true)); + assertThat(q.enQueue(3), equalTo(true)); + assertThat(q.enQueue(4), equalTo(false)); + assertThat(q.rear(), equalTo(3)); + assertThat(q.isFull(), equalTo(true)); + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.enQueue(4), equalTo(true)); + assertThat(q.rear(), equalTo(4)); + } + + @Test + void myCircularQueue3() { + MyCircularQueue q = new MyCircularQueue(2); + assertThat(q.front(), equalTo(-1)); + assertThat(q.rear(), equalTo(-1)); + assertThat(q.deQueue(), equalTo(false)); + assertThat(q.isEmpty(), equalTo(true)); + } + + @Test + void myCircularQueue4() { + MyCircularQueue q = new MyCircularQueue(1); + assertThat(q.enQueue(10), equalTo(true)); + assertThat(q.isFull(), equalTo(true)); + assertThat(q.front(), equalTo(10)); + assertThat(q.rear(), equalTo(10)); + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.isEmpty(), equalTo(true)); + assertThat(q.front(), equalTo(-1)); + assertThat(q.rear(), equalTo(-1)); + } + + @Test + void myCircularQueue5() { + MyCircularQueue q = new MyCircularQueue(3); + + assertThat(q.enQueue(1), equalTo(true)); + assertThat(q.enQueue(2), equalTo(true)); + assertThat(q.enQueue(3), equalTo(true)); + assertThat(q.isFull(), equalTo(true)); + + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.enQueue(4), equalTo(true)); + + assertThat(q.front(), equalTo(2)); + assertThat(q.rear(), equalTo(4)); + + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.deQueue(), equalTo(false)); + } + + @Test + void myCircularQueue6() { + MyCircularQueue q = new MyCircularQueue(2); + + assertThat(q.enQueue(5), equalTo(true)); + assertThat(q.enQueue(6), equalTo(true)); + assertThat(q.isFull(), equalTo(true)); + + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.deQueue(), equalTo(true)); + assertThat(q.isEmpty(), equalTo(true)); + + assertThat(q.enQueue(7), equalTo(true)); + assertThat(q.front(), equalTo(7)); + assertThat(q.rear(), equalTo(7)); + } } diff --git a/src/test/java/g0701_0800/s0782_transform_to_chessboard/SolutionTest.java b/src/test/java/g0701_0800/s0782_transform_to_chessboard/SolutionTest.java index 673c0c107..fc5111612 100644 --- a/src/test/java/g0701_0800/s0782_transform_to_chessboard/SolutionTest.java +++ b/src/test/java/g0701_0800/s0782_transform_to_chessboard/SolutionTest.java @@ -26,4 +26,72 @@ void movesToChessboard2() { void movesToChessboard3() { assertThat(new Solution().movesToChessboard(new int[][] {{1, 0}, {1, 0}}), equalTo(-1)); } + + @Test + void movesToChessboard4() { + assertThat( + new Solution() + .movesToChessboard( + new int[][] { + {0, 0}, + {0, 1} + }), + equalTo(-1)); + } + + @Test + void movesToChessboard5() { + assertThat( + new Solution() + .movesToChessboard( + new int[][] { + {1, 1}, + {1, 1} + }), + equalTo(-1)); + } + + @Test + void movesToChessboard6() { + assertThat( + new Solution() + .movesToChessboard( + new int[][] { + {1, 0}, + {1, 0} + }), + equalTo(-1)); + } + + @Test + void movesToChessboard7() { + assertThat( + new Solution() + .movesToChessboard( + new int[][] { + {1, 0, 1}, + {0, 1, 0}, + {1, 0, 1} + }), + equalTo(0)); + } + + @Test + void movesToChessboard8() { + assertThat( + new Solution() + .movesToChessboard( + new int[][] { + {1, 0, 0, 1}, + {0, 1, 1, 0}, + {1, 0, 0, 1}, + {0, 1, 1, 0} + }), + equalTo(1)); + } + + @Test + void movesToChessboard9() { + assertThat(new Solution().movesToChessboard(new int[][] {{0}}), equalTo(0)); + } } diff --git a/src/test/java/g0901_1000/s0972_equal_rational_numbers/SolutionTest.java b/src/test/java/g0901_1000/s0972_equal_rational_numbers/SolutionTest.java index 367de04ae..e7f446c24 100644 --- a/src/test/java/g0901_1000/s0972_equal_rational_numbers/SolutionTest.java +++ b/src/test/java/g0901_1000/s0972_equal_rational_numbers/SolutionTest.java @@ -20,4 +20,52 @@ void isRationalEqual2() { void isRationalEqual3() { assertThat(new Solution().isRationalEqual("0.9(9)", "1."), equalTo(true)); } + + @Test + void isRationalEqual4() { + assertThat(new Solution().isRationalEqual("3.14", "3.14"), equalTo(true)); + } + + @Test + void isRationalEqual5() { + assertThat(new Solution().isRationalEqual("3.14", "3.15"), equalTo(false)); + } + + @Test + void isRationalEqual6() { + // 0.(3) = 0.3333... + assertThat(new Solution().isRationalEqual("0.(3)", "0.3333333333"), equalTo(false)); + } + + @Test + void isRationalEqual7() { + assertThat(new Solution().isRationalEqual("0.(12)", "0.(13)"), equalTo(false)); + } + + @Test + void isRationalEqual8() { + // 1.(0) = 1.00000.... + assertThat(new Solution().isRationalEqual("1.(0)", "1."), equalTo(true)); + } + + @Test + void isRationalEqual9() { + // large repeating cycle + assertThat(new Solution().isRationalEqual("0.(987654321)", "0.(987654321)"), equalTo(true)); + } + + @Test + void isRationalEqual10() { + assertThat(new Solution().isRationalEqual("42", "42"), equalTo(true)); + } + + @Test + void isRationalEqual11() { + assertThat(new Solution().isRationalEqual("42", "42.0"), equalTo(true)); + } + + @Test + void isRationalEqual12() { + assertThat(new Solution().isRationalEqual("0.(1)", "0.(2)"), equalTo(false)); + } } diff --git a/src/test/java/g1001_1100/s1036_escape_a_large_maze/SolutionTest.java b/src/test/java/g1001_1100/s1036_escape_a_large_maze/SolutionTest.java index 9e201430c..85a29249a 100644 --- a/src/test/java/g1001_1100/s1036_escape_a_large_maze/SolutionTest.java +++ b/src/test/java/g1001_1100/s1036_escape_a_large_maze/SolutionTest.java @@ -23,4 +23,88 @@ void isEscapePossible2() { new int[][] {}, new int[] {0, 0}, new int[] {999999, 999999}), equalTo(true)); } + + @Test + void isEscapePossible3() { + assertThat( + new Solution() + .isEscapePossible(new int[][] {{1, 1}}, new int[] {0, 0}, new int[] {1, 1}), + equalTo(true)); + } + + @Test + void isEscapePossible4() { + assertThat( + new Solution() + .isEscapePossible( + new int[][] {{10, 10}}, new int[] {0, 0}, new int[] {0, 1}), + equalTo(true)); + } + + @Test + void isEscapePossible5() { + assertThat( + new Solution() + .isEscapePossible( + new int[][] {{0, 2}, {1, 2}, {2, 2}}, + new int[] {0, 0}, + new int[] {3, 3}), + equalTo(true)); + } + + @Test + void isEscapePossible6() { + assertThat( + new Solution() + .isEscapePossible( + new int[][] {{0, 1}, {0, 2}, {1, 0}, {2, 0}}, + new int[] {0, 0}, + new int[] {3, 3}), + equalTo(false)); + } + + @Test + void isEscapePossible7() { + assertThat( + new Solution() + .isEscapePossible( + new int[][] {{999998, 999999}, {999999, 999998}}, + new int[] {999999, 999999}, + new int[] {0, 0}), + equalTo(false)); + } + + @Test + void isEscapePossible8() { + assertThat( + new Solution() + .isEscapePossible( + new int[][] {{5, 5}, {5, 6}, {6, 5}}, + new int[] {5, 7}, + new int[] {6, 6}), + equalTo(true)); + } + + @Test + void isEscapePossible9() { + assertThat( + new Solution() + .isEscapePossible(new int[][] {{1, 2}}, new int[] {2, 2}, new int[] {2, 2}), + equalTo(true)); + } + + @Test + void isEscapePossible10() { + assertThat( + new Solution().isEscapePossible(new int[][] {}, new int[] {0, 0}, new int[] {0, 1}), + equalTo(true)); + } + + @Test + void isEscapePossible11() { + assertThat( + new Solution() + .isEscapePossible(new int[][] {{2, 2}}, new int[] {2, 1}, new int[] {2, 2}), + equalTo(true)); + } } From 217ecc4f8fc461b20f0c056ab8276cbb71f54243 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Nov 2025 03:22:37 +0200 Subject: [PATCH 17/21] Bump org.apache.maven.plugins:maven-jar-plugin from 3.4.2 to 3.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d1374da52..a0c540658 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.4.2 + 3.5.0 From 94668677aa4431a655bf43843af2d47edbe347e9 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Tue, 18 Nov 2025 23:11:35 +0700 Subject: [PATCH 18/21] Added tests for tasks 8-3548 --- .../SolutionTest.java | 60 +++++++++++++++++++ .../SolutionTest.java | 34 +++++++++++ .../SolutionTest.java | 50 ++++++++++++++++ .../SolutionTest.java | 40 +++++++++++++ .../SolutionTest.java | 57 ++++++++++++++++++ 5 files changed, 241 insertions(+) diff --git a/src/test/java/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.java b/src/test/java/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.java index 23df3d4e9..9e9094e6d 100644 --- a/src/test/java/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.java +++ b/src/test/java/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.java @@ -30,4 +30,64 @@ void myAtoi4() { void myAtoi5() { assertThat(new Solution().myAtoi("-91283472332"), equalTo(-2147483648)); } + + @Test + void myAtoi6() { + assertThat(new Solution().myAtoi("123"), equalTo(123)); + } + + @Test + void myAtoi7() { + assertThat(new Solution().myAtoi("+456"), equalTo(456)); + } + + @Test + void myAtoi8() { + assertThat(new Solution().myAtoi("0000123"), equalTo(123)); + } + + @Test + void myAtoi9() { + assertThat(new Solution().myAtoi("2147483648"), equalTo(Integer.MAX_VALUE)); + } + + @Test + void myAtoi10() { + assertThat(new Solution().myAtoi("-2147483649"), equalTo(Integer.MIN_VALUE)); + } + + @Test + void myAtoi11() { + assertThat(new Solution().myAtoi(""), equalTo(0)); + } + + @Test + void myAtoi12() { + assertThat(new Solution().myAtoi(" "), equalTo(0)); + } + + @Test + void myAtoi13() { + assertThat(new Solution().myAtoi("+-2"), equalTo(0)); + } + + @Test + void myAtoi14() { + assertThat(new Solution().myAtoi("0"), equalTo(0)); + } + + @Test + void myAtoi15() { + assertThat(new Solution().myAtoi("-0"), equalTo(0)); + } + + @Test + void myAtoi16() { + assertThat(new Solution().myAtoi("words 123"), equalTo(0)); + } + + @Test + void myAtoi17() { + assertThat(new Solution().myAtoi(" 0000000000012345678abc"), equalTo(12345678)); + } } diff --git a/src/test/java/g1101_1200/s1184_distance_between_bus_stops/SolutionTest.java b/src/test/java/g1101_1200/s1184_distance_between_bus_stops/SolutionTest.java index 45bb554fb..30a080334 100644 --- a/src/test/java/g1101_1200/s1184_distance_between_bus_stops/SolutionTest.java +++ b/src/test/java/g1101_1200/s1184_distance_between_bus_stops/SolutionTest.java @@ -23,4 +23,38 @@ void distanceBetweenBusStops3() { assertThat( new Solution().distanceBetweenBusStops(new int[] {1, 2, 3, 4}, 0, 3), equalTo(4)); } + + @Test + void distanceBetweenBusStops4() { + assertThat( + new Solution().distanceBetweenBusStops(new int[] {1, 2, 3, 4}, 3, 1), equalTo(5)); + } + + @Test + void distanceBetweenBusStops5() { + assertThat( + new Solution().distanceBetweenBusStops(new int[] {7, 1, 2, 3}, 1, 3), equalTo(3)); + } + + @Test + void distanceBetweenBusStops6() { + assertThat( + new Solution().distanceBetweenBusStops(new int[] {2, 2, 2, 2}, 1, 3), equalTo(4)); + } + + @Test + void distanceBetweenBusStops7() { + assertThat(new Solution().distanceBetweenBusStops(new int[] {5}, 0, 0), equalTo(0)); + } + + @Test + void distanceBetweenBusStops8() { + assertThat(new Solution().distanceBetweenBusStops(new int[] {3, 8}, 1, 0), equalTo(3)); + } + + @Test + void distanceBetweenBusStops9() { + assertThat( + new Solution().distanceBetweenBusStops(new int[] {1, 4, 6, 3}, 2, 1), equalTo(4)); + } } diff --git a/src/test/java/g1801_1900/s1882_process_tasks_using_servers/SolutionTest.java b/src/test/java/g1801_1900/s1882_process_tasks_using_servers/SolutionTest.java index f704b3df4..a9deb9015 100644 --- a/src/test/java/g1801_1900/s1882_process_tasks_using_servers/SolutionTest.java +++ b/src/test/java/g1801_1900/s1882_process_tasks_using_servers/SolutionTest.java @@ -20,4 +20,54 @@ void assignTasks2() { .assignTasks(new int[] {5, 1, 4, 3, 2}, new int[] {2, 1, 2, 4, 5, 2, 1}), equalTo(new int[] {1, 4, 1, 4, 1, 3, 2})); } + + @Test + void assignTasks3() { + assertThat( + new Solution().assignTasks(new int[] {1}, new int[] {1, 2, 3}), + equalTo(new int[] {0, 0, 0})); + } + + @Test + void assignTasks4() { + assertThat( + new Solution().assignTasks(new int[] {2, 2, 2}, new int[] {1, 2, 1, 2}), + equalTo(new int[] {0, 0, 1, 0})); + } + + @Test + void assignTasks5() { + assertThat( + new Solution().assignTasks(new int[] {1, 2}, new int[] {1, 2, 3, 4}), + equalTo(new int[] {0, 0, 1, 0})); + } + + @Test + void assignTasks6() { + assertThat( + new Solution().assignTasks(new int[] {1, 2, 3}, new int[] {}), + equalTo(new int[] {})); + } + + @Test + void assignTasks7() { + assertThat( + new Solution().assignTasks(new int[] {3, 1, 4}, new int[] {5}), + equalTo(new int[] {1})); + } + + @Test + void assignTasks8() { + assertThat( + new Solution().assignTasks(new int[] {1, 2}, new int[] {2, 2, 2}), + equalTo(new int[] {0, 1, 0})); + } + + @Test + void assignTasks9() { + int[] servers = {5, 3, 1, 4, 2}; + int[] tasks = {1, 3, 5, 7, 9, 11}; + assertThat( + new Solution().assignTasks(servers, tasks), equalTo(new int[] {2, 2, 4, 1, 2, 3})); + } } diff --git a/src/test/java/g2501_2600/s2600_k_items_with_the_maximum_sum/SolutionTest.java b/src/test/java/g2501_2600/s2600_k_items_with_the_maximum_sum/SolutionTest.java index f735049b8..924f93ffb 100644 --- a/src/test/java/g2501_2600/s2600_k_items_with_the_maximum_sum/SolutionTest.java +++ b/src/test/java/g2501_2600/s2600_k_items_with_the_maximum_sum/SolutionTest.java @@ -15,4 +15,44 @@ void kItemsWithMaximumSum() { void kItemsWithMaximumSum2() { assertThat(new Solution().kItemsWithMaximumSum(3, 2, 0, 4), equalTo(3)); } + + @Test + void kItemsWithMaximumSum3() { + assertThat(new Solution().kItemsWithMaximumSum(5, 3, 2, 5), equalTo(5)); + } + + @Test + void kItemsWithMaximumSum4() { + assertThat(new Solution().kItemsWithMaximumSum(3, 4, 5, 7), equalTo(3)); + } + + @Test + void kItemsWithMaximumSum5() { + assertThat(new Solution().kItemsWithMaximumSum(3, 1, 5, 6), equalTo(1)); + } + + @Test + void kItemsWithMaximumSum6() { + assertThat(new Solution().kItemsWithMaximumSum(2, 1, 10, 13), equalTo(-8)); + } + + @Test + void kItemsWithMaximumSum7() { + assertThat(new Solution().kItemsWithMaximumSum(0, 5, 5, 3), equalTo(0)); + } + + @Test + void kItemsWithMaximumSum8() { + assertThat(new Solution().kItemsWithMaximumSum(2, 0, 5, 3), equalTo(1)); + } + + @Test + void kItemsWithMaximumSum9() { + assertThat(new Solution().kItemsWithMaximumSum(4, 3, 0, 6), equalTo(4)); + } + + @Test + void kItemsWithMaximumSum10() { + assertThat(new Solution().kItemsWithMaximumSum(5, 5, 5, 0), equalTo(0)); + } } diff --git a/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java b/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java index a80e0c66f..c004147b2 100644 --- a/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java +++ b/src/test/java/g3501_3600/s3548_equal_sum_grid_partition_ii/SolutionTest.java @@ -139,4 +139,61 @@ void canPartitionGrid23() { new Solution().canPartitionGrid(new int[][] {{2, 2}, {2, 2}, {1, 1}}), equalTo(true)); } + + @Test + void canPartitionGrid24() { + Solution solution = new Solution(); + int[][] grid = { + {2, 1}, + {1, 1} + }; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid2325() { + Solution solution = new Solution(); + int[][] grid = {{1}, {2}, {1}}; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid26() { + Solution solution = new Solution(); + int[][] grid = { + {1, 2}, + {1, 1} + }; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid27() { + Solution solution = new Solution(); + int[][] grid = { + {1, 1, 2}, + {1, 1, 1} + }; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid28() { + Solution solution = new Solution(); + int[][] grid = { + {1, 1}, + {1, 1} + }; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } + + @Test + void canPartitionGrid29() { + Solution solution = new Solution(); + int[][] grid = { + {1, 2}, + {3, 4} + }; + assertThat(solution.canPartitionGrid(grid), equalTo(true)); + } } From 2d7360f471327480028728932d2808c99260ecd0 Mon Sep 17 00:00:00 2001 From: ThanhNIT <93962044+ThanhNIT@users.noreply.github.com> Date: Wed, 19 Nov 2025 22:56:41 +0700 Subject: [PATCH 19/21] Added tests for tasks 556-3142 --- .../SolutionTest.java | 65 ++++++++++ .../SolutionTest.java | 112 ++++++++++++++++++ .../s1185_day_of_the_week/SolutionTest.java | 65 ++++++++++ .../SolutionTest.java | 35 ++++++ .../SolutionTest.java | 71 +++++++++++ 5 files changed, 348 insertions(+) diff --git a/src/test/java/g0501_0600/s0556_next_greater_element_iii/SolutionTest.java b/src/test/java/g0501_0600/s0556_next_greater_element_iii/SolutionTest.java index a9d84d4e1..7e37c1d3f 100644 --- a/src/test/java/g0501_0600/s0556_next_greater_element_iii/SolutionTest.java +++ b/src/test/java/g0501_0600/s0556_next_greater_element_iii/SolutionTest.java @@ -15,4 +15,69 @@ void nextGreaterElement() { void nextGreaterElement2() { assertThat(new Solution().nextGreaterElement(21), equalTo(-1)); } + + @Test + void nextGreaterElement3() { + assertThat(new Solution().nextGreaterElement(1234), equalTo(1243)); + } + + @Test + void nextGreaterElement4() { + assertThat(new Solution().nextGreaterElement(4321), equalTo(-1)); + } + + @Test + void nextGreaterElement5() { + assertThat(new Solution().nextGreaterElement(115), equalTo(151)); + } + + @Test + void nextGreaterElement6() { + assertThat(new Solution().nextGreaterElement(111), equalTo(-1)); + } + + @Test + void nextGreaterElement7() { + assertThat(new Solution().nextGreaterElement(12443322), equalTo(13222344)); + } + + @Test + void nextGreaterElement8() { + assertThat(new Solution().nextGreaterElement(230241), equalTo(230412)); + } + + @Test + void nextGreaterElement9() { + assertThat(new Solution().nextGreaterElement(1999999999), equalTo(-1)); + } + + @Test + void nextGreaterElement10() { + assertThat(new Solution().nextGreaterElement(218765), equalTo(251678)); + } + + @Test + void nextGreaterElement11() { + assertThat(new Solution().nextGreaterElement(7), equalTo(-1)); + } + + @Test + void nextGreaterElement12() { + assertThat(new Solution().nextGreaterElement(132), equalTo(213)); + } + + @Test + void nextGreaterElement13() { + assertThat(new Solution().nextGreaterElement(534976), equalTo(536479)); + } + + @Test + void nextGreaterElement14() { + assertThat(new Solution().nextGreaterElement(1998), equalTo(8199)); + } + + @Test + void nextGreaterElement15() { + assertThat(new Solution().nextGreaterElement(2147483647), equalTo(-1)); + } } diff --git a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java index dfc7c1d31..87170fdc5 100644 --- a/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java +++ b/src/test/java/g0801_0900/s0840_magic_squares_in_grid/SolutionTest.java @@ -79,4 +79,116 @@ void numMagicSquaresInside7() { }), equalTo(0)); } + + @Test + void numMagicSquaresInside8() { + int[][] grid = { + {8, 1, 6}, + {3, 5, 7}, + {4, 9, 2} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(1)); + } + + @Test + void numMagicSquaresInside9() { + int[][] grid = { + {8, 1, 6, 8, 1, 6}, + {3, 5, 7, 3, 5, 7}, + {4, 9, 2, 4, 9, 2} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(2)); + } + + @Test + void numMagicSquaresInside10() { + int[][] grid = { + {8, 1, 6, 1}, + {3, 5, 7, 5}, + {4, 9, 2, 9}, + {8, 1, 6, 1} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(1)); + } + + @Test + void numMagicSquaresInside11() { + int[][] grid = { + {8, 1, 6}, + {3, 5, 7}, + {4, 9, 8} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside12() { + int[][] grid = { + {8, 1, 6}, + {3, 5, 20}, + {4, 9, 2} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside13() { + int[][] grid = { + {8, 1, 6}, + {3, 5, 7}, + {4, 2, 9} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside14() { + int[][] grid = { + {8, 1, 6}, + {3, 5, 7}, + {4, 9, 3} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside15() { + int[][] grid = { + {1, 2}, + {3, 4}, + {5, 6} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside16() { + int[][] grid = { + {1, 2, 3}, + {4, 5, 6} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside17() { + int[][] grid = { + {1, 2, 3, 8}, + {4, 5, 6, 1}, + {7, 8, 9, 6}, + {3, 5, 7, 7} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(0)); + } + + @Test + void numMagicSquaresInside18() { + int[][] grid = { + {8, 1, 6, 8}, + {3, 5, 7, 3}, + {4, 9, 2, 4}, + {8, 1, 6, 99} + }; + assertThat(new Solution().numMagicSquaresInside(grid), equalTo(1)); + } } diff --git a/src/test/java/g1101_1200/s1185_day_of_the_week/SolutionTest.java b/src/test/java/g1101_1200/s1185_day_of_the_week/SolutionTest.java index 27a6dd3e7..e3ced159b 100644 --- a/src/test/java/g1101_1200/s1185_day_of_the_week/SolutionTest.java +++ b/src/test/java/g1101_1200/s1185_day_of_the_week/SolutionTest.java @@ -20,4 +20,69 @@ void dayOfTheWeek2() { void dayOfTheWeek3() { assertThat(new Solution().dayOfTheWeek(15, 8, 1993), equalTo("Sunday")); } + + @Test + void dayOfTheWeek4() { + assertThat(new Solution().dayOfTheWeek(1, 1, 1971), equalTo("Friday")); + } + + @Test + void dayOfTheWeek5() { + assertThat(new Solution().dayOfTheWeek(29, 2, 2020), equalTo("Saturday")); + } + + @Test + void dayOfTheWeek6() { + assertThat(new Solution().dayOfTheWeek(1, 3, 2020), equalTo("Sunday")); + } + + @Test + void dayOfTheWeek7() { + assertThat(new Solution().dayOfTheWeek(28, 2, 2019), equalTo("Thursday")); + } + + @Test + void dayOfTheWeek8() { + assertThat(new Solution().dayOfTheWeek(31, 12, 1999), equalTo("Friday")); + } + + @Test + void dayOfTheWeek9() { + assertThat(new Solution().dayOfTheWeek(1, 1, 2001), equalTo("Monday")); + } + + @Test + void dayOfTheWeek10() { + assertThat(new Solution().dayOfTheWeek(1, 1, 2000), equalTo("Saturday")); + } + + @Test + void dayOfTheWeek11() { + assertThat(new Solution().dayOfTheWeek(1, 3, 1900), equalTo("Monday")); + } + + @Test + void dayOfTheWeek12() { + assertThat(new Solution().dayOfTheWeek(15, 6, 2024), equalTo("Saturday")); + } + + @Test + void dayOfTheWeek13() { + assertThat(new Solution().dayOfTheWeek(30, 11, 1985), equalTo("Saturday")); + } + + @Test + void dayOfTheWeek14() { + assertThat(new Solution().dayOfTheWeek(20, 4, 1975), equalTo("Sunday")); + } + + @Test + void dayOfTheWeek15() { + assertThat(new Solution().dayOfTheWeek(5, 1, 1971), equalTo("Tuesday")); + } + + @Test + void dayOfTheWeek16() { + assertThat(new Solution().dayOfTheWeek(6, 1, 1971), equalTo("Wednesday")); + } } diff --git a/src/test/java/g2401_2500/s2481_minimum_cuts_to_divide_a_circle/SolutionTest.java b/src/test/java/g2401_2500/s2481_minimum_cuts_to_divide_a_circle/SolutionTest.java index f85f88770..5a1dec378 100644 --- a/src/test/java/g2401_2500/s2481_minimum_cuts_to_divide_a_circle/SolutionTest.java +++ b/src/test/java/g2401_2500/s2481_minimum_cuts_to_divide_a_circle/SolutionTest.java @@ -15,4 +15,39 @@ void numberOfCuts() { void numberOfCuts2() { assertThat(new Solution().numberOfCuts(3), equalTo(3)); } + + @Test + void numberOfCuts3() { + assertThat(new Solution().numberOfCuts(1), equalTo(0)); + } + + @Test + void numberOfCuts4() { + assertThat(new Solution().numberOfCuts(6), equalTo(3)); + } + + @Test + void numberOfCuts5() { + assertThat(new Solution().numberOfCuts(5), equalTo(5)); + } + + @Test + void numberOfCuts6() { + assertThat(new Solution().numberOfCuts(100), equalTo(50)); + } + + @Test + void numberOfCuts7() { + assertThat(new Solution().numberOfCuts(101), equalTo(101)); + } + + @Test + void numberOfCuts8() { + assertThat(new Solution().numberOfCuts(2), equalTo(1)); + } + + @Test + void numberOfCuts9() { + assertThat(new Solution().numberOfCuts(3), equalTo(3)); + } } diff --git a/src/test/java/g3101_3200/s3142_check_if_grid_satisfies_conditions/SolutionTest.java b/src/test/java/g3101_3200/s3142_check_if_grid_satisfies_conditions/SolutionTest.java index 3a81d33d1..a3dd39635 100644 --- a/src/test/java/g3101_3200/s3142_check_if_grid_satisfies_conditions/SolutionTest.java +++ b/src/test/java/g3101_3200/s3142_check_if_grid_satisfies_conditions/SolutionTest.java @@ -19,4 +19,75 @@ void satisfiesConditions2() { new Solution().satisfiesConditions(new int[][] {{1, 1, 1}, {0, 0, 0}}), equalTo(false)); } + + @Test + void satisfiesConditions3() { + assertThat(new Solution().satisfiesConditions(new int[][] {{1}, {2}, {3}}), equalTo(false)); + } + + @Test + void satisfiesConditions4() { + assertThat(new Solution().satisfiesConditions(new int[][] {{1}, {1}}), equalTo(true)); + } + + @Test + void satisfiesConditions5() { + assertThat(new Solution().satisfiesConditions(new int[][] {{1, 2, 3}}), equalTo(true)); + } + + @Test + void satisfiesConditions6() { + assertThat(new Solution().satisfiesConditions(new int[][] {{1, 1}}), equalTo(false)); + } + + @Test + void satisfiesConditions7() { + assertThat( + new Solution().satisfiesConditions(new int[][] {{1, 2, 2}, {3, 4, 5}}), + equalTo(false)); + } + + @Test + void satisfiesConditions8() { + int[][] grid = { + {1, 0, 1}, + {0, 1, 0}, + {1, 0, 1} + }; + assertThat(new Solution().satisfiesConditions(grid), equalTo(false)); + } + + @Test + void satisfiesConditions9() { + assertThat(new Solution().satisfiesConditions(new int[][] {{5, 1}, {5, 0}}), equalTo(true)); + } + + @Test + void satisfiesConditions10() { + assertThat( + new Solution().satisfiesConditions(new int[][] {{1, 0}, {2, 2}}), equalTo(false)); + } + + @Test + void satisfiesConditions11() { + assertThat(new Solution().satisfiesConditions(new int[][] {{7}}), equalTo(true)); + } + + @Test + void satisfiesConditions12() { + int[][] grid = { + {4, 1, 5, 2}, + {3, 0, 4, 1} + }; + assertThat(new Solution().satisfiesConditions(grid), equalTo(false)); + } + + @Test + void satisfiesConditions13() { + int[][] grid = { + {2, 3, 3, 1}, + {1, 0, 4, 2} + }; + assertThat(new Solution().satisfiesConditions(grid), equalTo(false)); + } } From 268b52cb5cac1c7544fa3abb7cdf4030681de295 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Dec 2025 07:04:43 +0200 Subject: [PATCH 20/21] Bump org.apache.maven.plugins:maven-source-plugin from 3.3.1 to 3.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a0c540658..11e225a81 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.1 + 3.4.0 attach-sources From 5f9c5d66697b63700276bca2f35ea142b8c2cf73 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Tue, 9 Dec 2025 17:04:09 +0200 Subject: [PATCH 21/21] Gradle 9.2.1 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bad7c2462..23449a2b5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME