diff --git a/.circleci/config.yml b/.circleci/config.yml
index bcb41db63..b6c3379e9 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ jobs:
# Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/configuration-reference/#executor-job
docker:
- - image: cimg/openjdk:17.0.8
+ - image: cimg/openjdk:17.0.16
# Add steps to the job
# See: https://circleci.com/docs/configuration-reference/#steps
steps:
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 000000000..7af8a4f3d
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,11 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+ - package-ecosystem: "maven" # See documentation for possible values
+ directory: "/" # Location of package manifests
+ schedule:
+ interval: "weekly"
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
deleted file mode 100644
index bfe3b6e16..000000000
--- a/.github/workflows/codeql-analysis.yml
+++ /dev/null
@@ -1,79 +0,0 @@
-# For most projects, this workflow file will not need changing; you simply need
-# to commit it to your repository.
-#
-# You may wish to alter this file to override the set of languages analyzed,
-# or to provide custom queries or build logic.
-#
-# ******** NOTE ********
-# We have attempted to detect the languages in your repository. Please check
-# the `language` matrix defined below to confirm you have the correct set of
-# supported CodeQL languages.
-#
-name: "CodeQL"
-
-on:
- push:
- branches: [ main ]
- pull_request:
- # The branches below must be a subset of the branches above
- branches: [ main ]
- schedule:
- - cron: '20 2 * * 6'
-
-permissions: read-all
-jobs:
- analyze:
- name: Analyze
- runs-on: ubuntu-latest
- permissions:
- actions: read
- contents: read
- security-events: write
-
- strategy:
- fail-fast: false
- matrix:
- language: [ 'java' ]
- # CodeQL supports [ 'java' ]
- # Learn more:
- # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v3
-
- - name: Set up JDK 17
- uses: actions/setup-java@v3
- with:
- distribution: 'temurin'
- java-version: '17'
- cache: 'gradle'
-
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v2
- with:
- languages: ${{ matrix.language }}
- # If you wish to specify custom queries, you can do so here or in a config file.
- # By default, queries listed here will override any specified in a config file.
- # Prefix the list here with "+" to use these queries and those in the config file.
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v2
-
- # âšī¸ Command-line programs to run using the OS shell.
- # đ https://git.io/JvXDl
-
- # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines
- # and modify them (or add more) to build your code if your project
- # uses a compiled language
-
- #- run: |
- # make bootstrap
- # make release
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v2
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
new file mode 100644
index 000000000..3aa979cf9
--- /dev/null
+++ b/.github/workflows/codeql.yml
@@ -0,0 +1,96 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL Advanced"
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+ schedule:
+ - cron: '21 12 * * 1'
+
+jobs:
+ analyze:
+ name: Analyze (${{ matrix.language }})
+ # Runner size impacts CodeQL analysis time. To learn more, please see:
+ # - https://gh.io/recommended-hardware-resources-for-running-codeql
+ # - https://gh.io/supported-runners-and-hardware-resources
+ # - https://gh.io/using-larger-runners (GitHub.com only)
+ # Consider using larger runners or machines with greater resources for possible analysis time improvements.
+ runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
+ permissions:
+ # required for all workflows
+ security-events: write
+
+ # required to fetch internal or private CodeQL packs
+ packages: read
+
+ # only required for workflows in private repositories
+ actions: read
+ contents: read
+
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - language: java-kotlin
+ build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too.
+ - language: javascript-typescript
+ build-mode: none
+ - language: python
+ build-mode: none
+ # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
+ # Use `c-cpp` to analyze code written in C, C++ or both
+ # Use 'java-kotlin' to analyze code written in Java, Kotlin or both
+ # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
+ # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
+ # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
+ # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
+ # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v3
+ with:
+ languages: ${{ matrix.language }}
+ build-mode: ${{ matrix.build-mode }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+
+ # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+ # queries: security-extended,security-and-quality
+
+ # If the analyze step fails for one of the languages you are analyzing with
+ # "We were unable to automatically build your code", modify the matrix above
+ # to set the build mode to "manual" for that language. Then modify this step
+ # to build your code.
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
+ - if: matrix.build-mode == 'manual'
+ shell: bash
+ run: |
+ echo 'If you are using a "manual" build mode for one or more of the' \
+ 'languages you are analyzing, replace this with the commands to build' \
+ 'your code, for example:'
+ echo ' make bootstrap'
+ echo ' make release'
+ exit 1
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v3
+ with:
+ category: "/language:${{matrix.language}}"
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index e98405077..a27e8cc36 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -17,17 +17,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'corretto'
java-version: '17'
cache: 'gradle'
- name: Cache SonarCloud packages
- uses: actions/cache@v3
+ uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
@@ -44,13 +44,13 @@ jobs:
runs-on: windows-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'corretto'
java-version: '17'
cache: 'gradle'
- name: Build with Gradle
@@ -62,13 +62,13 @@ jobs:
runs-on: macOS-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'corretto'
java-version: '17'
cache: 'gradle'
- name: Build with Gradle
@@ -78,13 +78,13 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'corretto'
java-version: '17'
cache: 'maven'
- name: Build and analyze
diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml
deleted file mode 100644
index 355638527..000000000
--- a/.github/workflows/scorecard.yml
+++ /dev/null
@@ -1,72 +0,0 @@
-# This workflow uses actions that are not certified by GitHub. They are provided
-# by a third-party and are governed by separate terms of service, privacy
-# policy, and support documentation.
-
-name: Scorecard supply-chain security
-on:
- # For Branch-Protection check. Only the default branch is supported. See
- # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
- branch_protection_rule:
- # To guarantee Maintained check is occasionally updated. See
- # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
- schedule:
- - cron: '25 3 * * 4'
- push:
- branches: [ "main" ]
-
-# Declare default permissions as read only.
-permissions: read-all
-
-jobs:
- analysis:
- name: Scorecard analysis
- runs-on: ubuntu-latest
- permissions:
- # Needed to upload the results to code-scanning dashboard.
- security-events: write
- # Needed to publish results and get a badge (see publish_results below).
- id-token: write
- # Uncomment the permissions below if installing in a private repository.
- # contents: read
- # actions: read
-
- steps:
- - name: "Checkout code"
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- with:
- persist-credentials: false
-
- - name: "Run analysis"
- uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6
- with:
- results_file: results.sarif
- results_format: sarif
- # (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
- # - you want to enable the Branch-Protection check on a *public* repository, or
- # - you are installing Scorecard on a *private* repository
- # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
- # repo_token: ${{ secrets.SCORECARD_TOKEN }}
-
- # Public repositories:
- # - Publish results to OpenSSF REST API for easy access by consumers
- # - Allows the repository to include the Scorecard badge.
- # - See https://github.com/ossf/scorecard-action#publishing-results.
- # For private repositories:
- # - `publish_results` will always be set to `false`, regardless
- # of the value entered here.
- publish_results: true
-
- # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
- # format to the repository Actions tab.
- - name: "Upload artifact"
- uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
- with:
- name: SARIF file
- path: results.sarif
- retention-days: 5
-
- # Upload the results to GitHub's code scanning dashboard.
- - name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@807578363a7869ca324a79039e6db9c843e0e100 # v2.1.27
- with:
- sarif_file: results.sarif
diff --git a/LICENSE b/LICENSE
index 050d548f6..0a3041226 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2021-2023 Valentyn Kolesnikov
+Copyright (c) 2021-2025 Valentyn Kolesnikov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index e925c82ba..e67e978c8 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# LeetCode-in-Java
-[](https://central.sonatype.com/artifact/com.github.javadev/leetcode-in-java/1.27)
+[](https://central.sonatype.com/artifact/com.github.javadev/leetcode-in-java/1.49)
[ ](https://github.com/javadev/leetcode-in-java/blob/main/LICENSE)
[](https://github.com/javadev/LeetCode-in-Java/actions/workflows/maven.yml)
[](https://sonarcloud.io/summary/overall?id=javadev_LeetCode-in-Java)
@@ -19,7 +19,7 @@ To configure your Maven project, add the following code to your pom.xml file:
com.github.javadevleetcode-in-java
- 1.27
+ 1.49
...
@@ -28,1821 +28,2089 @@ To configure your Maven project, add the following code to your pom.xml file:
Gradle configuration:
```groovy
-implementation 'com.github.javadev:leetcode-in-java:1.27'
+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)
##
-* [Binary Search I](#binary-search-i)
-* [Binary Search II](#binary-search-ii)
-* [Dynamic Programming I](#dynamic-programming-i)
-* [Programming Skills I](#programming-skills-i)
-* [Programming Skills II](#programming-skills-ii)
-* [Graph Theory I](#graph-theory-i)
-* [SQL I](#sql-i)
* [Level 1](#level-1)
* [Level 2](#level-2)
* [Udemy](#udemy)
+* [Top Interview 150](#top-interview-150)
* [Data Structure I](#data-structure-i)
* [Data Structure II](#data-structure-ii)
* [Algorithm I](#algorithm-i)
* [Algorithm II](#algorithm-ii)
+* [Binary Search I](#binary-search-i)
+* [Binary Search II](#binary-search-ii)
+* [Dynamic Programming I](#dynamic-programming-i)
+* [Programming Skills I](#programming-skills-i)
+* [Programming Skills II](#programming-skills-ii)
+* [Graph Theory I](#graph-theory-i)
+* [SQL I](#sql-i)
-### Binary Search I
+### Level 1
-#### Day 1
+#### Day 1 Prefix Sum
| | | | | |
|-|-|-|-|-|-
-| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-| 0374 |[Guess Number Higher or Lower](src/main/java/g0301_0400/s0374_guess_number_higher_or_lower/Solution.java)| Easy | Binary_Search, Interactive | 0 | 100.00
+| 1480 |[Running Sum of 1d Array](src/main/java/g1401_1500/s1480_running_sum_of_1d_array/Solution.java)| Easy | Array, Prefix_Sum | 0 | 100.00
+| 0724 |[Find Pivot Index](src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java)| Easy | Array, Prefix_Sum, LeetCode_75_Prefix_Sum | 2 | 69.67
-#### Day 2
+#### Day 2 String
| | | | | |
|-|-|-|-|-|-
-| 0035 |[Search Insert Position](src/main/java/g0001_0100/s0035_search_insert_position/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-| 0852 |[Peak Index in a Mountain Array](src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0205 |[Isomorphic Strings](src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java)| Easy | String, Hash_Table | 2 | 99.18
+| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 1 | 93.13
-#### Day 3
+#### Day 3 Linked List
| | | | | |
|-|-|-|-|-|-
-| 0367 |[Valid Perfect Square](src/main/java/g0301_0400/s0367_valid_perfect_square/Solution.java)| Easy | Math, Binary_Search | 0 | 100.00
-| 1385 |[Find the Distance Value Between Two Arrays](src/main/java/g1301_1400/s1385_find_the_distance_value_between_two_arrays/Solution.java)| Easy | Array, Sorting, Binary_Search, Two_Pointers | 5 | 65.78
+| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
+| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-#### Day 4
+#### Day 4 Linked List
| | | | | |
|-|-|-|-|-|-
-| 0069 |[Sqrt(x)](src/main/java/g0001_0100/s0069_sqrtx/Solution.java)| Easy | Top_Interview_Questions, Math, Binary_Search | 1 | 99.51
-| 0744 |[Find Smallest Letter Greater Than Target](src/main/java/g0701_0800/s0744_find_smallest_letter_greater_than_target/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
+| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-#### Day 5
+#### Day 5 Greedy
| | | | | |
|-|-|-|-|-|-
-| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
-| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 99.78
+| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
-#### Day 6
+#### Day 6 Tree
| | | | | |
|-|-|-|-|-|-
-| 0441 |[Arranging Coins](src/main/java/g0401_0500/s0441_arranging_coins/Solution.java)| Easy | Math, Binary_Search | 2 | 95.97
-| 1539 |[Kth Missing Positive Number](src/main/java/g1501_1600/s1539_kth_missing_positive_number/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
+| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.19
-#### Day 7
+#### Day 7 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0167 |[Two Sum II - Input Array Is Sorted](src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers | 1 | 99.21
-| 1608 |[Special Array With X Elements Greater Than or Equal X](src/main/java/g1601_1700/s1608_special_array_with_x_elements_greater_than_or_equal_x/Solution.java)| Easy | Array, Sorting, Binary_Search | 2 | 61.14
+| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
-#### Day 8
+#### Day 8 Binary Search Tree
| | | | | |
|-|-|-|-|-|-
-| 1351 |[Count Negative Numbers in a Sorted Matrix](src/main/java/g1301_1400/s1351_count_negative_numbers_in_a_sorted_matrix/Solution.java)| Easy | Array, Binary_Search, Matrix | 1 | 49.66
-| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
-#### Day 9
+#### Day 9 Graph/BFS/DFS
| | | | | |
|-|-|-|-|-|-
-| 1337 |[The K Weakest Rows in a Matrix](src/main/java/g1301_1400/s1337_the_k_weakest_rows_in_a_matrix/Solution.java)| Easy | Array, Sorting, Binary_Search, Matrix, Heap_Priority_Queue | 1 | 99.77
-| 1346 |[Check If N and Its Double Exist](src/main/java/g1301_1400/s1346_check_if_n_and_its_double_exist/Solution.java)| Easy | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 1 | 99.64
+| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
+| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
-#### Day 10
+#### Day 10 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0350 |[Intersection of Two Arrays II](src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 4 | 69.62
-| 0633 |[Sum of Square Numbers](src/main/java/g0601_0700/s0633_sum_of_square_numbers/Solution.java)| Medium | Math, Binary_Search, Two_Pointers | 4 | 82.92
+| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
+| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-#### Day 11
+#### Day 11 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 1855 |[Maximum Distance Between a Pair of Values](src/main/java/g1801_1900/s1855_maximum_distance_between_a_pair_of_values/Solution.java)| Medium | Array, Greedy, Binary_Search, Two_Pointers | 4 | 62.20
-| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming, LeetCode_75_DP/1D | 1 | 86.38
+| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
-#### Day 12
+#### Day 12 Sliding Window/Two Pointer
| | | | | |
|-|-|-|-|-|-
-| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
-
-### Binary Search II
+| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 3 | 99.83
+| 0424 |[Longest Repeating Character Replacement](src/main/java/g0401_0500/s0424_longest_repeating_character_replacement/Solution.java)| Medium | String, Hash_Table, Sliding_Window | 5 | 95.15
-#### Day 1
+#### Day 13 Hashmap
| | | | | |
|-|-|-|-|-|-
-| 0209 |[Minimum Size Subarray Sum](src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 1 | 100.00
-| 0611 |[Valid Triangle Number](src/main/java/g0601_0700/s0611_valid_triangle_number/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 10 | 100.00
+| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 98.90
+| 0299 |[Bulls and Cows](src/main/java/g0201_0300/s0299_bulls_and_cows/Solution.java)| Medium | String, Hash_Table, Counting | 6 | 86.69
-#### Day 2
+#### Day 14 Stack
| | | | | |
|-|-|-|-|-|-
-| 0658 |[Find K Closest Elements](src/main/java/g0601_0700/s0658_find_k_closest_elements/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers, Heap_Priority_Queue | 3 | 99.20
-| 1894 |[Find the Student that Will Replace the Chalk](src/main/java/g1801_1900/s1894_find_the_student_that_will_replace_the_chalk/Solution.java)| Medium | Array, Binary_Search, Simulation, Prefix_Sum | 2 | 76.67
+| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
+| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-#### Day 3
+#### Day 15 Heap
| | | | | |
|-|-|-|-|-|-
-| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 98.63
-| 1760 |[Minimum Limit of Balls in a Bag](src/main/java/g1701_1800/s1760_minimum_limit_of_balls_in_a_bag/Solution.java)| Medium | Array, Binary_Search | 44 | 78.49
-
-#### Day 4
+| 1046 |[Last Stone Weight](src/main/java/g1001_1100/s1046_last_stone_weight/Solution.java)| Easy | Array, Heap_Priority_Queue | 2 | 73.81
+| 0692 |[Top K Frequent Words](src/main/java/g0601_0700/s0692_top_k_frequent_words/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 11 | 38.54
-| | | | | |
-|-|-|-|-|-|-
-| 0875 |[Koko Eating Bananas](src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java)| Medium | Array, Binary_Search | 15 | 91.32
-| 1552 |[Magnetic Force Between Two Balls](src/main/java/g1501_1600/s1552_magnetic_force_between_two_balls/Solution.java)| Medium | Array, Sorting, Binary_Search | 39 | 99.65
+### Level 2
-#### Day 5
+#### Day 1 Implementation/Simulation
| | | | | |
|-|-|-|-|-|-
-| 0287 |[Find the Duplicate Number](src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 2 | 99.82
-| 1283 |[Find the Smallest Divisor Given a Threshold](src/main/java/g1201_1300/s1283_find_the_smallest_divisor_given_a_threshold/Solution.java)| Medium | Array, Binary_Search | 9 | 95.49
+| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
+| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
+| 1706 |[Where Will the Ball Fall](src/main/java/g1701_1800/s1706_where_will_the_ball_fall/Solution.java)| Medium | Array, Dynamic_Programming, Depth_First_Search, Matrix, Simulation | 2 | 64.55
-#### Day 6
+#### Day 2 String
| | | | | |
|-|-|-|-|-|-
-| 1898 |[Maximum Number of Removable Characters](src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java)| Medium | Array, String, Binary_Search | 121 | 72.51
-| 1870 |[Minimum Speed to Arrive on Time](src/main/java/g1801_1900/s1870_minimum_speed_to_arrive_on_time/Solution.java)| Medium | Array, Binary_Search | 86 | 88.58
+| 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
+| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
-#### Day 7
+#### Day 3 Linked List
| | | | | |
|-|-|-|-|-|-
-| 1482 |[Minimum Number of Days to Make m Bouquets](src/main/java/g1401_1500/s1482_minimum_number_of_days_to_make_m_bouquets/Solution.java)| Medium | Array, Binary_Search | 25 | 69.18
-| 1818 |[Minimum Absolute Sum Difference](src/main/java/g1801_1900/s1818_minimum_absolute_sum_difference/Solution.java)| Medium | Array, Sorting, Binary_Search, Ordered_Set | 13 | 99.44
+| 0019 |[Remove Nth Node From End of List](src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
+| 0234 |[Palindrome Linked List](src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 4 | 84.46
-#### Day 8
+#### Day 4 Linked List
| | | | | |
|-|-|-|-|-|-
-| 0240 |[Search a 2D Matrix II](src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 7 | 86.73
-| 0275 |[H-Index II](src/main/java/g0201_0300/s0275_h_index_ii/Solution.java)| Medium | Array, Binary_Search | 0 | 100.00
+| 0328 |[Odd Even Linked List](src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java)| Medium | Linked_List, LeetCode_75_LinkedList | 0 | 100.00
+| 0148 |[Sort List](src/main/java/g0101_0200/s0148_sort_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 9 | 93.90
-#### Day 9
+#### Day 5 Greedy
| | | | | |
|-|-|-|-|-|-
-| 1838 |[Frequency of the Most Frequent Element](src/main/java/g1801_1900/s1838_frequency_of_the_most_frequent_element/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Prefix_Sum, Sliding_Window | 11 | 100.00
-| 0540 |[Single Element in a Sorted Array](src/main/java/g0501_0600/s0540_single_element_in_a_sorted_array/Solution.java)| Medium | Array, Binary_Search | 0 | 100.00
+| 2131 |[Longest Palindrome by Concatenating Two Letter Words](src/main/java/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words/Solution.java)| Medium | Array, String, Hash_Table, Greedy, Counting | 73 | 76.60
+| 0621 |[Task Scheduler](src/main/java/g0601_0700/s0621_task_scheduler/Solution.java)| Medium | Array, Hash_Table, Sorting, Greedy, Heap_Priority_Queue, Counting | 3 | 84.32
-#### Day 10
+#### Day 6 Tree
| | | | | |
|-|-|-|-|-|-
-| 0222 |[Count Complete Tree Nodes](src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Search, Binary_Tree | 0 | 100.00
-| 1712 |[Ways to Split Array Into Three Subarrays](src/main/java/g1701_1800/s1712_ways_to_split_array_into_three_subarrays/Solution.java)| Medium | Array, Binary_Search, Two_Pointers, Prefix_Sum | 16 | 84.24
+| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
-#### Day 11
+#### Day 7 Tree
| | | | | |
|-|-|-|-|-|-
-| 0826 |[Most Profit Assigning Work](src/main/java/g0801_0900/s0826_most_profit_assigning_work/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 21 | 83.83
-| 0436 |[Find Right Interval](src/main/java/g0401_0500/s0436_find_right_interval/Solution.java)| Medium | Array, Sorting, Binary_Search | 20 | 81.51
+| 0543 |[Diameter of Binary Tree](src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0437 |[Path Sum III](src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 2 | 100.00
-#### Day 12
+#### Day 8 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0081 |[Search in Rotated Sorted Array II](src/main/java/g0001_0100/s0081_search_in_rotated_sorted_array_ii/Solution.java)| Medium | Array, Binary_Search | 1 | 82.83
-| 0162 |[Find Peak Element](src/main/java/g0101_0200/s0162_find_peak_element/Solution.java)| Medium | Top_Interview_Questions, Array, Binary_Search | 0 | 100.00
+| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-#### Day 13
+#### Day 9 Binary Search Tree
| | | | | |
|-|-|-|-|-|-
-| 0154 |[Find Minimum in Rotated Sorted Array II](src/main/java/g0101_0200/s0154_find_minimum_in_rotated_sorted_array_ii/Solution.java)| Hard | Array, Binary_Search | 1 | 77.09
-| 0528 |[Random Pick with Weight](src/main/java/g0501_0600/s0528_random_pick_with_weight/Solution.java)| Medium | Math, Binary_Search, Prefix_Sum, Randomized | 42 | 50.90
+| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
+| 0230 |[Kth Smallest Element in a BST](src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 15 | 100.00
-#### Day 14
+#### Day 10 Graph/BFS/DFS
| | | | | |
|-|-|-|-|-|-
-| 1508 |[Range Sum of Sorted Subarray Sums](src/main/java/g1501_1600/s1508_range_sum_of_sorted_subarray_sums/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 60 | 93.84
-| 1574 |[Shortest Subarray to be Removed to Make Array Sorted](src/main/java/g1501_1600/s1574_shortest_subarray_to_be_removed_to_make_array_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers, Stack, Monotonic_Stack | 2 | 84.97
+| 0994 |[Rotting Oranges](src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java)| Medium | Top_100_Liked_Questions, Array, Breadth_First_Search, Matrix, LeetCode_75_Graphs/BFS | 3 | 74.27
+| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
-#### Day 15
+#### Day 11 Graph/BFS/DFS
| | | | | |
|-|-|-|-|-|-
-| 1292 |[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](src/main/java/g1201_1300/s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold/Solution.java)| Medium | Array, Binary_Search, Matrix, Prefix_Sum | 23 | 32.97
-| 1498 |[Number of Subsequences That Satisfy the Given Sum Condition](src/main/java/g1401_1500/s1498_number_of_subsequences_that_satisfy_the_given_sum_condition/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 27 | 99.13
+| 0210 |[Course Schedule II](src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 4 | 91.07
+| 0815 |[Bus Routes](src/main/java/g0801_0900/s0815_bus_routes/Solution.java)| Hard | Array, Hash_Table, Breadth_First_Search | 49 | 89.11
-#### Day 16
+#### Day 12 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0981 |[Time Based Key-Value Store](src/main/java/g0901_1000/s0981_time_based_key_value_store/TimeMap.java)| Medium | String, Hash_Table, Binary_Search, Design | 239 | 72.78
-| 1300 |[Sum of Mutated Array Closest to Target](src/main/java/g1201_1300/s1300_sum_of_mutated_array_closest_to_target/Solution.java)| Medium | Array, Sorting, Binary_Search | 7 | 33.33
+| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 12 | 92.59
-#### Day 17
+#### Day 13 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 1802 |[Maximum Value at a Given Index in a Bounded Array](src/main/java/g1801_1900/s1802_maximum_value_at_a_given_index_in_a_bounded_array/Solution.java)| Medium | Greedy, Binary_Search | 2 | 58.44
-| 1901 |[Find a Peak Element II](src/main/java/g1901_2000/s1901_find_a_peak_element_ii/Solution.java)| Medium | Array, Binary_Search, Matrix, Divide_and_Conquer | 0 | 100.00
+| 0416 |[Partition Equal Subset Sum](src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 5 | 99.88
+| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 92.74
-#### Day 18
+#### Day 14 Sliding Window/Two Pointer
| | | | | |
|-|-|-|-|-|-
-| 1146 |[Snapshot Array](src/main/java/g1101_1200/s1146_snapshot_array/SnapshotArray.java)| Medium | Array, Hash_Table, Binary_Search, Design | 68 | 45.86
-| 1488 |[Avoid Flood in The City](src/main/java/g1401_1500/s1488_avoid_flood_in_the_city/Solution.java)| Medium | Array, Hash_Table, Greedy, Binary_Search, Heap_Priority_Queue | 82 | 75.08
+| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 2 | 98.59
+| 0016 |[3Sum Closest](src/main/java/g0001_0100/s0016_3sum_closest/Solution.java)| Medium | Array, Sorting, Two_Pointers | 4 | 98.21
+| 0076 |[Minimum Window Substring](src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 2 | 99.83
-#### Day 19
+#### Day 15 Tree
| | | | | |
|-|-|-|-|-|-
-| 1562 |[Find Latest Group of Size M](src/main/java/g1501_1600/s1562_find_latest_group_of_size_m/Solution.java)| Medium | Array, Binary_Search, Simulation | 8 | 90.00
-| 1648 |[Sell Diminishing-Valued Colored Balls](src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java)| Medium | Array, Math, Sorting, Greedy, Binary_Search, Heap_Priority_Queue | 27 | 80.64
+| 0100 |[Same Tree](src/main/java/g0001_0100/s0100_same_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0101 |[Symmetric Tree](src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0199 |[Binary Tree Right Side View](src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00
-#### Day 20
+#### Day 16 Design
| | | | | |
|-|-|-|-|-|-
-| 1201 |[Ugly Number III](src/main/java/g1201_1300/s1201_ugly_number_iii/Solution.java)| Medium | Math, Binary_Search, Number_Theory | 0 | 100.00
-| 0911 |[Online Election](src/main/java/g0901_1000/s0911_online_election/TopVotedCandidate.java)| Medium | Array, Hash_Table, Binary_Search, Design | 63 | 98.81
-
-### Dynamic Programming I
+| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
+| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 4 | 96.54
+| 0208 |[Implement Trie (Prefix Tree)](src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 32 | 95.05
-#### Day 1
+#### Day 17 Interval
| | | | | |
|-|-|-|-|-|-
-| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
-| 1137 |[N-th Tribonacci Number](src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Memoization | 0 | 100.00
+| 0057 |[Insert Interval](src/main/java/g0001_0100/s0057_insert_interval/Solution.java)| Medium | Array | 0 | 100.00
+| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 98.37
-#### Day 2
+#### Day 18 Stack
| | | | | |
|-|-|-|-|-|-
-| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming | 1 | 86.38
+| 0735 |[Asteroid Collision](src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java)| Medium | Array, Stack, LeetCode_75_Stack | 2 | 99.59
+| 0227 |[Basic Calculator II](src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java)| Medium | String, Math, Stack | 8 | 95.32
-#### Day 3
+#### Day 19 Union Find
| | | | | |
|-|-|-|-|-|-
-| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
-| 0740 |[Delete and Earn](src/main/java/g0701_0800/s0740_delete_and_earn/Solution.java)| Medium | Array, Hash_Table, Dynamic_Programming | 4 | 77.68
+| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find, LeetCode_75_Graphs/DFS | 2 | 69.51
+| 0947 |[Most Stones Removed with Same Row or Column](src/main/java/g0901_1000/s0947_most_stones_removed_with_same_row_or_column/Solution.java)| Medium | Depth_First_Search, Graph, Union_Find | 7 | 98.83
-#### Day 4
+#### Day 20 Brute Force/Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 2 | 79.47
-| 0045 |[Jump Game II](src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 2 | 49.02
+| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 99.99
+| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 94.08
-#### Day 5
+### Udemy
+
+#### Udemy Integers
| | | | | |
|-|-|-|-|-|-
-| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
-| 0918 |[Maximum Sum Circular Subarray](src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 3 | 92.86
+| 0412 |[Fizz Buzz](src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java)| Easy | String, Math, Simulation | 1 | 100.00
+| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.86
+| 0007 |[Reverse Integer](src/main/java/g0001_0100/s0007_reverse_integer/Solution.java)| Medium | Top_Interview_Questions, Math, Big_O_Time_O(log10(x))_Space_O(1) | 0 | 100.00
+| 0009 |[Palindrome Number](src/main/java/g0001_0100/s0009_palindrome_number/Solution.java)| Easy | Math, Big_O_Time_O(log10(x))_Space_O(1) | 4 | 100.00
+| 0172 |[Factorial Trailing Zeroes](src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java)| Medium | Top_Interview_Questions, Math | 0 | 100.00
+| 0050 |[Pow(x, n)](src/main/java/g0001_0100/s0050_powx_n/Solution.java)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
-#### Day 6
+#### Udemy Strings
| | | | | |
|-|-|-|-|-|-
-| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 1567 |[Maximum Length of Subarray With Positive Product](src/main/java/g1501_1600/s1567_maximum_length_of_subarray_with_positive_product/Solution.java)| Medium | Array, Dynamic_Programming, Greedy | 4 | 80.86
+| 0344 |[Reverse String](src/main/java/g0301_0400/s0344_reverse_string/Solution.java)| Easy | String, Two_Pointers, Recursion | 1 | 99.91
+| 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
+| 0187 |[Repeated DNA Sequences](src/main/java/g0101_0200/s0187_repeated_dna_sequences/Solution.java)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash | 29 | 77.11
+| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 2 | 98.59
+| 0020 |[Valid Parentheses](src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 97.19
+| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.82
+| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, LeetCode_75_Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | String, Hash_Table, Sorting | 2 | 97.76
+| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 97.61
+| 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
+| 0273 |[Integer to English Words](src/main/java/g0201_0300/s0273_integer_to_english_words/Solution.java)| Hard | String, Math, Recursion | 3 | 95.67
-#### Day 7
+#### Udemy Binary Search
| | | | | |
|-|-|-|-|-|-
-| 1014 |[Best Sightseeing Pair](src/main/java/g1001_1100/s1014_best_sightseeing_pair/Solution.java)| Medium | Array, Dynamic_Programming | 2 | 99.86
-| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
-| 0122 |[Best Time to Buy and Sell Stock II](src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 1 | 96.82
+| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
-#### Day 8
+#### Udemy Arrays
| | | | | |
|-|-|-|-|-|-
-| 0309 |[Best Time to Buy and Sell Stock with Cooldown](src/main/java/g0301_0400/s0309_best_time_to_buy_and_sell_stock_with_cooldown/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
-| 0714 |[Best Time to Buy and Sell Stock with Transaction Fee](src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java)| Medium | Array, Dynamic_Programming, Greedy | 4 | 78.57
+| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 99.78
+| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 83.99
+| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 98.90
+| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
+| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java)| Easy | String | 0 | 100.00
+| 0605 |[Can Place Flowers](src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java)| Easy | Array, Greedy, LeetCode_75_Array/String | 1 | 96.77
+| 0122 |[Best Time to Buy and Sell Stock II](src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 1 | 76.91
+| 0080 |[Remove Duplicates from Sorted Array II](src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java)| Medium | Array, Two_Pointers | 0 | 100.00
+| 0189 |[Rotate Array](src/main/java/g0101_0200/s0189_rotate_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 0075 |[Sort Colors](src/main/java/g0001_0100/s0075_sort_colors/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0066 |[Plus One](src/main/java/g0001_0100/s0066_plus_one/Solution.java)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
+| 0238 |[Product of Array Except Self](src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 1 | 99.66
+| 1291 |[Sequential Digits](src/main/java/g1201_1300/s1291_sequential_digits/Solution.java)| Medium | Enumeration | 0 | 100.00
+| 0448 |[Find All Numbers Disappeared in an Array](src/main/java/g0401_0500/s0448_find_all_numbers_disappeared_in_an_array/Solution.java)| Easy | Array, Hash_Table | 3 | 100.00
+| 0442 |[Find All Duplicates in an Array](src/main/java/g0401_0500/s0442_find_all_duplicates_in_an_array/Solution.java)| Medium | Array, Hash_Table | 5 | 98.83
+| 0041 |[First Missing Positive](src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 100.00
+| 0697 |[Degree of an Array](src/main/java/g0601_0700/s0697_degree_of_an_array/Solution.java)| Easy | Array, Hash_Table | 14 | 93.19
+| 0532 |[K-diff Pairs in an Array](src/main/java/g0501_0600/s0532_k_diff_pairs_in_an_array/Solution.java)| Medium | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 13 | 58.23
+| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
+| 1007 |[Minimum Domino Rotations For Equal Row](src/main/java/g1001_1100/s1007_minimum_domino_rotations_for_equal_row/Solution.java)| Medium | Array, Greedy | 5 | 79.64
+| 1306 |[Jump Game III](src/main/java/g1301_1400/s1306_jump_game_iii/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search | 2 | 96.23
+| 0456 |[132 Pattern](src/main/java/g0401_0500/s0456_132_pattern/Solution.java)| Medium | Array, Binary_Search, Stack, Ordered_Set, Monotonic_Stack | 16 | 82.41
+| 0239 |[Sliding Window Maximum](src/main/java/g0201_0300/s0239_sliding_window_maximum/Solution.java)| Hard | Top_100_Liked_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Big_O_Time_O(n\*k)_Space_O(n+k) | 26 | 95.89
-#### Day 9
+#### Udemy Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 2 | 97.08
+| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 1 | 93.13
+| 0125 |[Valid Palindrome](src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers | 2 | 99.11
+| 0977 |[Squares of a Sorted Array](src/main/java/g0901_1000/s0977_squares_of_a_sorted_array/Solution.java)| Easy | Array, Sorting, Two_Pointers | 1 | 100.00
+| 0026 |[Remove Duplicates from Sorted Array](src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00
| 0042 |[Trapping Rain Water](src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 29 | 72.02
-#### Day 10
+#### Udemy Famous Algorithm
| | | | | |
|-|-|-|-|-|-
-| 0413 |[Arithmetic Slices](src/main/java/g0401_0500/s0413_arithmetic_slices/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
-| 0091 |[Decode Ways](src/main/java/g0001_0100/s0091_decode_ways/Solution.java)| Medium | Top_Interview_Questions, String, Dynamic_Programming | 2 | 66.37
+| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.32
+| 0169 |[Majority Element](src/main/java/g0101_0200/s0169_majority_element/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.89
-#### Day 11
+#### Udemy Sorting Algorithms
| | | | | |
|-|-|-|-|-|-
-| 0264 |[Ugly Number II](src/main/java/g0201_0300/s0264_ugly_number_ii/Solution.java)| Medium | Hash_Table, Dynamic_Programming, Math, Heap_Priority_Queue | 2 | 99.91
-| 0096 |[Unique Binary Search Trees](src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0912 |[Sort an Array](src/main/java/g0901_1000/s0912_sort_an_array/Solution.java)| Medium | Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Merge_Sort, Bucket_Sort, Counting_Sort, Radix_Sort | 25 | 38.15
-#### Day 12
+#### Udemy 2D Arrays/Matrix
| | | | | |
|-|-|-|-|-|-
-| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
-| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
+| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
+| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
+| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
+| 1572 |[Matrix Diagonal Sum](src/main/java/g1501_1600/s1572_matrix_diagonal_sum/Solution.java)| Easy | Array, Matrix | 0 | 100.00
+| 0073 |[Set Matrix Zeroes](src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 0 | 100.00
+| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 98.37
-#### Day 13
+#### Udemy Linked List
| | | | | |
|-|-|-|-|-|-
-| 0931 |[Minimum Falling Path Sum](src/main/java/g0901_1000/s0931_minimum_falling_path_sum/Solution.java)| Medium | Array, Dynamic_Programming, Matrix | 4 | 72.19
-| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 2 | 94.63
+| 0114 |[Flatten Binary Tree to Linked List](src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii/Solution.java)| Medium | Math, Stack, Linked_List | 3 | 90.38
+| 0328 |[Odd Even Linked List](src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java)| Medium | Linked_List, LeetCode_75_LinkedList | 0 | 100.00
+| 0061 |[Rotate List](src/main/java/g0001_0100/s0061_rotate_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0024 |[Swap Nodes in Pairs](src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
+| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0141 |[Linked List Cycle](src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
+| 0160 |[Intersection of Two Linked Lists](src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 1 | 99.92
+| 0234 |[Palindrome Linked List](src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 4 | 84.46
+| 0138 |[Copy List with Random Pointer](src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0025 |[Reverse Nodes in k-Group](src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
+| 0146 |[LRU Cache](src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 40 | 98.20
+| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
-#### Day 14
+#### Udemy Tree Stack Queue
| | | | | |
|-|-|-|-|-|-
-| 1314 |[Matrix Block Sum](src/main/java/g1301_1400/s1314_matrix_block_sum/Solution.java)| Medium | Array, Matrix, Prefix_Sum | 5 | 67.46
-| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
-
-#### Day 15
-
-| | | | | |
-|-|-|-|-|-|-
-| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
-| 0063 |[Unique Paths II](src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java)| Medium | Array, Dynamic_Programming, Matrix | 0 | 100.00
+| 0144 |[Binary Tree Preorder Traversal](src/main/java/g0101_0200/s0144_binary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 48.38
+| 0094 |[Binary Tree Inorder Traversal](src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0145 |[Binary Tree Postorder Traversal](src/main/java/g0101_0200/s0145_binary_tree_postorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 49.11
+| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.19
+| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
+| 1008 |[Construct Binary Search Tree from Preorder Traversal](src/main/java/g1001_1100/s1008_construct_binary_search_tree_from_preorder_traversal/Solution.java)| Medium | Array, Tree, Binary_Tree, Stack, Monotonic_Stack, Binary_Search_Tree | 0 | 100.00
+| 0543 |[Diameter of Binary Tree](src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0938 |[Range Sum of BST](src/main/java/g0901_1000/s0938_range_sum_of_bst/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
+| 0100 |[Same Tree](src/main/java/g0001_0100/s0100_same_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0111 |[Minimum Depth of Binary Tree](src/main/java/g0101_0200/s0111_minimum_depth_of_binary_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 97.49
+| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
+| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
+| 0701 |[Insert into a Binary Search Tree](src/main/java/g0701_0800/s0701_insert_into_a_binary_search_tree/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
+| 0297 |[Serialize and Deserialize Binary Tree](src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java)| Hard | String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design | 7 | 98.13
+| 0124 |[Binary Tree Maximum Path Sum](src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0337 |[House Robber III](src/main/java/g0301_0400/s0337_house_robber_iii/Solution.java)| Medium | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 1 | 91.77
+| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 6 | 100.00
+| 0968 |[Binary Tree Cameras](src/main/java/g0901_1000/s0968_binary_tree_cameras/Solution.java)| Hard | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 0 | 100.00
-#### Day 16
+#### Udemy Trie and Heap
| | | | | |
|-|-|-|-|-|-
-| 0064 |[Minimum Path Sum](src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
-| 0221 |[Maximal Square](src/main/java/g0201_0300/s0221_maximal_square/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 7 | 72.35
+| 0208 |[Implement Trie (Prefix Tree)](src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 32 | 95.05
+| 0745 |[Prefix and Suffix Search](src/main/java/g0701_0800/s0745_prefix_and_suffix_search/WordFilter.java)| Hard | String, Design, Trie | 366 | 76.15
-#### Day 17
+#### Udemy Graph
| | | | | |
|-|-|-|-|-|-
-| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.94
-| 0516 |[Longest Palindromic Subsequence](src/main/java/g0501_0600/s0516_longest_palindromic_subsequence/Solution.java)| Medium | String, Dynamic_Programming | 88 | 58.87
+| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
+| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 25 | 68.87
+| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
-#### Day 18
+#### Udemy Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 98.63
-| 0376 |[Wiggle Subsequence](src/main/java/g0301_0400/s0376_wiggle_subsequence/Solution.java)| Medium | Array, Dynamic_Programming, Greedy | 0 | 100.00
+| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 99.79
+| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
+| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
+| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 1 | 99.42
+| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 92.74
+| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
+| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0064 |[Minimum Path Sum](src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 99.73
+| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 95.75
+| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 19 | 89.05
+| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 3 | 97.19
+| 0044 |[Wildcard Matching](src/main/java/g0001_0100/s0044_wildcard_matching/Solution.java)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Greedy, Recursion | 2 | 99.87
+| 0010 |[Regular Expression Matching](src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 100.00
-#### Day 19
+#### Udemy Backtracking/Recursion
| | | | | |
|-|-|-|-|-|-
-| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers | 1 | 93.01
-| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 33 | 46.23
-| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 4 | 90.13
+| 0022 |[Generate Parentheses](src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
+| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 99.99
+| 0216 |[Combination Sum III](src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java)| Medium | Array, Backtracking, LeetCode_75_Backtracking | 1 | 81.35
+| 0078 |[Subsets](src/main/java/g0001_0100/s0078_subsets/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00
+| 0017 |[Letter Combinations of a Phone Number](src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
+| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 94.08
-#### Day 20
+#### Udemy Bit Manipulation
| | | | | |
|-|-|-|-|-|-
-| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 17 | 91.77
-| 0518 |[Coin Change 2](src/main/java/g0501_0600/s0518_coin_change_2/Solution.java)| Medium | Array, Dynamic_Programming | 4 | 84.67
+| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00
+| 0389 |[Find the Difference](src/main/java/g0301_0400/s0389_find_the_difference/Solution.java)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 1 | 100.00
+| 0190 |[Reverse Bits](src/main/java/g0101_0200/s0190_reverse_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 0 | 100.00
+| 0461 |[Hamming Distance](src/main/java/g0401_0500/s0461_hamming_distance/Solution.java)| Easy | Bit_Manipulation | 0 | 100.00
+| 1009 |[Complement of Base 10 Integer](src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java)| Easy | Bit_Manipulation | 1 | 41.56
+| 0338 |[Counting Bits](src/main/java/g0301_0400/s0338_counting_bits/Solution.java)| Easy | Dynamic_Programming, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 2 | 96.37
+| 0371 |[Sum of Two Integers](src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java)| Medium | Math, Bit_Manipulation | 0 | 100.00
+| 0029 |[Divide Two Integers](src/main/java/g0001_0100/s0029_divide_two_integers/Solution.java)| Medium | Top_Interview_Questions, Math, Bit_Manipulation | 1 | 97.44
-#### Day 21
+#### Udemy Design
| | | | | |
|-|-|-|-|-|-
-| 0377 |[Combination Sum IV](src/main/java/g0301_0400/s0377_combination_sum_iv/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 92.54
-| 0343 |[Integer Break](src/main/java/g0301_0400/s0343_integer_break/Solution.java)| Medium | Dynamic_Programming, Math | 0 | 100.00
-| 0279 |[Perfect Squares](src/main/java/g0201_0300/s0279_perfect_squares/Solution.java)| Medium | Top_Interview_Questions, Dynamic_Programming, Math, Breadth_First_Search | 1 | 100.00
+| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 4 | 96.54
-### Programming Skills I
+### Top Interview 150
-#### Day 1 Basic Data Type
+#### Top Interview 150 Array/String
| | | | | |
|-|-|-|-|-|-
-| 1523 |[Count Odd Numbers in an Interval Range](src/main/java/g1501_1600/s1523_count_odd_numbers_in_an_interval_range/Solution.java)| Easy | Math | 0 | 100.00
-| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](src/main/java/g1401_1500/s1491_average_salary_excluding_the_minimum_and_maximum_salary/Solution.java)| Easy | Array, Sorting | 0 | 100.00
+| 0088 |[Merge Sorted Array](src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00
+| 0027 |[Remove Element](src/main/java/g0001_0100/s0027_remove_element/Solution.java)| Easy | Array, Two_Pointers | 0 | 100.00
+| 0026 |[Remove Duplicates from Sorted Array](src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00
+| 0080 |[Remove Duplicates from Sorted Array II](src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java)| Medium | Array, Two_Pointers | 0 | 100.00
+| 0169 |[Majority Element](src/main/java/g0101_0200/s0169_majority_element/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.89
+| 0189 |[Rotate Array](src/main/java/g0101_0200/s0189_rotate_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 99.78
+| 0122 |[Best Time to Buy and Sell Stock II](src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 1 | 76.91
+| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 0045 |[Jump Game II](src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0274 |[H-Index](src/main/java/g0201_0300/s0274_h_index/Solution.java)| Medium | Array, Sorting, Counting_Sort | 0 | 100.00
+| 0380 |[Insert Delete GetRandom O(1)](src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java)| Medium | Array, Hash_Table, Math, Design, Randomized | 27 | 93.44
+| 0238 |[Product of Array Except Self](src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 1 | 99.66
+| 0134 |[Gas Station](src/main/java/g0101_0200/s0134_gas_station/Solution.java)| Medium | Top_Interview_Questions, Array, Greedy | 2 | 97.52
+| 0135 |[Candy](src/main/java/g0101_0200/s0135_candy/Solution.java)| Hard | Array, Greedy | 3 | 83.95
+| 0042 |[Trapping Rain Water](src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0013 |[Roman to Integer](src/main/java/g0001_0100/s0013_roman_to_integer/Solution.java)| Easy | Top_Interview_Questions, String, Hash_Table, Math, Big_O_Time_O(n)_Space_O(1) | 2 | 100.00
+| 0012 |[Integer to Roman](src/main/java/g0001_0100/s0012_integer_to_roman/Solution.java)| Medium | String, Hash_Table, Math, Big_O_Time_O(1)_Space_O(1) | 2 | 100.00
+| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java)| Easy | String | 0 | 100.00
+| 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 |[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
-#### Day 2 Operator
+#### Top Interview 150 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 1 | 84.87
-| 1281 |[Subtract the Product and Sum of Digits of an Integer](src/main/java/g1201_1300/s1281_subtract_the_product_and_sum_of_digits_of_an_integer/Solution.java)| Easy | Math | 0 | 100.00
+| 0125 |[Valid Palindrome](src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers | 2 | 99.11
+| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 1 | 93.13
+| 0167 |[Two Sum II - Input Array Is Sorted](src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers | 2 | 92.62
+| 0011 |[Container With Most Water](src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 96.01
+| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 29 | 72.02
-#### Day 3 Conditional Statements
+#### Top Interview 150 Sliding Window
| | | | | |
|-|-|-|-|-|-
-| 0976 |[Largest Perimeter Triangle](src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java)| Easy | Array, Math, Sorting, Greedy | 12 | 26.01
-| 1779 |[Find Nearest Point That Has the Same X or Y Coordinate](src/main/java/g1701_1800/s1779_find_nearest_point_that_has_the_same_x_or_y_coordinate/Solution.java)| Easy | Array | 1 | 100.00
+| 0209 |[Minimum Size Subarray Sum](src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 1 | 99.76
+| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 2 | 98.59
+| 0030 |[Substring with Concatenation of All Words](src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/Solution.java)| Hard | String, Hash_Table, Sliding_Window | 11 | 97.43
+| 0076 |[Minimum Window Substring](src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 2 | 99.83
-#### Day 4 Loop
+#### Top Interview 150 Matrix
| | | | | |
|-|-|-|-|-|-
-| 1822 |[Sign of the Product of an Array](src/main/java/g1801_1900/s1822_sign_of_the_product_of_an_array/Solution.java)| Easy | Array, Math | 1 | 58.05
-| 1502 |[Can Make Arithmetic Progression From Sequence](src/main/java/g1501_1600/s1502_can_make_arithmetic_progression_from_sequence/Solution.java)| Easy | Array, Sorting | 2 | 90.55
-| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 1 | 98.59
-| 1790 |[Check if One String Swap Can Make Strings Equal](src/main/java/g1701_1800/s1790_check_if_one_string_swap_can_make_strings_equal/Solution.java)| Easy | String, Hash_Table, Counting | 0 | 100.00
+| 0036 |[Valid Sudoku](src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix | 1 | 100.00
+| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
+| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
+| 0073 |[Set Matrix Zeroes](src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 0 | 100.00
+| 0289 |[Game of Life](src/main/java/g0201_0300/s0289_game_of_life/Solution.java)| Medium | Array, Matrix, Simulation | 0 | 100.00
-#### Day 5 Function
+#### Top Interview 150 Hashmap
| | | | | |
|-|-|-|-|-|-
-| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
-| 0496 |[Next Greater Element I](src/main/java/g0401_0500/s0496_next_greater_element_i/Solution.java)| Easy | Array, Hash_Table, Stack, Monotonic_Stack | 4 | 81.18
-| 1232 |[Check If It Is a Straight Line](src/main/java/g1201_1300/s1232_check_if_it_is_a_straight_line/Solution.java)| Easy | Array, Math, Geometry | 0 | 100.00
+| 0383 |[Ransom Note](src/main/java/g0301_0400/s0383_ransom_note/Solution.java)| Easy | String, Hash_Table, Counting | 1 | 99.10
+| 0205 |[Isomorphic Strings](src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java)| Easy | String, Hash_Table | 2 | 99.18
+| 0290 |[Word Pattern](src/main/java/g0201_0300/s0290_word_pattern/Solution.java)| Easy | String, Hash_Table | 0 | 100.00
+| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | String, Hash_Table, Sorting | 2 | 97.76
+| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 97.61
+| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 98.90
+| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
+| 0219 |[Contains Duplicate II](src/main/java/g0201_0300/s0219_contains_duplicate_ii/Solution.java)| Easy | Array, Hash_Table, Sliding_Window | 15 | 98.00
+| 0128 |[Longest Consecutive Sequence](src/main/java/g0101_0200/s0128_longest_consecutive_sequence/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 14 | 98.89
-#### Day 6 Array
+#### Top Interview 150 Intervals
| | | | | |
|-|-|-|-|-|-
-| 1588 |[Sum of All Odd Length Subarrays](src/main/java/g1501_1600/s1588_sum_of_all_odd_length_subarrays/Solution.java)| Easy | Array, Math, Prefix_Sum | 0 | 100.00
-| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 79.54
-| 1672 |[Richest Customer Wealth](src/main/java/g1601_1700/s1672_richest_customer_wealth/Solution.java)| Easy | Array, Matrix | 0 | 100.00
+| 0228 |[Summary Ranges](src/main/java/g0201_0300/s0228_summary_ranges/Solution.java)| Easy | Array | 0 | 100.00
+| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 98.37
+| 0057 |[Insert Interval](src/main/java/g0001_0100/s0057_insert_interval/Solution.java)| Medium | Array | 0 | 100.00
+| 0452 |[Minimum Number of Arrows to Burst Balloons](src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/Solution.java)| Medium | Array, Sorting, Greedy, LeetCode_75_Intervals | 52 | 89.91
-#### Day 7 Array
+#### Top Interview 150 Stack
| | | | | |
|-|-|-|-|-|-
-| 1572 |[Matrix Diagonal Sum](src/main/java/g1501_1600/s1572_matrix_diagonal_sum/Solution.java)| Easy | Array, Matrix | 0 | 100.00
-| 0566 |[Reshape the Matrix](src/main/java/g0501_0600/s0566_reshape_the_matrix/Solution.java)| Easy | Array, Matrix, Simulation | 1 | 90.08
+| 0020 |[Valid Parentheses](src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 97.19
+| 0071 |[Simplify Path](src/main/java/g0001_0100/s0071_simplify_path/Solution.java)| Medium | String, Stack | 2 | 99.86
+| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 4 | 96.54
+| 0150 |[Evaluate Reverse Polish Notation](src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java)| Medium | Top_Interview_Questions, Array, Math, Stack | 6 | 76.50
+| 0224 |[Basic Calculator](src/main/java/g0201_0300/s0224_basic_calculator/Solution.java)| Hard | String, Math, Stack, Recursion | 2 | 96.52
-#### Day 8 String
+#### Top Interview 150 Linked List
| | | | | |
|-|-|-|-|-|-
-| 1768 |[Merge Strings Alternately](src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java)| Easy | String, Two_Pointers | 1 | 86.26
-| 1678 |[Goal Parser Interpretation](src/main/java/g1601_1700/s1678_goal_parser_interpretation/Solution.java)| Easy | String | 0 | 100.00
-| 0389 |[Find the Difference](src/main/java/g0301_0400/s0389_find_the_difference/Solution.java)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 1 | 100.00
+| 0141 |[Linked List Cycle](src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
+| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
+| 0138 |[Copy List with Random Pointer](src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0092 |[Reverse Linked List II](src/main/java/g0001_0100/s0092_reverse_linked_list_ii/Solution.java)| Medium | Linked_List | 0 | 100.00
+| 0025 |[Reverse Nodes in k-Group](src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
+| 0019 |[Remove Nth Node From End of List](src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
+| 0082 |[Remove Duplicates from Sorted List II](src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0061 |[Rotate List](src/main/java/g0001_0100/s0061_rotate_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0086 |[Partition List](src/main/java/g0001_0100/s0086_partition_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0146 |[LRU Cache](src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 40 | 98.20
-#### Day 9 String
+#### Top Interview 150 Binary Tree General
| | | | | |
|-|-|-|-|-|-
-| 0709 |[To Lower Case](src/main/java/g0701_0800/s0709_to_lower_case/Solution.java)| Easy | String | 1 | 71.74
-| 1309 |[Decrypt String from Alphabet to Integer Mapping](src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java)| Easy | String | 6 | 28.25
-| 0953 |[Verifying an Alien Dictionary](src/main/java/g0901_1000/s0953_verifying_an_alien_dictionary/Solution.java)| Easy | Array, String, Hash_Table | 0 | 100.00
+| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
+| 0100 |[Same Tree](src/main/java/g0001_0100/s0100_same_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0101 |[Symmetric Tree](src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 1 | 96.33
+| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/java/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.java)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer | 0 | 100.00
+| 0117 |[Populating Next Right Pointers in Each Node II](src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 0 | 100.00
+| 0114 |[Flatten Binary Tree to Linked List](src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0112 |[Path Sum](src/main/java/g0101_0200/s0112_path_sum/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0129 |[Sum Root to Leaf Numbers](src/main/java/g0101_0200/s0129_sum_root_to_leaf_numbers/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0124 |[Binary Tree Maximum Path Sum](src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 15 | 100.00
+| 0222 |[Count Complete Tree Nodes](src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree | 0 | 100.00
+| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 6 | 100.00
-#### Day 10 Linked List and Tree
+#### Top Interview 150 Binary Tree BFS
| | | | | |
|-|-|-|-|-|-
-| 1290 |[Convert Binary Number in a Linked List to Integer](src/main/java/g1201_1300/s1290_convert_binary_number_in_a_linked_list_to_integer/Solution.java)| Easy | Math, Linked_List | 0 | 100.00
-| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
-| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
-| 0404 |[Sum of Left Leaves](src/main/java/g0401_0500/s0404_sum_of_left_leaves/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 29.26
+| 0199 |[Binary Tree Right Side View](src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00
+| 0637 |[Average of Levels in Binary Tree](src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 2 | 94.34
+| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.19
+| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
-#### Day 11 Containers and Libraries
+#### Top Interview 150 Binary Search Tree
| | | | | |
|-|-|-|-|-|-
-| 1356 |[Sort Integers by The Number of 1 Bits](src/main/java/g1301_1400/s1356_sort_integers_by_the_number_of_1_bits/Solution.java)| Easy | Array, Sorting, Bit_Manipulation, Counting | 10 | 65.50
-| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
-| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | Top_Interview_Questions, String, Hash_Table, Sorting | 2 | 99.01
-| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
+| 0530 |[Minimum Absolute Difference in BST](src/main/java/g0501_0600/s0530_minimum_absolute_difference_in_bst/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
+| 0230 |[Kth Smallest Element in a BST](src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-#### Day 12 Class and Object
+#### Top Interview 150 Graph General
| | | | | |
|-|-|-|-|-|-
-| 1603 |[Design Parking System](src/main/java/g1601_1700/s1603_design_parking_system/ParkingSystem.java)| Easy | Design, Simulation, Counting | 8 | 76.16
-| 0303 |[Range Sum Query - Immutable](src/main/java/g0301_0400/s0303_range_sum_query_immutable/NumArray.java)| Easy | Array, Design, Prefix_Sum | 7 | 100.00
-
-### Programming Skills II
+| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
+| 0130 |[Surrounded Regions](src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 2 | 84.66
+| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 25 | 68.87
+| 0399 |[Evaluate Division](src/main/java/g0301_0400/s0399_evaluate_division/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 1 | 99.52
+| 0207 |[Course Schedule](src/main/java/g0201_0300/s0207_course_schedule/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 3 | 99.99
+| 0210 |[Course Schedule II](src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 4 | 91.07
-#### Day 1
+#### Top Interview 150 Graph BFS
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0909 |[Snakes and Ladders](src/main/java/g0901_1000/s0909_snakes_and_ladders/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 4 | 95.81
+| 0433 |[Minimum Genetic Mutation](src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java)| Medium | String, Hash_Table, Breadth_First_Search | 0 | 100.00
+| 0127 |[Word Ladder](src/main/java/g0101_0200/s0127_word_ladder/Solution.java)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 22 | 96.00
-#### Day 2
+#### Top Interview 150 Trie
| | | | | |
|-|-|-|-|-|-
-| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
-| 0459 |[Repeated Substring Pattern](src/main/java/g0401_0500/s0459_repeated_substring_pattern/Solution.java)| Easy | String, String_Matching | 8 | 96.64
+| 0208 |[Implement Trie (Prefix Tree)](src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, LeetCode_75_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 32 | 95.05
+| 0211 |[Design Add and Search Words Data Structure](src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/WordDictionary.java)| Medium | String, Depth_First_Search, Design, Trie | 156 | 99.85
+| 0212 |[Word Search II](src/main/java/g0201_0300/s0212_word_search_ii/Solution.java)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie | 17 | 99.16
-#### Day 3
+#### Top Interview 150 Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0150 |[Evaluate Reverse Polish Notation](src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java)| Medium | Top_Interview_Questions, Array, Math, Stack | 9 | 51.23
-| 0066 |[Plus One](src/main/java/g0001_0100/s0066_plus_one/Solution.java)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
+| 0017 |[Letter Combinations of a Phone Number](src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
+| 0077 |[Combinations](src/main/java/g0001_0100/s0077_combinations/Solution.java)| Medium | Backtracking | 15 | 92.38
+| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 94.08
+| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 99.99
+| 0052 |[N-Queens II](src/main/java/g0001_0100/s0052_n_queens_ii/Solution.java)| Hard | Backtracking | 0 | 100.00
+| 0022 |[Generate Parentheses](src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
+| 0079 |[Word Search](src/main/java/g0001_0100/s0079_word_search/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 64 | 98.51
-#### Day 4
+#### Top Interview 150 Divide and Conquer
| | | | | |
|-|-|-|-|-|-
-| 1367 |[Linked List in Binary Tree](src/main/java/g1301_1400/s1367_linked_list_in_binary_tree/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 2 | 61.23
-| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
+| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
+| 0148 |[Sort List](src/main/java/g0101_0200/s0148_sort_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 9 | 93.90
+| 0427 |[Construct Quad Tree](src/main/java/g0401_0500/s0427_construct_quad_tree/Solution.java)| Medium | Array, Tree, Matrix, Divide_and_Conquer | 0 | 100.00
+| 0023 |[Merge k Sorted Lists](src/main/java/g0001_0100/s0023_merge_k_sorted_lists/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 1 | 99.86
-#### Day 5
+#### Top Interview 150 Kadane's Algorithm
| | | | | |
|-|-|-|-|-|-
-| 0067 |[Add Binary](src/main/java/g0001_0100/s0067_add_binary/Solution.java)| Easy | String, Math, Bit_Manipulation, Simulation | 1 | 100.00
-| 0989 |[Add to Array-Form of Integer](src/main/java/g0901_1000/s0989_add_to_array_form_of_integer/Solution.java)| Easy | Array, Math | 7 | 65.92
+| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.32
+| 0918 |[Maximum Sum Circular Subarray](src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 99.34
-#### Day 6
+#### Top Interview 150 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0739 |[Daily Temperatures](src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 10 | 94.99
-| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java)| Easy | String | 0 | 100.00
+| 0035 |[Search Insert Position](src/main/java/g0001_0100/s0035_search_insert_position/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 0162 |[Find Peak Element](src/main/java/g0101_0200/s0162_find_peak_element/Solution.java)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00
+| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
+| 0004 |[Median of Two Sorted Arrays](src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1), AI_can_be_used_to_solve_the_task | 1 | 100.00
-#### Day 7
+#### Top Interview 150 Heap
| | | | | |
|-|-|-|-|-|-
-| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
-| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/java/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.java)| Easy | Array, Matrix | 1 | 78.38
+| 0215 |[Kth Largest Element in an Array](src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 5 | 70.82
+| 0502 |[IPO](src/main/java/g0501_0600/s0502_ipo/Solution.java)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue | 64 | 97.22
+| 0373 |[Find K Pairs with Smallest Sums](src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.java)| Medium | Array, Heap_Priority_Queue | 27 | 90.23
+| 0295 |[Find Median from Data Stream](src/main/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinder.java)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 83 | 99.56
-#### Day 8
+#### Top Interview 150 Bit Manipulation
| | | | | |
|-|-|-|-|-|-
-| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
-| 0973 |[K Closest Points to Origin](src/main/java/g0901_1000/s0973_k_closest_points_to_origin/Solution.java)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 4 | 98.26
+| 0067 |[Add Binary](src/main/java/g0001_0100/s0067_add_binary/Solution.java)| Easy | String, Math, Bit_Manipulation, Simulation | 1 | 99.82
+| 0190 |[Reverse Bits](src/main/java/g0101_0200/s0190_reverse_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 0 | 100.00
+| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00
+| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.86
+| 0137 |[Single Number II](src/main/java/g0101_0200/s0137_single_number_ii/Solution.java)| Medium | Array, Bit_Manipulation | 0 | 100.00
+| 0201 |[Bitwise AND of Numbers Range](src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java)| Medium | Bit_Manipulation | 3 | 100.00
-#### Day 9
+#### Top Interview 150 Math
| | | | | |
|-|-|-|-|-|-
-| 1630 |[Arithmetic Subarrays](src/main/java/g1601_1700/s1630_arithmetic_subarrays/Solution.java)| Medium | Array, Sorting | 8 | 93.62
-| 0429 |[N-ary Tree Level Order Traversal](src/main/java/g0401_0500/s0429_n_ary_tree_level_order_traversal/Solution.java)| Medium | Breadth_First_Search, Tree | 3 | 80.26
+| 0009 |[Palindrome Number](src/main/java/g0001_0100/s0009_palindrome_number/Solution.java)| Easy | Math, Big_O_Time_O(log10(x))_Space_O(1) | 4 | 100.00
+| 0066 |[Plus One](src/main/java/g0001_0100/s0066_plus_one/Solution.java)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
+| 0172 |[Factorial Trailing Zeroes](src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java)| Medium | Top_Interview_Questions, Math | 0 | 100.00
+| 0069 |[Sqrt(x)](src/main/java/g0001_0100/s0069_sqrtx/Solution.java)| Easy | Top_Interview_Questions, Math, Binary_Search | 1 | 86.67
+| 0050 |[Pow(x, n)](src/main/java/g0001_0100/s0050_powx_n/Solution.java)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
+| 0149 |[Max Points on a Line](src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 7 | 99.18
-#### Day 10
+#### Top Interview 150 1D DP
| | | | | |
|-|-|-|-|-|-
-| 0503 |[Next Greater Element II](src/main/java/g0501_0600/s0503_next_greater_element_ii/Solution.java)| Medium | Array, Stack, Monotonic_Stack | 7 | 97.03
-| 0556 |[Next Greater Element III](src/main/java/g0501_0600/s0556_next_greater_element_iii/Solution.java)| Medium | String, Math, Two_Pointers | 0 | 100.00
+| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 1 | 99.42
+| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 12 | 92.59
+| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 95.75
-#### Day 11
+#### Top Interview 150 Multidimensional DP
| | | | | |
|-|-|-|-|-|-
-| 1376 |[Time Needed to Inform All Employees](src/main/java/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 8 | 99.85
-| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 92.28
+| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 99.79
+| 0064 |[Minimum Path Sum](src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 99.73
+| 0063 |[Unique Paths II](src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java)| Medium | Array, Dynamic_Programming, Matrix | 0 | 100.00
+| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.82
+| 0097 |[Interleaving String](src/main/java/g0001_0100/s0097_interleaving_string/Solution.java)| Medium | String, Dynamic_Programming | 0 | 100.00
+| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 3 | 97.19
+| 0123 |[Best Time to Buy and Sell Stock III](src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/Solution.java)| Hard | Array, Dynamic_Programming | 4 | 74.67
+| 0188 |[Best Time to Buy and Sell Stock IV](src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.java)| Hard | Array, Dynamic_Programming | 1 | 99.73
+| 0221 |[Maximal Square](src/main/java/g0201_0300/s0221_maximal_square/Solution.java)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 6 | 97.07
-#### Day 12
+### Data Structure I
+
+#### Day 1 Array
| | | | | |
|-|-|-|-|-|-
-| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 6 | 99.03
-| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
+| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
+| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.32
-#### Day 13
+#### Day 2 Array
| | | | | |
|-|-|-|-|-|-
-| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
-| 0910 |[Smallest Range II](src/main/java/g0901_1000/s0910_smallest_range_ii/Solution.java)| Medium | Array, Math, Sorting, Greedy | 10 | 73.16
+| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 98.90
+| 0088 |[Merge Sorted Array](src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00
-#### Day 14
+#### Day 3 Array
| | | | | |
|-|-|-|-|-|-
-| 0143 |[Reorder List](src/main/java/g0101_0200/s0143_reorder_list/Solution.java)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 2 | 72.59
-| 0138 |[Copy List with Random Pointer](src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
+| 0350 |[Intersection of Two Arrays II](src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java)| Easy | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 4 | 69.62
+| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 99.78
-#### Day 15
+#### Day 4 Array
| | | | | |
|-|-|-|-|-|-
-| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 1 | 100.00
-| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii/Solution.java)| Medium | Math, Stack, Linked_List | 3 | 90.38
+| 0566 |[Reshape the Matrix](src/main/java/g0501_0600/s0566_reshape_the_matrix/Solution.java)| Easy | Array, Matrix, Simulation | 1 | 90.08
+| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
-#### Day 16
+#### Day 5 Array
| | | | | |
|-|-|-|-|-|-
-| 0061 |[Rotate List](src/main/java/g0001_0100/s0061_rotate_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
-| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 18 | 84.18
+| 0036 |[Valid Sudoku](src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix | 1 | 100.00
+| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
-#### Day 17
+#### Day 6 String
| | | | | |
|-|-|-|-|-|-
-| 1845 |[Seat Reservation Manager](src/main/java/g1801_1900/s1845_seat_reservation_manager/SeatManager.java)| Medium | Design, Heap_Priority_Queue | 47 | 87.63
-| 0860 |[Lemonade Change](src/main/java/g0801_0900/s0860_lemonade_change/Solution.java)| Easy | Array, Greedy | 2 | 90.84
+| 0387 |[First Unique Character in a String](src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java)| Easy | String, Hash_Table, Counting, Queue | 1 | 100.00
+| 0383 |[Ransom Note](src/main/java/g0301_0400/s0383_ransom_note/Solution.java)| Easy | String, Hash_Table, Counting | 1 | 99.10
+| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | String, Hash_Table, Sorting | 2 | 97.76
-#### Day 18
+#### Day 7 Linked List
| | | | | |
|-|-|-|-|-|-
-| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 3 | 100.00
-| 0341 |[Flatten Nested List Iterator](src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java)| Medium | Top_Interview_Questions, Depth_First_Search, Tree, Stack, Design, Queue, Iterator | 2 | 99.95
+| 0141 |[Linked List Cycle](src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
+| 0203 |[Remove Linked List Elements](src/main/java/g0201_0300/s0203_remove_linked_list_elements/Solution.java)| Easy | Linked_List, Recursion | 1 | 98.82
-#### Day 19
+#### Day 8 Linked List
| | | | | |
|-|-|-|-|-|-
-| 1797 |[Design Authentication Manager](src/main/java/g1701_1800/s1797_design_authentication_manager/AuthenticationManager.java)| Medium | Hash_Table, Design | 41 | 92.67
-| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
+| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0083 |[Remove Duplicates from Sorted List](src/main/java/g0001_0100/s0083_remove_duplicates_from_sorted_list/Solution.java)| Easy | Linked_List | 0 | 100.00
-#### Day 20
+#### Day 9 Stack Queue
| | | | | |
|-|-|-|-|-|-
-| 0380 |[Insert Delete GetRandom O(1)](src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java)| Medium | Top_Interview_Questions, Array, Hash_Table, Math, Design, Randomized | 27 | 93.44
-| 0622 |[Design Circular Queue](src/main/java/g0601_0700/s0622_design_circular_queue/MyCircularQueue.java)| Medium | Array, Design, Linked_List, Queue | 3 | 100.00
-| 0729 |[My Calendar I](src/main/java/g0701_0800/s0729_my_calendar_i/MyCalendar.java)| Medium | Binary_Search, Design, Ordered_Set, Segment_Tree | 17 | 97.23
-
-### Graph Theory I
+| 0020 |[Valid Parentheses](src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 97.19
+| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
-#### Day 1 Matrix Related Problems
+#### Day 10 Tree
| | | | | |
|-|-|-|-|-|-
-| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
-| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
+| 0144 |[Binary Tree Preorder Traversal](src/main/java/g0101_0200/s0144_binary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 48.38
+| 0094 |[Binary Tree Inorder Traversal](src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0145 |[Binary Tree Postorder Traversal](src/main/java/g0101_0200/s0145_binary_tree_postorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 49.11
-#### Day 2 Matrix Related Problems
+#### Day 11 Tree
| | | | | |
|-|-|-|-|-|-
-| 0695 |[Max Area of Island](src/main/java/g0601_0700/s0695_max_area_of_island/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 76.79
-| 1254 |[Number of Closed Islands](src/main/java/g1201_1300/s1254_number_of_closed_islands/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 55.59
+| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.19
+| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
+| 0101 |[Symmetric Tree](src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-#### Day 3 Matrix Related Problems
+#### Day 12 Tree
| | | | | |
|-|-|-|-|-|-
-| 1020 |[Number of Enclaves](src/main/java/g1001_1100/s1020_number_of_enclaves/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 6 | 68.24
-| 1905 |[Count Sub Islands](src/main/java/g1901_2000/s1905_count_sub_islands/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 24 | 85.54
+| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0112 |[Path Sum](src/main/java/g0101_0200/s0112_path_sum/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
-#### Day 4 Matrix Related Problems
+#### Day 13 Tree
| | | | | |
|-|-|-|-|-|-
-| 1162 |[As Far from Land as Possible](src/main/java/g1101_1200/s1162_as_far_from_land_as_possible/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 16 | 62.40
-| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
+| 0700 |[Search in a Binary Search Tree](src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java)| Easy | Tree, Binary_Tree, Binary_Search_Tree, LeetCode_75_Binary_Search_Tree | 0 | 100.00
+| 0701 |[Insert into a Binary Search Tree](src/main/java/g0701_0800/s0701_insert_into_a_binary_search_tree/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
-#### Day 5 Matrix Related Problems
+#### Day 14 Tree
| | | | | |
|-|-|-|-|-|-
-| 1091 |[Shortest Path in Binary Matrix](src/main/java/g1001_1100/s1091_shortest_path_in_binary_matrix/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 22 | 69.99
-| 0542 |[01 Matrix](src/main/java/g0501_0600/s0542_01_matrix/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 7 | 95.83
+| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0653 |[Two Sum IV - Input is a BST](src/main/java/g0601_0700/s0653_two_sum_iv_input_is_a_bst/Solution.java)| Easy | Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Two_Pointers, Binary_Search_Tree | 5 | 74.23
+| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
-#### Day 6 Matrix Related Problems
+### Data Structure II
+
+#### Day 1 Array
| | | | | |
|-|-|-|-|-|-
-| 0934 |[Shortest Bridge](src/main/java/g0901_1000/s0934_shortest_bridge/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 6 | 97.87
-| 1926 |[Nearest Exit from Entrance in Maze](src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 12 | 40.55
+| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.86
+| 0169 |[Majority Element](src/main/java/g0101_0200/s0169_majority_element/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.89
+| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 29 | 72.02
-#### Day 7 Standard Traversal
+#### Day 2 Array
| | | | | |
|-|-|-|-|-|-
-| 0797 |[All Paths From Source to Target](src/main/java/g0701_0800/s0797_all_paths_from_source_to_target/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 2 | 90.53
-| 0841 |[Keys and Rooms](src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph | 3 | 51.54
+| 0075 |[Sort Colors](src/main/java/g0001_0100/s0075_sort_colors/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 98.37
+| 0706 |[Design HashMap](src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java)| Easy | Array, Hash_Table, Design, Linked_List, Hash_Function | 13 | 95.71
-#### Day 8 Standard Traversal
+#### Day 3 Array
| | | | | |
|-|-|-|-|-|-
-| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 2 | 69.51
-| 1319 |[Number of Operations to Make Network Connected](src/main/java/g1301_1400/s1319_number_of_operations_to_make_network_connected/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 9 | 67.64
+| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
+| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
+| 0059 |[Spiral Matrix II](src/main/java/g0001_0100/s0059_spiral_matrix_ii/Solution.java)| Medium | Array, Matrix, Simulation | 0 | 100.00
-#### Day 9 Standard Traversal
+#### Day 4 Array
| | | | | |
|-|-|-|-|-|-
-| 1376 |[Time Needed to Inform All Employees](src/main/java/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 8 | 99.85
-| 0802 |[Find Eventual Safe States](src/main/java/g0801_0900/s0802_find_eventual_safe_states/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 7 | 74.93
+| 0240 |[Search a 2D Matrix II](src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 5 | 99.92
+| 0435 |[Non-overlapping Intervals](src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java)| Medium | Array, Dynamic_Programming, Sorting, Greedy, LeetCode_75_Intervals | 96 | 47.37
-#### Day 10 Standard Traversal
+#### Day 5 Array
| | | | | |
|-|-|-|-|-|-
-| 1129 |[Shortest Path with Alternating Colors](src/main/java/g1101_1200/s1129_shortest_path_with_alternating_colors/Solution.java)| Medium | Breadth_First_Search, Graph | 4 | 96.63
-| 1466 |[Reorder Routes to Make All Paths Lead to the City Zero](src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph | 39 | 97.71
-| 0847 |[Shortest Path Visiting All Nodes](src/main/java/g0801_0900/s0847_shortest_path_visiting_all_nodes/Solution.java)| Hard | Dynamic_Programming, Breadth_First_Search, Bit_Manipulation, Graph, Bitmask | 14 | 78.72
+| 0334 |[Increasing Triplet Subsequence](src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java)| Medium | Array, Greedy, LeetCode_75_Array/String | 2 | 99.33
+| 0238 |[Product of Array Except Self](src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, LeetCode_75_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 1 | 99.66
+| 0560 |[Subarray Sum Equals K](src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 22 | 95.17
-#### Day 11 Breadth First Search
+#### Day 6 String
| | | | | |
|-|-|-|-|-|-
-| 1306 |[Jump Game III](src/main/java/g1301_1400/s1306_jump_game_iii/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search | 2 | 96.23
-| 1654 |[Minimum Jumps to Reach Home](src/main/java/g1601_1700/s1654_minimum_jumps_to_reach_home/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search | 6 | 99.87
-| 0365 |[Water and Jug Problem](src/main/java/g0301_0400/s0365_water_and_jug_problem/Solution.java)| Medium | Math, Depth_First_Search, Breadth_First_Search | 0 | 100.00
+| 0415 |[Add Strings](src/main/java/g0401_0500/s0415_add_strings/Solution.java)| Easy | String, Math, Simulation | 3 | 82.41
+| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
-#### Day 12 Breadth First Search
+#### Day 7 String
| | | | | |
|-|-|-|-|-|-
-| 0433 |[Minimum Genetic Mutation](src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java)| Medium | String, Hash_Table, Breadth_First_Search | 1 | 90.95
-| 0752 |[Open the Lock](src/main/java/g0701_0800/s0752_open_the_lock/Solution.java)| Medium | Array, String, Hash_Table, Breadth_First_Search | 72 | 91.06
-| 0127 |[Word Ladder](src/main/java/g0101_0200/s0127_word_ladder/Solution.java)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 37 | 94.58
+| 0290 |[Word Pattern](src/main/java/g0201_0300/s0290_word_pattern/Solution.java)| Easy | String, Hash_Table | 0 | 100.00
+| 0763 |[Partition Labels](src/main/java/g0701_0800/s0763_partition_labels/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 100.00
-#### Day 13 Graph Theory
+#### Day 8 String
| | | | | |
|-|-|-|-|-|-
-| 0997 |[Find the Town Judge](src/main/java/g0901_1000/s0997_find_the_town_judge/Solution.java)| Easy | Array, Hash_Table, Graph | 3 | 80.64
-| 1557 |[Minimum Number of Vertices to Reach All Nodes](src/main/java/g1501_1600/s1557_minimum_number_of_vertices_to_reach_all_nodes/Solution.java)| Medium | Graph | 8 | 99.94
+| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 97.61
+| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
-#### Day 14 Graph Theory
+#### Day 9 String
| | | | | |
|-|-|-|-|-|-
-| 1615 |[Maximal Network Rank](src/main/java/g1601_1700/s1615_maximal_network_rank/Solution.java)| Medium | Graph | 3 | 97.34
-| 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
+| 0187 |[Repeated DNA Sequences](src/main/java/g0101_0200/s0187_repeated_dna_sequences/Solution.java)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash | 29 | 77.11
+| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.82
-#### Day 1 Select
+#### Day 10 Linked List
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
+| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-#### Day 2 Select and Order
+#### Day 11 Linked List
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0160 |[Intersection of Two Linked Lists](src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 1 | 99.92
+| 0082 |[Remove Duplicates from Sorted List II](src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
-#### Day 3 String Processing Functions
+#### Day 12 Linked List
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0024 |[Swap Nodes in Pairs](src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
-#### Day 4 Union and Select
+#### Day 13 Linked List
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0025 |[Reverse Nodes in k-Group](src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
+| 0143 |[Reorder List](src/main/java/g0101_0200/s0143_reorder_list/Solution.java)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 2 | 72.59
-#### Day 5 Union
+#### Day 14 Stack Queue
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 4 | 96.54
+| 1249 |[Minimum Remove to Make Valid Parentheses](src/main/java/g1201_1300/s1249_minimum_remove_to_make_valid_parentheses/Solution.java)| Medium | String, Stack | 13 | 94.62
+| 1823 |[Find the Winner of the Circular Game](src/main/java/g1801_1900/s1823_find_the_winner_of_the_circular_game/Solution.java)| Medium | Array, Math, Simulation, Recursion, Queue | 3 | 64.85
-#### Day 6 Union
+#### Day 15 Tree
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
+| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 1 | 96.33
+| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
-#### Day 7 Function
+#### Day 16 Tree
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0199 |[Binary Tree Right Side View](src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/BFS | 0 | 100.00
+| 0113 |[Path Sum II](src/main/java/g0101_0200/s0113_path_sum_ii/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Backtracking | 1 | 100.00
+| 0450 |[Delete Node in a BST](src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree, LeetCode_75_Binary_Search_Tree | 0 | 100.00
-#### Day 8 Function
+#### Day 17 Tree
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0230 |[Kth Smallest Element in a BST](src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 15 | 100.00
-#### Day 9 Control of Flow
+#### Day 18 Tree
| | | | | |
|-|-|-|-|-|-
-| 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
+| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 6 | 100.00
+| 0297 |[Serialize and Deserialize Binary Tree](src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java)| Hard | String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design | 7 | 98.13
-#### Day 10 Where
+#### Day 19 Graph
| | | | | |
|-|-|-|-|-|-
-| 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
-
-### Level 1
+| 0997 |[Find the Town Judge](src/main/java/g0901_1000/s0997_find_the_town_judge/Solution.java)| Easy | Array, Hash_Table, Graph | 3 | 80.64
+| 1557 |[Minimum Number of Vertices to Reach All Nodes](src/main/java/g1501_1600/s1557_minimum_number_of_vertices_to_reach_all_nodes/Solution.java)| Medium | Graph | 8 | 99.94
+| 0841 |[Keys and Rooms](src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, LeetCode_75_Graphs/DFS | 3 | 51.54
-#### Day 1 Prefix Sum
+#### Day 20 Heap Priority Queue
| | | | | |
|-|-|-|-|-|-
-| 1480 |[Running Sum of 1d Array](src/main/java/g1401_1500/s1480_running_sum_of_1d_array/Solution.java)| Easy | Array, Prefix_Sum | 0 | 100.00
-| 0724 |[Find Pivot Index](src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java)| Easy | Array, Prefix_Sum | 2 | 69.67
+| 0215 |[Kth Largest Element in an Array](src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, LeetCode_75_Heap/Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 5 | 70.82
+| 0347 |[Top K Frequent Elements](src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 9 | 97.30
-#### Day 2 String
+#### Day 21 Heap Priority Queue
| | | | | |
|-|-|-|-|-|-
-| 0205 |[Isomorphic Strings](src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java)| Easy | String, Hash_Table | 2 | 99.97
-| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers | 1 | 93.01
+| 0451 |[Sort Characters By Frequency](src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Bucket_Sort | 13 | 89.63
+| 0973 |[K Closest Points to Origin](src/main/java/g0901_1000/s0973_k_closest_points_to_origin/Solution.java)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 4 | 98.26
-#### Day 3 Linked List
+### Algorithm I
+
+#### Day 1 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
-| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
+| 0035 |[Search Insert Position](src/main/java/g0001_0100/s0035_search_insert_position/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-#### Day 4 Linked List
+#### Day 2 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
-| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0977 |[Squares of a Sorted Array](src/main/java/g0901_1000/s0977_squares_of_a_sorted_array/Solution.java)| Easy | Array, Sorting, Two_Pointers | 1 | 100.00
+| 0189 |[Rotate Array](src/main/java/g0101_0200/s0189_rotate_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-#### Day 5 Greedy
+#### Day 3 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
-| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
+| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 83.99
+| 0167 |[Two Sum II - Input Array Is Sorted](src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers | 2 | 92.62
-#### Day 6 Tree
+#### Day 4 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
-| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.09
+| 0344 |[Reverse String](src/main/java/g0301_0400/s0344_reverse_string/Solution.java)| Easy | String, Two_Pointers, Recursion | 1 | 99.91
+| 0557 |[Reverse Words in a String III](src/main/java/g0501_0600/s0557_reverse_words_in_a_string_iii/Solution.java)| Easy | String, Two_Pointers | 4 | 97.75
-#### Day 7 Binary Search
+#### Day 5 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
+| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
+| 0019 |[Remove Nth Node From End of List](src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
-#### Day 8 Binary Search Tree
+#### Day 6 Sliding Window
| | | | | |
|-|-|-|-|-|-
-| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
+| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 2 | 98.59
+| 0567 |[Permutation in String](src/main/java/g0501_0600/s0567_permutation_in_string/Solution.java)| Medium | String, Hash_Table, Two_Pointers, Sliding_Window | 5 | 93.93
-#### Day 9 Graph/BFS/DFS
+#### Day 7 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
-| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
+| 0695 |[Max Area of Island](src/main/java/g0601_0700/s0695_max_area_of_island/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 76.79
-#### Day 10 Dynamic Programming
+#### Day 8 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
-| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
-| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0617 |[Merge Two Binary Trees](src/main/java/g0601_0700/s0617_merge_two_binary_trees/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 72.47
+| 0116 |[Populating Next Right Pointers in Each Node](src/main/java/g0101_0200/s0116_populating_next_right_pointers_in_each_node/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 0 | 100.00
-#### Day 11 Dynamic Programming
+#### Day 9 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
-| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming | 1 | 86.38
-| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
+| 0542 |[01 Matrix](src/main/java/g0501_0600/s0542_01_matrix/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 7 | 95.83
+| 0994 |[Rotting Oranges](src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java)| Medium | Top_100_Liked_Questions, Array, Breadth_First_Search, Matrix, LeetCode_75_Graphs/BFS | 3 | 74.27
-#### Day 12 Sliding Window/Two Pointer
+#### Day 10 Recursion Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 6 | 99.03
-| 0424 |[Longest Repeating Character Replacement](src/main/java/g0401_0500/s0424_longest_repeating_character_replacement/Solution.java)| Medium | String, Hash_Table, Sliding_Window | 5 | 95.15
+| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
+| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, LeetCode_75_LinkedList, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-#### Day 13 Hashmap
+#### Day 11 Recursion Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 99.37
-| 0299 |[Bulls and Cows](src/main/java/g0201_0300/s0299_bulls_and_cows/Solution.java)| Medium | String, Hash_Table, Counting | 6 | 86.69
+| 0077 |[Combinations](src/main/java/g0001_0100/s0077_combinations/Solution.java)| Medium | Backtracking | 15 | 92.38
+| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 94.08
+| 0784 |[Letter Case Permutation](src/main/java/g0701_0800/s0784_letter_case_permutation/Solution.java)| Medium | String, Bit_Manipulation, Backtracking | 10 | 40.38
-#### Day 14 Stack
+#### Day 12 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
-| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 1 | 87.68
+| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 99.79
-#### Day 15 Heap
+#### Day 13 Bit Manipulation
| | | | | |
|-|-|-|-|-|-
-| 1046 |[Last Stone Weight](src/main/java/g1001_1100/s1046_last_stone_weight/Solution.java)| Easy | Array, Heap_Priority_Queue | 2 | 73.81
-| 0692 |[Top K Frequent Words](src/main/java/g0601_0700/s0692_top_k_frequent_words/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 11 | 38.54
+| 0231 |[Power of Two](src/main/java/g0201_0300/s0231_power_of_two/Solution.java)| Easy | Math, Bit_Manipulation, Recursion | 1 | 100.00
+| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00
-### Level 2
+#### Day 14 Bit Manipulation
-#### Day 1 Implementation/Simulation
+| | | | | |
+|-|-|-|-|-|-
+| 0190 |[Reverse Bits](src/main/java/g0101_0200/s0190_reverse_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 0 | 100.00
+| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, LeetCode_75_Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.86
+
+### Algorithm II
+
+#### Day 1 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 1 | 98.59
-| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
-| 1706 |[Where Will the Ball Fall](src/main/java/g1701_1800/s1706_where_will_the_ball_fall/Solution.java)| Medium | Array, Dynamic_Programming, Depth_First_Search, Matrix, Simulation | 2 | 64.55
+| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
-#### Day 2 String
+#### Day 2 Binary Search
| | | | | |
|-|-|-|-|-|-
-| 0014 |[Longest Common Prefix](src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java)| Easy | Top_Interview_Questions, String | 0 | 100.00
-| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
+| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
+| 0162 |[Find Peak Element](src/main/java/g0101_0200/s0162_find_peak_element/Solution.java)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00
-#### Day 3 Linked List
+#### Day 3 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0019 |[Remove Nth Node From End of List](src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
-| 0234 |[Palindrome Linked List](src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 6 | 76.07
+| 0082 |[Remove Duplicates from Sorted List II](src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 29 | 72.02
-#### Day 4 Linked List
+#### Day 4 Two Pointers
| | | | | |
|-|-|-|-|-|-
-| 0328 |[Odd Even Linked List](src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java)| Medium | Top_Interview_Questions, Linked_List | 0 | 100.00
-| 0148 |[Sort List](src/main/java/g0101_0200/s0148_sort_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 12 | 85.82
+| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
+| 0986 |[Interval List Intersections](src/main/java/g0901_1000/s0986_interval_list_intersections/Solution.java)| Medium | Array, Two_Pointers | 2 | 99.95
+| 0011 |[Container With Most Water](src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 96.01
-#### Day 5 Greedy
+#### Day 5 Sliding Window
| | | | | |
|-|-|-|-|-|-
-| 2131 |[Longest Palindrome by Concatenating Two Letter Words](src/main/java/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words/Solution.java)| Medium | Array, String, Hash_Table, Greedy, Counting | 73 | 76.60
-| 0621 |[Task Scheduler](src/main/java/g0601_0700/s0621_task_scheduler/Solution.java)| Medium | Array, Hash_Table, Sorting, Greedy, Heap_Priority_Queue, Counting | 3 | 84.32
+| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 3 | 99.83
+| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
+| 0209 |[Minimum Size Subarray Sum](src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 1 | 99.76
-#### Day 6 Tree
+#### Day 6 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
-| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
+| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
+| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find, LeetCode_75_Graphs/DFS | 2 | 69.51
-#### Day 7 Tree
+#### Day 7 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
-| 0543 |[Diameter of Binary Tree](src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 65.86
-| 0437 |[Path Sum III](src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 18 | 45.66
+| 0117 |[Populating Next Right Pointers in Each Node II](src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 0 | 100.00
+| 0572 |[Subtree of Another Tree](src/main/java/g0501_0600/s0572_subtree_of_another_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Hash_Function, String_Matching | 2 | 97.06
-#### Day 8 Binary Search
+#### Day 8 Breadth First Search Depth First Search
| | | | | |
|-|-|-|-|-|-
-| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
-| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 1091 |[Shortest Path in Binary Matrix](src/main/java/g1001_1100/s1091_shortest_path_in_binary_matrix/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 22 | 69.99
+| 0130 |[Surrounded Regions](src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 2 | 84.66
+| 0797 |[All Paths From Source to Target](src/main/java/g0701_0800/s0797_all_paths_from_source_to_target/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 2 | 90.53
-#### Day 9 Binary Search Tree
+#### Day 9 Recursion Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
-| 0230 |[Kth Smallest Element in a BST](src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 78.91
-| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 18 | 84.18
+| 0078 |[Subsets](src/main/java/g0001_0100/s0078_subsets/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00
+| 0090 |[Subsets II](src/main/java/g0001_0100/s0090_subsets_ii/Solution.java)| Medium | Array, Bit_Manipulation, Backtracking | 2 | 82.94
-#### Day 10 Graph/BFS/DFS
+#### Day 10 Recursion Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0994 |[Rotting Oranges](src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 3 | 74.27
-| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
+| 0047 |[Permutations II](src/main/java/g0001_0100/s0047_permutations_ii/Solution.java)| Medium | Array, Backtracking | 1 | 99.86
+| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 99.99
+| 0040 |[Combination Sum II](src/main/java/g0001_0100/s0040_combination_sum_ii/Solution.java)| Medium | Array, Backtracking | 2 | 99.75
-#### Day 11 Graph/BFS/DFS
+#### Day 11 Recursion Backtracking
| | | | | |
|-|-|-|-|-|-
-| 0210 |[Course Schedule II](src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 13 | 35.17
-| 0815 |[Bus Routes](src/main/java/g0801_0900/s0815_bus_routes/Solution.java)| Hard | Array, Hash_Table, Breadth_First_Search | 49 | 89.11
+| 0017 |[Letter Combinations of a Phone Number](src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
+| 0022 |[Generate Parentheses](src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
+| 0079 |[Word Search](src/main/java/g0001_0100/s0079_word_search/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 64 | 98.51
#### Day 12 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 17 | 91.77
+| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
#### Day 13 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0416 |[Partition Equal Subset Sum](src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 27 | 94.53
-| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 0045 |[Jump Game II](src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
-#### Day 14 Sliding Window/Two Pointer
+#### Day 14 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 2 | 99.88
-| 0016 |[3Sum Closest](src/main/java/g0001_0100/s0016_3sum_closest/Solution.java)| Medium | Array, Sorting, Two_Pointers | 3 | 99.88
-| 0076 |[Minimum Window Substring](src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 2 | 99.94
+| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.82
+| 0413 |[Arithmetic Slices](src/main/java/g0401_0500/s0413_arithmetic_slices/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
-#### Day 15 Tree
+#### Day 15 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0100 |[Same Tree](src/main/java/g0001_0100/s0100_same_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
-| 0101 |[Symmetric Tree](src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-| 0199 |[Binary Tree Right Side View](src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 94.57
+| 0091 |[Decode Ways](src/main/java/g0001_0100/s0091_decode_ways/Solution.java)| Medium | Top_Interview_Questions, String, Dynamic_Programming | 2 | 66.37
+| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 1 | 99.42
-#### Day 16 Design
+#### Day 16 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
-| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 3 | 100.00
-| 0208 |[Implement Trie (Prefix Tree)](src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 34 | 99.90
+| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 95.75
+| 0673 |[Number of Longest Increasing Subsequence](src/main/java/g0601_0700/s0673_number_of_longest_increasing_subsequence/Solution.java)| Medium | Array, Dynamic_Programming, Segment_Tree, Binary_Indexed_Tree | 25 | 68.75
-#### Day 17 Interval
+#### Day 17 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0057 |[Insert Interval](src/main/java/g0001_0100/s0057_insert_interval/Solution.java)| Medium | Array | 0 | 100.00
-| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 8 | 96.27
+| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 19 | 89.05
+| 0583 |[Delete Operation for Two Strings](src/main/java/g0501_0600/s0583_delete_operation_for_two_strings/Solution.java)| Medium | String, Dynamic_Programming | 12 | 79.10
-#### Day 18 Stack
+#### Day 18 Dynamic Programming
| | | | | |
|-|-|-|-|-|-
-| 0735 |[Asteroid Collision](src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java)| Medium | Array, Stack | 2 | 99.59
-| 0227 |[Basic Calculator II](src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java)| Medium | Top_Interview_Questions, String, Math, Stack | 8 | 95.32
+| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 3 | 97.19
+| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 12 | 92.59
+| 0343 |[Integer Break](src/main/java/g0301_0400/s0343_integer_break/Solution.java)| Medium | Dynamic_Programming, Math | 0 | 100.00
-#### Day 19 Union Find
+#### Day 19 Bit Manipulation
| | | | | |
|-|-|-|-|-|-
-| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 2 | 69.51
-| 0947 |[Most Stones Removed with Same Row or Column](src/main/java/g0901_1000/s0947_most_stones_removed_with_same_row_or_column/Solution.java)| Medium | Depth_First_Search, Graph, Union_Find | 7 | 98.83
+| 0201 |[Bitwise AND of Numbers Range](src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java)| Medium | Bit_Manipulation | 3 | 100.00
-#### Day 20 Brute Force/Backtracking
+#### Day 20 Others
| | | | | |
|-|-|-|-|-|-
-| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00
-| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 95.07
+| 0384 |[Shuffle an Array](src/main/java/g0301_0400/s0384_shuffle_an_array/Solution.java)| Medium | Array, Math, Randomized | 52 | 91.77
-### Udemy
+#### Day 21 Others
-#### Udemy Integers
+| | | | | |
+|-|-|-|-|-|-
+| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
+| 0149 |[Max Points on a Line](src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 7 | 99.18
+
+### Binary Search I
+
+#### Day 1
| | | | | |
|-|-|-|-|-|-
-| 0412 |[Fizz Buzz](src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java)| Easy | Top_Interview_Questions, String, Math, Simulation | 1 | 100.00
-| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.97
-| 0007 |[Reverse Integer](src/main/java/g0001_0100/s0007_reverse_integer/Solution.java)| Medium | Top_Interview_Questions, Math | 1 | 99.69
-| 0009 |[Palindrome Number](src/main/java/g0001_0100/s0009_palindrome_number/Solution.java)| Easy | Math | 4 | 100.00
-| 0172 |[Factorial Trailing Zeroes](src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java)| Medium | Top_Interview_Questions, Math | 1 | 85.61
-| 0050 |[Pow(x, n)](src/main/java/g0001_0100/s0050_powx_n/Solution.java)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
+| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
+| 0374 |[Guess Number Higher or Lower](src/main/java/g0301_0400/s0374_guess_number_higher_or_lower/Solution.java)| Easy | Binary_Search, Interactive, LeetCode_75_Binary_Search | 0 | 100.00
-#### Udemy Strings
+#### Day 2
| | | | | |
|-|-|-|-|-|-
-| 0344 |[Reverse String](src/main/java/g0301_0400/s0344_reverse_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, Recursion | 1 | 99.91
-| 0014 |[Longest Common Prefix](src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java)| Easy | Top_Interview_Questions, String | 0 | 100.00
-| 0187 |[Repeated DNA Sequences](src/main/java/g0101_0200/s0187_repeated_dna_sequences/Solution.java)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash | 29 | 77.11
-| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 2 | 99.88
-| 0020 |[Valid Parentheses](src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 90.49
-| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.94
-| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 1 | 87.68
-| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | Top_Interview_Questions, String, Hash_Table, Sorting | 2 | 99.01
-| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 92.28
-| 0151 |[Reverse Words in a String](src/main/java/g0101_0200/s0151_reverse_words_in_a_string/Solution.java)| Medium | String, Two_Pointers | 2 | 99.94
-| 0273 |[Integer to English Words](src/main/java/g0201_0300/s0273_integer_to_english_words/Solution.java)| Hard | String, Math, Recursion | 3 | 95.67
+| 0035 |[Search Insert Position](src/main/java/g0001_0100/s0035_search_insert_position/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0852 |[Peak Index in a Mountain Array](src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java)| Medium | Array, Binary_Search | 0 | 100.00
-#### Udemy Binary Search
+#### Day 3
| | | | | |
|-|-|-|-|-|-
-| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
+| 0367 |[Valid Perfect Square](src/main/java/g0301_0400/s0367_valid_perfect_square/Solution.java)| Easy | Math, Binary_Search | 0 | 100.00
+| 1385 |[Find the Distance Value Between Two Arrays](src/main/java/g1301_1400/s1385_find_the_distance_value_between_two_arrays/Solution.java)| Easy | Array, Sorting, Binary_Search, Two_Pointers | 5 | 65.78
-#### Udemy Arrays
+#### Day 4
| | | | | |
|-|-|-|-|-|-
-| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
-| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 79.54
-| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 99.37
-| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
-| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java)| Easy | String | 0 | 100.00
-| 0605 |[Can Place Flowers](src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java)| Easy | Array, Greedy | 1 | 96.77
-| 0122 |[Best Time to Buy and Sell Stock II](src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 1 | 96.82
-| 0080 |[Remove Duplicates from Sorted Array II](src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java)| Medium | Array, Two_Pointers | 0 | 100.00
-| 0189 |[Rotate Array](src/main/java/g0101_0200/s0189_rotate_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 2 | 79.47
-| 0075 |[Sort Colors](src/main/java/g0001_0100/s0075_sort_colors/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0066 |[Plus One](src/main/java/g0001_0100/s0066_plus_one/Solution.java)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
-| 0238 |[Product of Array Except Self](src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 1 | 100.00
-| 1291 |[Sequential Digits](src/main/java/g1201_1300/s1291_sequential_digits/Solution.java)| Medium | Enumeration | 0 | 100.00
-| 0448 |[Find All Numbers Disappeared in an Array](src/main/java/g0401_0500/s0448_find_all_numbers_disappeared_in_an_array/Solution.java)| Easy | Array, Hash_Table | 3 | 100.00
-| 0442 |[Find All Duplicates in an Array](src/main/java/g0401_0500/s0442_find_all_duplicates_in_an_array/Solution.java)| Medium | Array, Hash_Table | 5 | 98.83
-| 0041 |[First Missing Positive](src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 57.59
-| 0697 |[Degree of an Array](src/main/java/g0601_0700/s0697_degree_of_an_array/Solution.java)| Easy | Array, Hash_Table | 14 | 93.19
-| 0532 |[K-diff Pairs in an Array](src/main/java/g0501_0600/s0532_k_diff_pairs_in_an_array/Solution.java)| Medium | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 13 | 58.23
-| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
-| 1007 |[Minimum Domino Rotations For Equal Row](src/main/java/g1001_1100/s1007_minimum_domino_rotations_for_equal_row/Solution.java)| Medium | Array, Greedy | 5 | 79.64
-| 1306 |[Jump Game III](src/main/java/g1301_1400/s1306_jump_game_iii/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search | 2 | 96.23
-| 0456 |[132 Pattern](src/main/java/g0401_0500/s0456_132_pattern/Solution.java)| Medium | Array, Binary_Search, Stack, Ordered_Set, Monotonic_Stack | 16 | 82.41
-| 0239 |[Sliding Window Maximum](src/main/java/g0201_0300/s0239_sliding_window_maximum/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Big_O_Time_O(n\*k)_Space_O(n+k) | 58 | 52.28
+| 0069 |[Sqrt(x)](src/main/java/g0001_0100/s0069_sqrtx/Solution.java)| Easy | Top_Interview_Questions, Math, Binary_Search | 1 | 86.67
+| 0744 |[Find Smallest Letter Greater Than Target](src/main/java/g0701_0800/s0744_find_smallest_letter_greater_than_target/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-#### Udemy Two Pointers
+#### Day 5
| | | | | |
|-|-|-|-|-|-
-| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers | 1 | 93.01
-| 0125 |[Valid Palindrome](src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers | 3 | 98.64
-| 0977 |[Squares of a Sorted Array](src/main/java/g0901_1000/s0977_squares_of_a_sorted_array/Solution.java)| Easy | Array, Sorting, Two_Pointers | 1 | 100.00
-| 0026 |[Remove Duplicates from Sorted Array](src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Two_Pointers | 1 | 98.56
-| 0042 |[Trapping Rain Water](src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 27 | 97.93
+| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
+| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-#### Udemy Famous Algorithm
+#### Day 6
| | | | | |
|-|-|-|-|-|-
-| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
-| 0169 |[Majority Element](src/main/java/g0101_0200/s0169_majority_element/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 0441 |[Arranging Coins](src/main/java/g0401_0500/s0441_arranging_coins/Solution.java)| Easy | Math, Binary_Search | 2 | 95.97
+| 1539 |[Kth Missing Positive Number](src/main/java/g1501_1600/s1539_kth_missing_positive_number/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-#### Udemy Sorting Algorithms
+#### Day 7
| | | | | |
|-|-|-|-|-|-
-| 0912 |[Sort an Array](src/main/java/g0901_1000/s0912_sort_an_array/Solution.java)| Medium | Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Merge_Sort, Bucket_Sort, Counting_Sort, Radix_Sort | 25 | 38.15
+| 0167 |[Two Sum II - Input Array Is Sorted](src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers | 2 | 92.62
+| 1608 |[Special Array With X Elements Greater Than or Equal X](src/main/java/g1601_1700/s1608_special_array_with_x_elements_greater_than_or_equal_x/Solution.java)| Easy | Array, Sorting, Binary_Search | 2 | 61.14
-#### Udemy 2D Arrays/Matrix
+#### Day 8
| | | | | |
|-|-|-|-|-|-
-| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
+| 1351 |[Count Negative Numbers in a Sorted Matrix](src/main/java/g1301_1400/s1351_count_negative_numbers_in_a_sorted_matrix/Solution.java)| Easy | Array, Binary_Search, Matrix | 1 | 49.66
| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
-| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
-| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
-| 1572 |[Matrix Diagonal Sum](src/main/java/g1501_1600/s1572_matrix_diagonal_sum/Solution.java)| Easy | Array, Matrix | 0 | 100.00
-| 0073 |[Set Matrix Zeroes](src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 1 | 79.07
-| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 8 | 96.27
-#### Udemy Linked List
+#### Day 9
| | | | | |
|-|-|-|-|-|-
-| 0114 |[Flatten Binary Tree to Linked List](src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 1 | 75.27
-| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii/Solution.java)| Medium | Math, Stack, Linked_List | 3 | 90.38
-| 0328 |[Odd Even Linked List](src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java)| Medium | Top_Interview_Questions, Linked_List | 0 | 100.00
-| 0061 |[Rotate List](src/main/java/g0001_0100/s0061_rotate_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
-| 0024 |[Swap Nodes in Pairs](src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
-| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0141 |[Linked List Cycle](src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
-| 0160 |[Intersection of Two Linked Lists](src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 1 | 99.68
-| 0234 |[Palindrome Linked List](src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 6 | 76.07
-| 0138 |[Copy List with Random Pointer](src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
-| 0025 |[Reverse Nodes in k-Group](src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
-| 0146 |[LRU Cache](src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 87 | 50.80
-| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
+| 1337 |[The K Weakest Rows in a Matrix](src/main/java/g1301_1400/s1337_the_k_weakest_rows_in_a_matrix/Solution.java)| Easy | Array, Sorting, Binary_Search, Matrix, Heap_Priority_Queue | 1 | 99.77
+| 1346 |[Check If N and Its Double Exist](src/main/java/g1301_1400/s1346_check_if_n_and_its_double_exist/Solution.java)| Easy | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 1 | 99.64
-#### Udemy Tree Stack Queue
+#### Day 10
| | | | | |
|-|-|-|-|-|-
-| 0144 |[Binary Tree Preorder Traversal](src/main/java/g0101_0200/s0144_binary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 48.38
-| 0094 |[Binary Tree Inorder Traversal](src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0145 |[Binary Tree Postorder Traversal](src/main/java/g0101_0200/s0145_binary_tree_postorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 49.11
-| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.09
-| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 1 | 95.00
-| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
-| 1008 |[Construct Binary Search Tree from Preorder Traversal](src/main/java/g1001_1100/s1008_construct_binary_search_tree_from_preorder_traversal/Solution.java)| Medium | Array, Tree, Binary_Tree, Stack, Monotonic_Stack, Binary_Search_Tree | 0 | 100.00
-| 0543 |[Diameter of Binary Tree](src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 65.86
-| 0938 |[Range Sum of BST](src/main/java/g0901_1000/s0938_range_sum_of_bst/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
-| 0100 |[Same Tree](src/main/java/g0001_0100/s0100_same_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
-| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0111 |[Minimum Depth of Binary Tree](src/main/java/g0101_0200/s0111_minimum_depth_of_binary_tree/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 97.49
-| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
-| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
-| 0701 |[Insert into a Binary Search Tree](src/main/java/g0701_0800/s0701_insert_into_a_binary_search_tree/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
-| 0297 |[Serialize and Deserialize Binary Tree](src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java)| Hard | Top_Interview_Questions, String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design | 7 | 98.13
-| 0124 |[Binary Tree Maximum Path Sum](src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 99.46
-| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-| 0337 |[House Robber III](src/main/java/g0301_0400/s0337_house_robber_iii/Solution.java)| Medium | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 1 | 91.77
-| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 10 | 56.51
-| 0968 |[Binary Tree Cameras](src/main/java/g0901_1000/s0968_binary_tree_cameras/Solution.java)| Hard | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0350 |[Intersection of Two Arrays II](src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java)| Easy | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 4 | 69.62
+| 0633 |[Sum of Square Numbers](src/main/java/g0601_0700/s0633_sum_of_square_numbers/Solution.java)| Medium | Math, Binary_Search, Two_Pointers | 4 | 82.92
-#### Udemy Trie and Heap
+#### Day 11
| | | | | |
|-|-|-|-|-|-
-| 0208 |[Implement Trie (Prefix Tree)](src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 34 | 99.90
-| 0745 |[Prefix and Suffix Search](src/main/java/g0701_0800/s0745_prefix_and_suffix_search/WordFilter.java)| Hard | String, Design, Trie | 366 | 76.15
+| 1855 |[Maximum Distance Between a Pair of Values](src/main/java/g1801_1900/s1855_maximum_distance_between_a_pair_of_values/Solution.java)| Medium | Array, Greedy, Binary_Search, Two_Pointers | 4 | 62.20
+| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-#### Udemy Graph
+#### Day 12
| | | | | |
|-|-|-|-|-|-
-| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
-| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 45 | 29.80
-| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
+| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
-#### Udemy Dynamic Programming
+### Binary Search II
+
+#### Day 1
+
+| | | | | |
+|-|-|-|-|-|-
+| 0209 |[Minimum Size Subarray Sum](src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 1 | 99.76
+| 0611 |[Valid Triangle Number](src/main/java/g0601_0700/s0611_valid_triangle_number/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 10 | 100.00
+
+#### Day 2
+
+| | | | | |
+|-|-|-|-|-|-
+| 0658 |[Find K Closest Elements](src/main/java/g0601_0700/s0658_find_k_closest_elements/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers, Heap_Priority_Queue | 3 | 99.20
+| 1894 |[Find the Student that Will Replace the Chalk](src/main/java/g1801_1900/s1894_find_the_student_that_will_replace_the_chalk/Solution.java)| Medium | Array, Binary_Search, Simulation, Prefix_Sum | 2 | 76.67
+
+#### Day 3
+
+| | | | | |
+|-|-|-|-|-|-
+| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 95.75
+| 1760 |[Minimum Limit of Balls in a Bag](src/main/java/g1701_1800/s1760_minimum_limit_of_balls_in_a_bag/Solution.java)| Medium | Array, Binary_Search | 44 | 78.49
+
+#### Day 4
+
+| | | | | |
+|-|-|-|-|-|-
+| 0875 |[Koko Eating Bananas](src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java)| Medium | Array, Binary_Search, LeetCode_75_Binary_Search | 15 | 91.32
+| 1552 |[Magnetic Force Between Two Balls](src/main/java/g1501_1600/s1552_magnetic_force_between_two_balls/Solution.java)| Medium | Array, Sorting, Binary_Search | 39 | 99.65
+
+#### Day 5
+
+| | | | | |
+|-|-|-|-|-|-
+| 0287 |[Find the Duplicate Number](src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 2 | 97.52
+| 1283 |[Find the Smallest Divisor Given a Threshold](src/main/java/g1201_1300/s1283_find_the_smallest_divisor_given_a_threshold/Solution.java)| Medium | Array, Binary_Search | 9 | 95.49
+
+#### Day 6
+
+| | | | | |
+|-|-|-|-|-|-
+| 1898 |[Maximum Number of Removable Characters](src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java)| Medium | Array, String, Binary_Search | 121 | 72.51
+| 1870 |[Minimum Speed to Arrive on Time](src/main/java/g1801_1900/s1870_minimum_speed_to_arrive_on_time/Solution.java)| Medium | Array, Binary_Search | 86 | 88.58
+
+#### Day 7
+
+| | | | | |
+|-|-|-|-|-|-
+| 1482 |[Minimum Number of Days to Make m Bouquets](src/main/java/g1401_1500/s1482_minimum_number_of_days_to_make_m_bouquets/Solution.java)| Medium | Array, Binary_Search | 25 | 69.18
+| 1818 |[Minimum Absolute Sum Difference](src/main/java/g1801_1900/s1818_minimum_absolute_sum_difference/Solution.java)| Medium | Array, Sorting, Binary_Search, Ordered_Set | 13 | 99.44
+
+#### Day 8
+
+| | | | | |
+|-|-|-|-|-|-
+| 0240 |[Search a 2D Matrix II](src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 5 | 99.92
+| 0275 |[H-Index II](src/main/java/g0201_0300/s0275_h_index_ii/Solution.java)| Medium | Array, Binary_Search | 0 | 100.00
+
+#### Day 9
+
+| | | | | |
+|-|-|-|-|-|-
+| 1838 |[Frequency of the Most Frequent Element](src/main/java/g1801_1900/s1838_frequency_of_the_most_frequent_element/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Prefix_Sum, Sliding_Window | 11 | 100.00
+| 0540 |[Single Element in a Sorted Array](src/main/java/g0501_0600/s0540_single_element_in_a_sorted_array/Solution.java)| Medium | Array, Binary_Search | 0 | 100.00
+
+#### Day 10
+
+| | | | | |
+|-|-|-|-|-|-
+| 0222 |[Count Complete Tree Nodes](src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree | 0 | 100.00
+| 1712 |[Ways to Split Array Into Three Subarrays](src/main/java/g1701_1800/s1712_ways_to_split_array_into_three_subarrays/Solution.java)| Medium | Array, Binary_Search, Two_Pointers, Prefix_Sum | 16 | 84.24
+
+#### Day 11
+
+| | | | | |
+|-|-|-|-|-|-
+| 0826 |[Most Profit Assigning Work](src/main/java/g0801_0900/s0826_most_profit_assigning_work/Solution.java)| Medium | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 21 | 83.83
+| 0436 |[Find Right Interval](src/main/java/g0401_0500/s0436_find_right_interval/Solution.java)| Medium | Array, Sorting, Binary_Search | 20 | 81.51
+
+#### Day 12
+
+| | | | | |
+|-|-|-|-|-|-
+| 0081 |[Search in Rotated Sorted Array II](src/main/java/g0001_0100/s0081_search_in_rotated_sorted_array_ii/Solution.java)| Medium | Array, Binary_Search | 1 | 82.83
+| 0162 |[Find Peak Element](src/main/java/g0101_0200/s0162_find_peak_element/Solution.java)| Medium | Top_Interview_Questions, Array, Binary_Search, LeetCode_75_Binary_Search | 0 | 100.00
+
+#### Day 13
+
+| | | | | |
+|-|-|-|-|-|-
+| 0154 |[Find Minimum in Rotated Sorted Array II](src/main/java/g0101_0200/s0154_find_minimum_in_rotated_sorted_array_ii/Solution.java)| Hard | Array, Binary_Search | 1 | 77.09
+| 0528 |[Random Pick with Weight](src/main/java/g0501_0600/s0528_random_pick_with_weight/Solution.java)| Medium | Math, Binary_Search, Prefix_Sum, Randomized | 42 | 50.90
+
+#### Day 14
+
+| | | | | |
+|-|-|-|-|-|-
+| 1508 |[Range Sum of Sorted Subarray Sums](src/main/java/g1501_1600/s1508_range_sum_of_sorted_subarray_sums/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 60 | 93.84
+| 1574 |[Shortest Subarray to be Removed to Make Array Sorted](src/main/java/g1501_1600/s1574_shortest_subarray_to_be_removed_to_make_array_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers, Stack, Monotonic_Stack | 2 | 84.97
+
+#### Day 15
+
+| | | | | |
+|-|-|-|-|-|-
+| 1292 |[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](src/main/java/g1201_1300/s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold/Solution.java)| Medium | Array, Binary_Search, Matrix, Prefix_Sum | 23 | 32.97
+| 1498 |[Number of Subsequences That Satisfy the Given Sum Condition](src/main/java/g1401_1500/s1498_number_of_subsequences_that_satisfy_the_given_sum_condition/Solution.java)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 27 | 99.13
+
+#### Day 16
+
+| | | | | |
+|-|-|-|-|-|-
+| 0981 |[Time Based Key-Value Store](src/main/java/g0901_1000/s0981_time_based_key_value_store/TimeMap.java)| Medium | String, Hash_Table, Binary_Search, Design | 239 | 72.78
+| 1300 |[Sum of Mutated Array Closest to Target](src/main/java/g1201_1300/s1300_sum_of_mutated_array_closest_to_target/Solution.java)| Medium | Array, Sorting, Binary_Search | 7 | 33.33
+
+#### Day 17
+
+| | | | | |
+|-|-|-|-|-|-
+| 1802 |[Maximum Value at a Given Index in a Bounded Array](src/main/java/g1801_1900/s1802_maximum_value_at_a_given_index_in_a_bounded_array/Solution.java)| Medium | Greedy, Binary_Search | 2 | 58.44
+| 1901 |[Find a Peak Element II](src/main/java/g1901_2000/s1901_find_a_peak_element_ii/Solution.java)| Medium | Array, Binary_Search, Matrix, Divide_and_Conquer | 0 | 100.00
+
+#### Day 18
+
+| | | | | |
+|-|-|-|-|-|-
+| 1146 |[Snapshot Array](src/main/java/g1101_1200/s1146_snapshot_array/SnapshotArray.java)| Medium | Array, Hash_Table, Binary_Search, Design | 68 | 45.86
+| 1488 |[Avoid Flood in The City](src/main/java/g1401_1500/s1488_avoid_flood_in_the_city/Solution.java)| Medium | Array, Hash_Table, Greedy, Binary_Search, Heap_Priority_Queue | 82 | 75.08
+
+#### Day 19
+
+| | | | | |
+|-|-|-|-|-|-
+| 1562 |[Find Latest Group of Size M](src/main/java/g1501_1600/s1562_find_latest_group_of_size_m/Solution.java)| Medium | Array, Binary_Search, Simulation | 8 | 90.00
+| 1648 |[Sell Diminishing-Valued Colored Balls](src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java)| Medium | Array, Math, Sorting, Greedy, Binary_Search, Heap_Priority_Queue | 27 | 80.64
+
+#### Day 20
+
+| | | | | |
+|-|-|-|-|-|-
+| 1201 |[Ugly Number III](src/main/java/g1201_1300/s1201_ugly_number_iii/Solution.java)| Medium | Math, Binary_Search, Number_Theory | 0 | 100.00
+| 0911 |[Online Election](src/main/java/g0901_1000/s0911_online_election/TopVotedCandidate.java)| Medium | Array, Hash_Table, Binary_Search, Design | 63 | 98.81
+
+### Dynamic Programming I
+
+#### Day 1
| | | | | |
|-|-|-|-|-|-
-| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 2 | 94.63
-| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
-| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
-| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 2 | 97.08
-| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
+| 1137 |[N-th Tribonacci Number](src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Memoization, LeetCode_75_DP/1D | 0 | 100.00
+
+#### Day 2
+
+| | | | | |
+|-|-|-|-|-|-
| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0064 |[Minimum Path Sum](src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
-| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 98.63
-| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 33 | 46.23
-| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 4 | 90.13
-| 0044 |[Wildcard Matching](src/main/java/g0001_0100/s0044_wildcard_matching/Solution.java)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Greedy, Recursion | 2 | 99.87
-| 0010 |[Regular Expression Matching](src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 100.00
+| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming, LeetCode_75_DP/1D | 1 | 86.38
-#### Udemy Backtracking/Recursion
+#### Day 3
| | | | | |
|-|-|-|-|-|-
-| 0022 |[Generate Parentheses](src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
-| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00
-| 0216 |[Combination Sum III](src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java)| Medium | Array, Backtracking | 1 | 81.35
-| 0078 |[Subsets](src/main/java/g0001_0100/s0078_subsets/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 1 | 70.60
-| 0017 |[Letter Combinations of a Phone Number](src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
-| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 95.07
+| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, LeetCode_75_DP/1D, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
+| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 0740 |[Delete and Earn](src/main/java/g0701_0800/s0740_delete_and_earn/Solution.java)| Medium | Array, Hash_Table, Dynamic_Programming | 4 | 77.68
-#### Udemy Bit Manipulation
+#### Day 4
| | | | | |
|-|-|-|-|-|-
-| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 1 | 84.87
-| 0389 |[Find the Difference](src/main/java/g0301_0400/s0389_find_the_difference/Solution.java)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 1 | 100.00
-| 0190 |[Reverse Bits](src/main/java/g0101_0200/s0190_reverse_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 1 | 98.66
-| 0461 |[Hamming Distance](src/main/java/g0401_0500/s0461_hamming_distance/Solution.java)| Easy | Bit_Manipulation | 0 | 100.00
-| 1009 |[Complement of Base 10 Integer](src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java)| Easy | Bit_Manipulation | 1 | 41.56
-| 0338 |[Counting Bits](src/main/java/g0301_0400/s0338_counting_bits/Solution.java)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 2 | 86.73
-| 0371 |[Sum of Two Integers](src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java)| Medium | Top_Interview_Questions, Math, Bit_Manipulation | 0 | 100.00
-| 0029 |[Divide Two Integers](src/main/java/g0001_0100/s0029_divide_two_integers/Solution.java)| Medium | Top_Interview_Questions, Math, Bit_Manipulation | 1 | 97.44
+| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 0045 |[Jump Game II](src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-#### Udemy Design
+#### Day 5
| | | | | |
|-|-|-|-|-|-
-| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 3 | 100.00
+| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 99.32
+| 0918 |[Maximum Sum Circular Subarray](src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java)| Medium | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Monotonic_Queue | 2 | 99.34
-### Data Structure I
+#### Day 6
-#### Day 1 Array
+| | | | | |
+|-|-|-|-|-|-
+| 0152 |[Maximum Product Subarray](src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 92.74
+| 1567 |[Maximum Length of Subarray With Positive Product](src/main/java/g1501_1600/s1567_maximum_length_of_subarray_with_positive_product/Solution.java)| Medium | Array, Dynamic_Programming, Greedy | 4 | 80.86
+
+#### Day 7
| | | | | |
|-|-|-|-|-|-
-| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
-| 0053 |[Maximum Subarray](src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 1014 |[Best Sightseeing Pair](src/main/java/g1001_1100/s1014_best_sightseeing_pair/Solution.java)| Medium | Array, Dynamic_Programming | 2 | 99.86
+| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 99.78
+| 0122 |[Best Time to Buy and Sell Stock II](src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 1 | 76.91
-#### Day 2 Array
+#### Day 8
| | | | | |
|-|-|-|-|-|-
-| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 99.37
-| 0088 |[Merge Sorted Array](src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00
+| 0309 |[Best Time to Buy and Sell Stock with Cooldown](src/main/java/g0301_0400/s0309_best_time_to_buy_and_sell_stock_with_cooldown/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 0714 |[Best Time to Buy and Sell Stock with Transaction Fee](src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java)| Medium | Array, Dynamic_Programming, Greedy, LeetCode_75_DP/Multidimensional | 4 | 78.57
-#### Day 3 Array
+#### Day 9
| | | | | |
|-|-|-|-|-|-
-| 0350 |[Intersection of Two Arrays II](src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 4 | 69.62
-| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
+| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 1 | 99.42
+| 0042 |[Trapping Rain Water](src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-#### Day 4 Array
+#### Day 10
| | | | | |
|-|-|-|-|-|-
-| 0566 |[Reshape the Matrix](src/main/java/g0501_0600/s0566_reshape_the_matrix/Solution.java)| Easy | Array, Matrix, Simulation | 1 | 90.08
-| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
+| 0413 |[Arithmetic Slices](src/main/java/g0401_0500/s0413_arithmetic_slices/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 0091 |[Decode Ways](src/main/java/g0001_0100/s0091_decode_ways/Solution.java)| Medium | Top_Interview_Questions, String, Dynamic_Programming | 2 | 66.37
-#### Day 5 Array
+#### Day 11
| | | | | |
|-|-|-|-|-|-
-| 0036 |[Valid Sudoku](src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java)| Medium | Top_Interview_Questions, Array, Hash_Table, Matrix | 1 | 100.00
-| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 0264 |[Ugly Number II](src/main/java/g0201_0300/s0264_ugly_number_ii/Solution.java)| Medium | Hash_Table, Dynamic_Programming, Math, Heap_Priority_Queue | 2 | 99.91
+| 0096 |[Unique Binary Search Trees](src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-#### Day 6 String
+#### Day 12
| | | | | |
|-|-|-|-|-|-
-| 0387 |[First Unique Character in a String](src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java)| Easy | Top_Interview_Questions, String, Hash_Table, Counting, Queue | 1 | 100.00
-| 0383 |[Ransom Note](src/main/java/g0301_0400/s0383_ransom_note/Solution.java)| Easy | String, Hash_Table, Counting | 1 | 99.97
-| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | Top_Interview_Questions, String, Hash_Table, Sorting | 2 | 99.01
+| 0118 |[Pascal's Triangle](src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 1 | 67.08
+| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
-#### Day 7 Linked List
+#### Day 13
| | | | | |
|-|-|-|-|-|-
-| 0141 |[Linked List Cycle](src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
-| 0203 |[Remove Linked List Elements](src/main/java/g0201_0300/s0203_remove_linked_list_elements/Solution.java)| Easy | Linked_List, Recursion | 1 | 98.82
+| 0931 |[Minimum Falling Path Sum](src/main/java/g0901_1000/s0931_minimum_falling_path_sum/Solution.java)| Medium | Array, Dynamic_Programming, Matrix | 4 | 72.19
+| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 99.79
-#### Day 8 Linked List
+#### Day 14
| | | | | |
|-|-|-|-|-|-
-| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
-| 0083 |[Remove Duplicates from Sorted List](src/main/java/g0001_0100/s0083_remove_duplicates_from_sorted_list/Solution.java)| Easy | Linked_List | 0 | 100.00
+| 1314 |[Matrix Block Sum](src/main/java/g1301_1400/s1314_matrix_block_sum/Solution.java)| Medium | Array, Matrix, Prefix_Sum | 5 | 67.46
+| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
-#### Day 9 Stack Queue
+#### Day 15
| | | | | |
|-|-|-|-|-|-
-| 0020 |[Valid Parentheses](src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 2 | 90.49
-| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
+| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, LeetCode_75_DP/Multidimensional, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
+| 0063 |[Unique Paths II](src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java)| Medium | Array, Dynamic_Programming, Matrix | 0 | 100.00
-#### Day 10 Tree
+#### Day 16
| | | | | |
|-|-|-|-|-|-
-| 0144 |[Binary Tree Preorder Traversal](src/main/java/g0101_0200/s0144_binary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 48.38
-| 0094 |[Binary Tree Inorder Traversal](src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0145 |[Binary Tree Postorder Traversal](src/main/java/g0101_0200/s0145_binary_tree_postorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Stack | 1 | 49.11
+| 0064 |[Minimum Path Sum](src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 1 | 99.73
+| 0221 |[Maximal Square](src/main/java/g0201_0300/s0221_maximal_square/Solution.java)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 6 | 97.07
-#### Day 11 Tree
+#### Day 17
| | | | | |
|-|-|-|-|-|-
-| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.09
-| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
-| 0101 |[Symmetric Tree](src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
+| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.82
+| 0516 |[Longest Palindromic Subsequence](src/main/java/g0501_0600/s0516_longest_palindromic_subsequence/Solution.java)| Medium | String, Dynamic_Programming | 88 | 58.87
-#### Day 12 Tree
+#### Day 18
| | | | | |
|-|-|-|-|-|-
-| 0226 |[Invert Binary Tree](src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0112 |[Path Sum](src/main/java/g0101_0200/s0112_path_sum/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
+| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 95.75
+| 0376 |[Wiggle Subsequence](src/main/java/g0301_0400/s0376_wiggle_subsequence/Solution.java)| Medium | Array, Dynamic_Programming, Greedy | 0 | 100.00
-#### Day 13 Tree
+#### Day 19
| | | | | |
|-|-|-|-|-|-
-| 0700 |[Search in a Binary Search Tree](src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java)| Easy | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
-| 0701 |[Insert into a Binary Search Tree](src/main/java/g0701_0800/s0701_insert_into_a_binary_search_tree/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
+| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers, LeetCode_75_Two_Pointers | 1 | 93.13
+| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n\*m)_Space_O(n\*m) | 19 | 89.05
+| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Big_O_Time_O(n^2)_Space_O(n2) | 3 | 97.19
-#### Day 14 Tree
+#### Day 20
| | | | | |
|-|-|-|-|-|-
-| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
-| 0653 |[Two Sum IV - Input is a BST](src/main/java/g0601_0700/s0653_two_sum_iv_input_is_a_bst/Solution.java)| Easy | Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Two_Pointers, Binary_Search_Tree | 5 | 74.23
-| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
+| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 12 | 92.59
+| 0518 |[Coin Change 2](src/main/java/g0501_0600/s0518_coin_change_2/Solution.java)| Medium | Array, Dynamic_Programming | 4 | 84.67
-### Data Structure II
+#### Day 21
-#### Day 1 Array
+| | | | | |
+|-|-|-|-|-|-
+| 0377 |[Combination Sum IV](src/main/java/g0301_0400/s0377_combination_sum_iv/Solution.java)| Medium | Array, Dynamic_Programming | 1 | 92.54
+| 0343 |[Integer Break](src/main/java/g0301_0400/s0343_integer_break/Solution.java)| Medium | Dynamic_Programming, Math | 0 | 100.00
+| 0279 |[Perfect Squares](src/main/java/g0201_0300/s0279_perfect_squares/Solution.java)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Breadth_First_Search | 1 | 100.00
+
+### Programming Skills I
+
+#### Day 1 Basic Data Type
| | | | | |
|-|-|-|-|-|-
-| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.97
-| 0169 |[Majority Element](src/main/java/g0101_0200/s0169_majority_element/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
-| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 27 | 97.93
+| 1523 |[Count Odd Numbers in an Interval Range](src/main/java/g1501_1600/s1523_count_odd_numbers_in_an_interval_range/Solution.java)| Easy | Math | 0 | 100.00
+| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](src/main/java/g1401_1500/s1491_average_salary_excluding_the_minimum_and_maximum_salary/Solution.java)| Easy | Array, Sorting | 0 | 100.00
-#### Day 2 Array
+#### Day 2 Operator
| | | | | |
|-|-|-|-|-|-
-| 0075 |[Sort Colors](src/main/java/g0001_0100/s0075_sort_colors/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0056 |[Merge Intervals](src/main/java/g0001_0100/s0056_merge_intervals/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 8 | 96.27
-| 0706 |[Design HashMap](src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java)| Easy | Array, Hash_Table, Design, Linked_List, Hash_Function | 13 | 95.71
+| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00
+| 1281 |[Subtract the Product and Sum of Digits of an Integer](src/main/java/g1201_1300/s1281_subtract_the_product_and_sum_of_digits_of_an_integer/Solution.java)| Easy | Math | 0 | 100.00
-#### Day 3 Array
+#### Day 3 Conditional Statements
| | | | | |
|-|-|-|-|-|-
-| 0119 |[Pascal's Triangle II](src/main/java/g0101_0200/s0119_pascals_triangle_ii/Solution.java)| Easy | Array, Dynamic_Programming | 0 | 100.00
-| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
-| 0059 |[Spiral Matrix II](src/main/java/g0001_0100/s0059_spiral_matrix_ii/Solution.java)| Medium | Array, Matrix, Simulation | 0 | 100.00
+| 0976 |[Largest Perimeter Triangle](src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java)| Easy | Array, Math, Sorting, Greedy | 7 | 99.33
+| 1779 |[Find Nearest Point That Has the Same X or Y Coordinate](src/main/java/g1701_1800/s1779_find_nearest_point_that_has_the_same_x_or_y_coordinate/Solution.java)| Easy | Array | 1 | 100.00
-#### Day 4 Array
+#### Day 4 Loop
| | | | | |
|-|-|-|-|-|-
-| 0240 |[Search a 2D Matrix II](src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 7 | 86.73
-| 0435 |[Non-overlapping Intervals](src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java)| Medium | Array, Dynamic_Programming, Sorting, Greedy | 96 | 47.37
+| 1822 |[Sign of the Product of an Array](src/main/java/g1801_1900/s1822_sign_of_the_product_of_an_array/Solution.java)| Easy | Array, Math | 1 | 58.05
+| 1502 |[Can Make Arithmetic Progression From Sequence](src/main/java/g1501_1600/s1502_can_make_arithmetic_progression_from_sequence/Solution.java)| Easy | Array, Sorting | 2 | 90.55
+| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
+| 1790 |[Check if One String Swap Can Make Strings Equal](src/main/java/g1701_1800/s1790_check_if_one_string_swap_can_make_strings_equal/Solution.java)| Easy | String, Hash_Table, Counting | 0 | 100.00
-#### Day 5 Array
+#### Day 5 Function
| | | | | |
|-|-|-|-|-|-
-| 0334 |[Increasing Triplet Subsequence](src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java)| Medium | Top_Interview_Questions, Array, Greedy | 2 | 99.33
-| 0238 |[Product of Array Except Self](src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 1 | 100.00
-| 0560 |[Subarray Sum Equals K](src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 21 | 98.97
+| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
+| 0496 |[Next Greater Element I](src/main/java/g0401_0500/s0496_next_greater_element_i/Solution.java)| Easy | Array, Hash_Table, Stack, Monotonic_Stack | 4 | 81.18
+| 1232 |[Check If It Is a Straight Line](src/main/java/g1201_1300/s1232_check_if_it_is_a_straight_line/Solution.java)| Easy | Array, Math, Geometry | 0 | 100.00
-#### Day 6 String
+#### Day 6 Array
| | | | | |
|-|-|-|-|-|-
-| 0415 |[Add Strings](src/main/java/g0401_0500/s0415_add_strings/Solution.java)| Easy | String, Math, Simulation | 3 | 82.41
-| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
+| 1588 |[Sum of All Odd Length Subarrays](src/main/java/g1501_1600/s1588_sum_of_all_odd_length_subarrays/Solution.java)| Easy | Array, Math, Prefix_Sum | 0 | 100.00
+| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 83.99
+| 1672 |[Richest Customer Wealth](src/main/java/g1601_1700/s1672_richest_customer_wealth/Solution.java)| Easy | Array, Matrix | 0 | 100.00
-#### Day 7 String
+#### Day 7 Array
| | | | | |
|-|-|-|-|-|-
-| 0290 |[Word Pattern](src/main/java/g0201_0300/s0290_word_pattern/Solution.java)| Easy | String, Hash_Table | 1 | 97.26
-| 0763 |[Partition Labels](src/main/java/g0701_0800/s0763_partition_labels/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 100.00
+| 1572 |[Matrix Diagonal Sum](src/main/java/g1501_1600/s1572_matrix_diagonal_sum/Solution.java)| Easy | Array, Matrix | 0 | 100.00
+| 0566 |[Reshape the Matrix](src/main/java/g0501_0600/s0566_reshape_the_matrix/Solution.java)| Easy | Array, Matrix, Simulation | 1 | 90.08
#### Day 8 String
| | | | | |
|-|-|-|-|-|-
-| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 92.28
-| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
+| 1768 |[Merge Strings Alternately](src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java)| Easy | String, Two_Pointers, LeetCode_75_Array/String | 1 | 86.26
+| 1678 |[Goal Parser Interpretation](src/main/java/g1601_1700/s1678_goal_parser_interpretation/Solution.java)| Easy | String | 0 | 100.00
+| 0389 |[Find the Difference](src/main/java/g0301_0400/s0389_find_the_difference/Solution.java)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 1 | 100.00
#### Day 9 String
| | | | | |
|-|-|-|-|-|-
-| 0187 |[Repeated DNA Sequences](src/main/java/g0101_0200/s0187_repeated_dna_sequences/Solution.java)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash | 29 | 77.11
-| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.94
+| 0709 |[To Lower Case](src/main/java/g0701_0800/s0709_to_lower_case/Solution.java)| Easy | String | 1 | 71.74
+| 1309 |[Decrypt String from Alphabet to Integer Mapping](src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java)| Easy | String | 0 | 100.00
+| 0953 |[Verifying an Alien Dictionary](src/main/java/g0901_1000/s0953_verifying_an_alien_dictionary/Solution.java)| Easy | Array, String, Hash_Table | 0 | 100.00
-#### Day 10 Linked List
+#### Day 10 Linked List and Tree
| | | | | |
|-|-|-|-|-|-
-| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 1 | 100.00
-| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 1290 |[Convert Binary Number in a Linked List to Integer](src/main/java/g1201_1300/s1290_convert_binary_number_in_a_linked_list_to_integer/Solution.java)| Easy | Math, Linked_List | 0 | 100.00
+| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
+| 0104 |[Maximum Depth of Binary Tree](src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
+| 0404 |[Sum of Left Leaves](src/main/java/g0401_0500/s0404_sum_of_left_leaves/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 29.26
-#### Day 11 Linked List
+#### Day 11 Containers and Libraries
| | | | | |
|-|-|-|-|-|-
-| 0160 |[Intersection of Two Linked Lists](src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 1 | 99.68
-| 0082 |[Remove Duplicates from Sorted List II](src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 1356 |[Sort Integers by The Number of 1 Bits](src/main/java/g1301_1400/s1356_sort_integers_by_the_number_of_1_bits/Solution.java)| Easy | Array, Sorting, Bit_Manipulation, Counting | 10 | 65.50
+| 0232 |[Implement Queue using Stacks](src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java)| Easy | Stack, Design, Queue | 1 | 67.21
+| 0242 |[Valid Anagram](src/main/java/g0201_0300/s0242_valid_anagram/Solution.java)| Easy | String, Hash_Table, Sorting | 2 | 97.76
+| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate/Solution.java)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
-#### Day 12 Linked List
+#### Day 12 Class and Object
| | | | | |
|-|-|-|-|-|-
-| 0024 |[Swap Nodes in Pairs](src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
-| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
+| 1603 |[Design Parking System](src/main/java/g1601_1700/s1603_design_parking_system/ParkingSystem.java)| Easy | Design, Simulation, Counting | 8 | 76.16
+| 0303 |[Range Sum Query - Immutable](src/main/java/g0301_0400/s0303_range_sum_query_immutable/NumArray.java)| Easy | Array, Design, Prefix_Sum | 7 | 100.00
-#### Day 13 Linked List
+### Programming Skills II
+
+#### Day 1
| | | | | |
|-|-|-|-|-|-
-| 0025 |[Reverse Nodes in k-Group](src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
-| 0143 |[Reorder List](src/main/java/g0101_0200/s0143_reorder_list/Solution.java)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 2 | 72.59
+| 0896 |[Monotonic Array](src/main/java/g0801_0900/s0896_monotonic_array/Solution.java)| Easy | Array | 2 | 86.21
+| 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 14 Stack Queue
+#### Day 2
| | | | | |
|-|-|-|-|-|-
-| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 3 | 100.00
-| 1249 |[Minimum Remove to Make Valid Parentheses](src/main/java/g1201_1300/s1249_minimum_remove_to_make_valid_parentheses/Solution.java)| Medium | String, Stack | 13 | 94.62
-| 1823 |[Find the Winner of the Circular Game](src/main/java/g1801_1900/s1823_find_the_winner_of_the_circular_game/Solution.java)| Medium | Array, Math, Simulation, Recursion, Queue | 3 | 64.85
+| 0110 |[Balanced Binary Tree](src/main/java/g0101_0200/s0110_balanced_binary_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree | 1 | 98.82
+| 0459 |[Repeated Substring Pattern](src/main/java/g0401_0500/s0459_repeated_substring_pattern/Solution.java)| Easy | String, String_Matching | 8 | 96.64
-#### Day 15 Tree
+#### Day 3
| | | | | |
|-|-|-|-|-|-
-| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
-| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 3 | 86.35
-| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 1 | 95.00
+| 0150 |[Evaluate Reverse Polish Notation](src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java)| Medium | Top_Interview_Questions, Array, Math, Stack | 6 | 76.50
+| 0066 |[Plus One](src/main/java/g0001_0100/s0066_plus_one/Solution.java)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
-#### Day 16 Tree
+#### Day 4
| | | | | |
|-|-|-|-|-|-
-| 0199 |[Binary Tree Right Side View](src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 94.57
-| 0113 |[Path Sum II](src/main/java/g0101_0200/s0113_path_sum_ii/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Backtracking | 1 | 100.00
-| 0450 |[Delete Node in a BST](src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java)| Medium | Tree, Binary_Tree, Binary_Search_Tree | 0 | 100.00
+| 1367 |[Linked List in Binary Tree](src/main/java/g1301_1400/s1367_linked_list_in_binary_tree/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 2 | 61.23
+| 0043 |[Multiply Strings](src/main/java/g0001_0100/s0043_multiply_strings/Solution.java)| Medium | String, Math, Simulation | 1 | 100.00
-#### Day 17 Tree
+#### Day 5
| | | | | |
|-|-|-|-|-|-
-| 0230 |[Kth Smallest Element in a BST](src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 78.91
-| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 18 | 84.18
+| 0067 |[Add Binary](src/main/java/g0001_0100/s0067_add_binary/Solution.java)| Easy | String, Math, Bit_Manipulation, Simulation | 1 | 99.82
+| 0989 |[Add to Array-Form of Integer](src/main/java/g0901_1000/s0989_add_to_array_form_of_integer/Solution.java)| Easy | Array, Math | 7 | 65.92
-#### Day 18 Tree
+#### Day 6
| | | | | |
|-|-|-|-|-|-
-| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 10 | 56.51
-| 0297 |[Serialize and Deserialize Binary Tree](src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java)| Hard | Top_Interview_Questions, String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design | 7 | 98.13
+| 0739 |[Daily Temperatures](src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 8 | 96.83
+| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java)| Easy | String | 0 | 100.00
-#### Day 19 Graph
+#### Day 7
| | | | | |
|-|-|-|-|-|-
-| 0997 |[Find the Town Judge](src/main/java/g0901_1000/s0997_find_the_town_judge/Solution.java)| Easy | Array, Hash_Table, Graph | 3 | 80.64
-| 1557 |[Minimum Number of Vertices to Reach All Nodes](src/main/java/g1501_1600/s1557_minimum_number_of_vertices_to_reach_all_nodes/Solution.java)| Medium | Graph | 8 | 99.94
-| 0841 |[Keys and Rooms](src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph | 3 | 51.54
+| 0048 |[Rotate Image](src/main/java/g0001_0100/s0048_rotate_image/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
+| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/java/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.java)| Easy | Array, Matrix | 1 | 78.38
-#### Day 20 Heap Priority Queue
+#### Day 8
| | | | | |
|-|-|-|-|-|-
-| 0215 |[Kth Largest Element in an Array](src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 5 | 70.82
-| 0347 |[Top K Frequent Elements](src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 9 | 97.93
+| 0054 |[Spiral Matrix](src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
+| 0973 |[K Closest Points to Origin](src/main/java/g0901_1000/s0973_k_closest_points_to_origin/Solution.java)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 4 | 98.26
-#### Day 21 Heap Priority Queue
+#### Day 9
| | | | | |
|-|-|-|-|-|-
-| 0451 |[Sort Characters By Frequency](src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Bucket_Sort | 13 | 89.63
-| 0973 |[K Closest Points to Origin](src/main/java/g0901_1000/s0973_k_closest_points_to_origin/Solution.java)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 4 | 98.26
-
-### Algorithm I
+| 1630 |[Arithmetic Subarrays](src/main/java/g1601_1700/s1630_arithmetic_subarrays/Solution.java)| Medium | Array, Sorting | 8 | 93.62
+| 0429 |[N-ary Tree Level Order Traversal](src/main/java/g0401_0500/s0429_n_ary_tree_level_order_traversal/Solution.java)| Medium | Breadth_First_Search, Tree | 3 | 80.26
-#### Day 1 Binary Search
+#### Day 10
| | | | | |
|-|-|-|-|-|-
-| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Array, Binary_Search | 0 | 100.00
-| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
-| 0035 |[Search Insert Position](src/main/java/g0001_0100/s0035_search_insert_position/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
+| 0503 |[Next Greater Element II](src/main/java/g0501_0600/s0503_next_greater_element_ii/Solution.java)| Medium | Array, Stack, Monotonic_Stack | 7 | 97.03
+| 0556 |[Next Greater Element III](src/main/java/g0501_0600/s0556_next_greater_element_iii/Solution.java)| Medium | String, Math, Two_Pointers | 0 | 100.00
-#### Day 2 Two Pointers
+#### Day 11
| | | | | |
|-|-|-|-|-|-
-| 0977 |[Squares of a Sorted Array](src/main/java/g0901_1000/s0977_squares_of_a_sorted_array/Solution.java)| Easy | Array, Sorting, Two_Pointers | 1 | 100.00
-| 0189 |[Rotate Array](src/main/java/g0101_0200/s0189_rotate_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
+| 1376 |[Time Needed to Inform All Employees](src/main/java/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 8 | 99.85
+| 0049 |[Group Anagrams](src/main/java/g0001_0100/s0049_group_anagrams/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 6 | 97.61
-#### Day 3 Two Pointers
+#### Day 12
| | | | | |
|-|-|-|-|-|-
-| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 79.54
-| 0167 |[Two Sum II - Input Array Is Sorted](src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java)| Medium | Array, Binary_Search, Two_Pointers | 1 | 99.21
+| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 3 | 99.83
+| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
-#### Day 4 Two Pointers
+#### Day 13
| | | | | |
|-|-|-|-|-|-
-| 0344 |[Reverse String](src/main/java/g0301_0400/s0344_reverse_string/Solution.java)| Easy | Top_Interview_Questions, String, Two_Pointers, Recursion | 1 | 99.91
-| 0557 |[Reverse Words in a String III](src/main/java/g0501_0600/s0557_reverse_words_in_a_string_iii/Solution.java)| Easy | String, Two_Pointers | 4 | 97.75
+| 0304 |[Range Sum Query 2D - Immutable](src/main/java/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.java)| Medium | Array, Matrix, Design, Prefix_Sum | 153 | 87.51
+| 0910 |[Smallest Range II](src/main/java/g0901_1000/s0910_smallest_range_ii/Solution.java)| Medium | Array, Math, Sorting, Greedy | 10 | 73.16
-#### Day 5 Two Pointers
+#### Day 14
| | | | | |
|-|-|-|-|-|-
-| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
-| 0019 |[Remove Nth Node From End of List](src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
+| 0143 |[Reorder List](src/main/java/g0101_0200/s0143_reorder_list/Solution.java)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 2 | 72.59
+| 0138 |[Copy List with Random Pointer](src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
-#### Day 6 Sliding Window
+#### Day 15
| | | | | |
|-|-|-|-|-|-
-| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 2 | 99.88
-| 0567 |[Permutation in String](src/main/java/g0501_0600/s0567_permutation_in_string/Solution.java)| Medium | String, Hash_Table, Two_Pointers, Sliding_Window | 5 | 93.93
+| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
+| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii/Solution.java)| Medium | Math, Stack, Linked_List | 3 | 90.38
-#### Day 7 Breadth First Search Depth First Search
+#### Day 16
| | | | | |
|-|-|-|-|-|-
-| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
-| 0695 |[Max Area of Island](src/main/java/g0601_0700/s0695_max_area_of_island/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 76.79
+| 0061 |[Rotate List](src/main/java/g0001_0100/s0061_rotate_list/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
+| 0173 |[Binary Search Tree Iterator](src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 15 | 100.00
-#### Day 8 Breadth First Search Depth First Search
+#### Day 17
| | | | | |
|-|-|-|-|-|-
-| 0617 |[Merge Two Binary Trees](src/main/java/g0601_0700/s0617_merge_two_binary_trees/Solution.java)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 1 | 72.47
-| 0116 |[Populating Next Right Pointers in Each Node](src/main/java/g0101_0200/s0116_populating_next_right_pointers_in_each_node/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 0 | 100.00
+| 1845 |[Seat Reservation Manager](src/main/java/g1801_1900/s1845_seat_reservation_manager/SeatManager.java)| Medium | Design, Heap_Priority_Queue | 47 | 87.63
+| 0860 |[Lemonade Change](src/main/java/g0801_0900/s0860_lemonade_change/Solution.java)| Easy | Array, Greedy | 2 | 90.84
-#### Day 9 Breadth First Search Depth First Search
+#### Day 18
| | | | | |
|-|-|-|-|-|-
-| 0542 |[01 Matrix](src/main/java/g0501_0600/s0542_01_matrix/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 7 | 95.83
-| 0994 |[Rotting Oranges](src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 3 | 74.27
+| 0155 |[Min Stack](src/main/java/g0101_0200/s0155_min_stack/MinStack.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 4 | 96.54
+| 0341 |[Flatten Nested List Iterator](src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java)| Medium | Depth_First_Search, Tree, Stack, Design, Queue, Iterator | 2 | 99.95
-#### Day 10 Recursion Backtracking
+#### Day 19
| | | | | |
|-|-|-|-|-|-
-| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
-| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
+| 1797 |[Design Authentication Manager](src/main/java/g1701_1800/s1797_design_authentication_manager/AuthenticationManager.java)| Medium | Hash_Table, Design | 41 | 92.67
+| 0707 |[Design Linked List](src/main/java/g0701_0800/s0707_design_linked_list/MyLinkedList.java)| Medium | Design, Linked_List | 10 | 70.60
-#### Day 11 Recursion Backtracking
+#### Day 20
| | | | | |
|-|-|-|-|-|-
-| 0077 |[Combinations](src/main/java/g0001_0100/s0077_combinations/Solution.java)| Medium | Backtracking | 11 | 77.40
-| 0046 |[Permutations](src/main/java/g0001_0100/s0046_permutations/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 95.07
-| 0784 |[Letter Case Permutation](src/main/java/g0701_0800/s0784_letter_case_permutation/Solution.java)| Medium | String, Bit_Manipulation, Backtracking | 10 | 40.38
+| 0380 |[Insert Delete GetRandom O(1)](src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java)| Medium | Array, Hash_Table, Math, Design, Randomized | 27 | 93.44
+| 0622 |[Design Circular Queue](src/main/java/g0601_0700/s0622_design_circular_queue/MyCircularQueue.java)| Medium | Array, Design, Linked_List, Queue | 3 | 100.00
+| 0729 |[My Calendar I](src/main/java/g0701_0800/s0729_my_calendar_i/MyCalendar.java)| Medium | Binary_Search, Design, Ordered_Set, Segment_Tree | 17 | 97.23
-#### Day 12 Dynamic Programming
+### Graph Theory I
+
+#### Day 1 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0198 |[House Robber](src/main/java/g0101_0200/s0198_house_robber/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
-| 0120 |[Triangle](src/main/java/g0101_0200/s0120_triangle/Solution.java)| Medium | Array, Dynamic_Programming | 2 | 94.63
+| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
+| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
-#### Day 13 Bit Manipulation
+#### Day 2 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0231 |[Power of Two](src/main/java/g0201_0300/s0231_power_of_two/Solution.java)| Easy | Math, Bit_Manipulation, Recursion | 1 | 100.00
-| 0191 |[Number of 1 Bits](src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation | 1 | 84.87
+| 0695 |[Max Area of Island](src/main/java/g0601_0700/s0695_max_area_of_island/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 76.79
+| 1254 |[Number of Closed Islands](src/main/java/g1201_1300/s1254_number_of_closed_islands/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 3 | 55.59
-#### Day 14 Bit Manipulation
+#### Day 3 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0190 |[Reverse Bits](src/main/java/g0101_0200/s0190_reverse_bits/Solution.java)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer | 1 | 98.66
-| 0136 |[Single Number](src/main/java/g0101_0200/s0136_single_number/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 99.97
-
-### Algorithm II
+| 1020 |[Number of Enclaves](src/main/java/g1001_1100/s1020_number_of_enclaves/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 6 | 68.24
+| 1905 |[Count Sub Islands](src/main/java/g1901_2000/s1905_count_sub_islands/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 24 | 85.54
-#### Day 1 Binary Search
+#### Day 4 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-| 0033 |[Search in Rotated Sorted Array](src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
-| 0074 |[Search a 2D Matrix](src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
+| 1162 |[As Far from Land as Possible](src/main/java/g1101_1200/s1162_as_far_from_land_as_possible/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 16 | 62.40
+| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
-#### Day 2 Binary Search
+#### Day 5 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0153 |[Find Minimum in Rotated Sorted Array](src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 0 | 100.00
-| 0162 |[Find Peak Element](src/main/java/g0101_0200/s0162_find_peak_element/Solution.java)| Medium | Top_Interview_Questions, Array, Binary_Search | 0 | 100.00
+| 1091 |[Shortest Path in Binary Matrix](src/main/java/g1001_1100/s1091_shortest_path_in_binary_matrix/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 22 | 69.99
+| 0542 |[01 Matrix](src/main/java/g0501_0600/s0542_01_matrix/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 7 | 95.83
-#### Day 3 Two Pointers
+#### Day 6 Matrix Related Problems
| | | | | |
|-|-|-|-|-|-
-| 0082 |[Remove Duplicates from Sorted List II](src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java)| Medium | Two_Pointers, Linked_List | 0 | 100.00
-| 0015 |[3Sum](src/main/java/g0001_0100/s0015_3sum/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 27 | 97.93
+| 0934 |[Shortest Bridge](src/main/java/g0901_1000/s0934_shortest_bridge/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 6 | 97.87
+| 1926 |[Nearest Exit from Entrance in Maze](src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java)| Medium | Array, Breadth_First_Search, Matrix, LeetCode_75_Graphs/BFS | 12 | 40.55
-#### Day 4 Two Pointers
+#### Day 7 Standard Traversal
| | | | | |
|-|-|-|-|-|-
-| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
-| 0986 |[Interval List Intersections](src/main/java/g0901_1000/s0986_interval_list_intersections/Solution.java)| Medium | Array, Two_Pointers | 2 | 99.95
-| 0011 |[Container With Most Water](src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 94.75
+| 0797 |[All Paths From Source to Target](src/main/java/g0701_0800/s0797_all_paths_from_source_to_target/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 2 | 90.53
+| 0841 |[Keys and Rooms](src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, LeetCode_75_Graphs/DFS | 3 | 51.54
-#### Day 5 Sliding Window
+#### Day 8 Standard Traversal
| | | | | |
|-|-|-|-|-|-
-| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 6 | 99.03
-| 0713 |[Subarray Product Less Than K](src/main/java/g0701_0800/s0713_subarray_product_less_than_k/Solution.java)| Medium | Array, Sliding_Window | 8 | 39.00
-| 0209 |[Minimum Size Subarray Sum](src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 1 | 100.00
+| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find, LeetCode_75_Graphs/DFS | 2 | 69.51
+| 1319 |[Number of Operations to Make Network Connected](src/main/java/g1301_1400/s1319_number_of_operations_to_make_network_connected/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 9 | 67.64
-#### Day 6 Breadth First Search Depth First Search
+#### Day 9 Standard Traversal
| | | | | |
|-|-|-|-|-|-
-| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
-| 0547 |[Number of Provinces](src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 2 | 69.51
+| 1376 |[Time Needed to Inform All Employees](src/main/java/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 8 | 99.85
+| 0802 |[Find Eventual Safe States](src/main/java/g0801_0900/s0802_find_eventual_safe_states/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 7 | 74.93
-#### Day 7 Breadth First Search Depth First Search
+#### Day 10 Standard Traversal
| | | | | |
|-|-|-|-|-|-
-| 0117 |[Populating Next Right Pointers in Each Node II](src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 0 | 100.00
-| 0572 |[Subtree of Another Tree](src/main/java/g0501_0600/s0572_subtree_of_another_tree/Solution.java)| Easy | Depth_First_Search, Tree, Binary_Tree, Hash_Function, String_Matching | 1 | 100.00
+| 1129 |[Shortest Path with Alternating Colors](src/main/java/g1101_1200/s1129_shortest_path_with_alternating_colors/Solution.java)| Medium | Breadth_First_Search, Graph | 4 | 96.63
+| 1466 |[Reorder Routes to Make All Paths Lead to the City Zero](src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, LeetCode_75_Graphs/DFS | 39 | 97.71
+| 0847 |[Shortest Path Visiting All Nodes](src/main/java/g0801_0900/s0847_shortest_path_visiting_all_nodes/Solution.java)| Hard | Dynamic_Programming, Breadth_First_Search, Bit_Manipulation, Graph, Bitmask | 14 | 78.72
-#### Day 8 Breadth First Search Depth First Search
+#### Day 11 Breadth First Search
| | | | | |
|-|-|-|-|-|-
-| 1091 |[Shortest Path in Binary Matrix](src/main/java/g1001_1100/s1091_shortest_path_in_binary_matrix/Solution.java)| Medium | Array, Breadth_First_Search, Matrix | 22 | 69.99
-| 0130 |[Surrounded Regions](src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 2 | 84.66
-| 0797 |[All Paths From Source to Target](src/main/java/g0701_0800/s0797_all_paths_from_source_to_target/Solution.java)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 2 | 90.53
+| 1306 |[Jump Game III](src/main/java/g1301_1400/s1306_jump_game_iii/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search | 2 | 96.23
+| 1654 |[Minimum Jumps to Reach Home](src/main/java/g1601_1700/s1654_minimum_jumps_to_reach_home/Solution.java)| Medium | Array, Dynamic_Programming, Breadth_First_Search | 6 | 99.87
+| 0365 |[Water and Jug Problem](src/main/java/g0301_0400/s0365_water_and_jug_problem/Solution.java)| Medium | Math, Depth_First_Search, Breadth_First_Search | 0 | 100.00
-#### Day 9 Recursion Backtracking
+#### Day 12 Breadth First Search
| | | | | |
|-|-|-|-|-|-
-| 0078 |[Subsets](src/main/java/g0001_0100/s0078_subsets/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 1 | 70.60
-| 0090 |[Subsets II](src/main/java/g0001_0100/s0090_subsets_ii/Solution.java)| Medium | Array, Bit_Manipulation, Backtracking | 2 | 82.94
+| 0433 |[Minimum Genetic Mutation](src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java)| Medium | String, Hash_Table, Breadth_First_Search | 0 | 100.00
+| 0752 |[Open the Lock](src/main/java/g0701_0800/s0752_open_the_lock/Solution.java)| Medium | Array, String, Hash_Table, Breadth_First_Search | 72 | 91.06
+| 0127 |[Word Ladder](src/main/java/g0101_0200/s0127_word_ladder/Solution.java)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 22 | 96.00
-#### Day 10 Recursion Backtracking
+#### Day 13 Graph Theory
| | | | | |
|-|-|-|-|-|-
-| 0047 |[Permutations II](src/main/java/g0001_0100/s0047_permutations_ii/Solution.java)| Medium | Array, Backtracking | 1 | 99.86
-| 0039 |[Combination Sum](src/main/java/g0001_0100/s0039_combination_sum/Solution.java)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 100.00
-| 0040 |[Combination Sum II](src/main/java/g0001_0100/s0040_combination_sum_ii/Solution.java)| Medium | Array, Backtracking | 2 | 99.75
+| 0997 |[Find the Town Judge](src/main/java/g0901_1000/s0997_find_the_town_judge/Solution.java)| Easy | Array, Hash_Table, Graph | 3 | 80.64
+| 1557 |[Minimum Number of Vertices to Reach All Nodes](src/main/java/g1501_1600/s1557_minimum_number_of_vertices_to_reach_all_nodes/Solution.java)| Medium | Graph | 8 | 99.94
-#### Day 11 Recursion Backtracking
+#### Day 14 Graph Theory
| | | | | |
|-|-|-|-|-|-
-| 0017 |[Letter Combinations of a Phone Number](src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
-| 0022 |[Generate Parentheses](src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
-| 0079 |[Word Search](src/main/java/g0001_0100/s0079_word_search/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 157 | 78.97
+| 1615 |[Maximal Network Rank](src/main/java/g1601_1700/s1615_maximal_network_rank/Solution.java)| Medium | Graph | 3 | 97.34
+| 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
-#### Day 12 Dynamic Programming
+### SQL I
+
+#### Day 1 Select
| | | | | |
|-|-|-|-|-|-
-| 0213 |[House Robber II](src/main/java/g0201_0300/s0213_house_robber_ii/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
-| 0055 |[Jump Game](src/main/java/g0001_0100/s0055_jump_game/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 2 | 79.47
+| 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 13 Dynamic Programming
+#### Day 2 Select and Order
| | | | | |
|-|-|-|-|-|-
-| 0045 |[Jump Game II](src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 2 | 49.02
-| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
+| 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 14 Dynamic Programming
+#### Day 3 String Processing Functions
| | | | | |
|-|-|-|-|-|-
-| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 7 | 97.94
-| 0413 |[Arithmetic Slices](src/main/java/g0401_0500/s0413_arithmetic_slices/Solution.java)| Medium | Array, Dynamic_Programming | 0 | 100.00
+| 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 15 Dynamic Programming
+#### Day 4 Union and Select
| | | | | |
|-|-|-|-|-|-
-| 0091 |[Decode Ways](src/main/java/g0001_0100/s0091_decode_ways/Solution.java)| Medium | Top_Interview_Questions, String, Dynamic_Programming | 2 | 66.37
-| 0139 |[Word Break](src/main/java/g0101_0200/s0139_word_break/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 2 | 97.08
+| 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 16 Dynamic Programming
+#### Day 5 Union
| | | | | |
|-|-|-|-|-|-
-| 0300 |[Longest Increasing Subsequence](src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 3 | 98.63
-| 0673 |[Number of Longest Increasing Subsequence](src/main/java/g0601_0700/s0673_number_of_longest_increasing_subsequence/Solution.java)| Medium | Array, Dynamic_Programming, Segment_Tree, Binary_Indexed_Tree | 25 | 68.75
+| 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 17 Dynamic Programming
+#### Day 6 Union
| | | | | |
|-|-|-|-|-|-
-| 1143 |[Longest Common Subsequence](src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 33 | 46.23
-| 0583 |[Delete Operation for Two Strings](src/main/java/g0501_0600/s0583_delete_operation_for_two_strings/Solution.java)| Medium | String, Dynamic_Programming | 12 | 79.10
+| 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 18 Dynamic Programming
+#### Day 7 Function
| | | | | |
|-|-|-|-|-|-
-| 0072 |[Edit Distance](src/main/java/g0001_0100/s0072_edit_distance/Solution.java)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 4 | 90.13
-| 0322 |[Coin Change](src/main/java/g0301_0400/s0322_coin_change/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 17 | 91.77
-| 0343 |[Integer Break](src/main/java/g0301_0400/s0343_integer_break/Solution.java)| Medium | Dynamic_Programming, Math | 0 | 100.00
+| 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 19 Bit Manipulation
+#### Day 8 Function
| | | | | |
|-|-|-|-|-|-
-| 0201 |[Bitwise AND of Numbers Range](src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java)| Medium | Bit_Manipulation | 8 | 74.15
+| 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 20 Others
+#### Day 9 Control of Flow
| | | | | |
|-|-|-|-|-|-
-| 0384 |[Shuffle an Array](src/main/java/g0301_0400/s0384_shuffle_an_array/Solution.java)| Medium | Top_Interview_Questions, Array, Math, Randomized | 52 | 91.77
+| 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 21 Others
+#### Day 10 Where
| | | | | |
|-|-|-|-|-|-
-| 0202 |[Happy Number](src/main/java/g0201_0300/s0202_happy_number/Solution.java)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 1 | 98.59
-| 0149 |[Max Points on a Line](src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 11 | 99.21
+| 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!
diff --git a/build.gradle b/build.gradle
index d2151a8f7..657436fc2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,8 +1,8 @@
plugins {
id 'java'
id 'maven-publish'
- id 'com.diffplug.spotless' version '6.12.0'
- id 'org.sonarqube' version '4.3.0.3225'
+ id 'com.diffplug.spotless' version '7.0.4'
+ id 'org.sonarqube' version '6.2.0.5505'
id 'jacoco'
}
@@ -12,10 +12,10 @@ repositories {
}
dependencies {
- testImplementation 'org.junit.jupiter:junit-jupiter:[5.10.1,)'
- testImplementation 'org.hamcrest:hamcrest-core:[2.2,)'
- testImplementation 'org.zapodot:embedded-db-junit-jupiter:[2.1.1,)'
- testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
+ testImplementation 'org.junit.jupiter:junit-jupiter:[5.13.3,)'
+ testImplementation 'org.hamcrest:hamcrest-core:[3.0,)'
+ testImplementation 'org.zapodot:embedded-db-junit-jupiter:[2.2.3,)'
+ testRuntimeOnly 'org.junit.platform:junit-platform-launcher:[1.13.3,)'
}
test {
@@ -24,7 +24,7 @@ test {
}
group = 'com.github.javadev'
-version = '1.27-SNAPSHOT'
+version = '1.49-SNAPSHOT'
description = 'leetcode-in-java'
java.sourceCompatibility = JavaVersion.VERSION_17
@@ -33,15 +33,7 @@ java {
withJavadocJar()
}
-publishing {
- publications {
- maven(MavenPublication) {
- from(components.java)
- }
- }
-}
-
-tasks.withType(JavaCompile) {
+tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
@@ -54,7 +46,7 @@ spotless {
}
importOrder '\\#', '', '*'
removeUnusedImports()
- googleJavaFormat('1.15.0').aosp()
+ googleJavaFormat('1.22.0').aosp()
toggleOffOn()
endWithNewline()
}
diff --git a/gradle.properties b/gradle.properties
index aab906524..055bf6cf6 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,2 +1,3 @@
sonar.coverage.jacoco.xmlReportPaths=build/jacoco/test/jacocoTestReport.xml
org.gradle.jvmargs=-Xms512m -Xmx2048m
+org.gradle.configuration-cache=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 7f93135c4..8bdaf60c7 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1af9e0930..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-8.5-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/gradlew b/gradlew
index 1aa94a426..adff685a0 100644
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
#!/bin/sh
#
-# Copyright Š 2015-2021 the original authors.
+# Copyright Š 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
-APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -170,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
- CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
-# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
- -classpath "$CLASSPATH" \
- org.gradle.wrapper.GradleWrapperMain \
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
diff --git a/gradlew.bat b/gradlew.bat
index 93e3f59f1..c4bdd3ab8 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
@@ -57,22 +59,21 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
diff --git a/pom-central.xml b/pom-central.xml
index dd772b311..30105e979 100644
--- a/pom-central.xml
+++ b/pom-central.xml
@@ -4,7 +4,7 @@
com.github.javadevleetcode-in-javajar
- 1.27
+ 1.49leetcode-in-javaJava-based LeetCode algorithm problem solutions, regularly updatedhttps://github.com/javadev/LeetCode-in-Java
@@ -42,7 +42,7 @@
org.apache.maven.pluginsmaven-compiler-plugin
- 3.11.0
+ 3.14.01717
@@ -56,19 +56,19 @@
org.apache.maven.pluginsmaven-surefire-plugin
- 3.0.0
+ 3.2.5org.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)org.apache.maven.pluginsmaven-jar-plugin
- 3.2.2
+ 3.4.0
@@ -82,7 +82,7 @@
org.apache.maven.pluginsmaven-source-plugin
- 3.2.0
+ 3.3.1attach-sources
@@ -96,7 +96,7 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.4.1
+ 3.11.2attach-sources
@@ -118,7 +118,7 @@
com.vladsch.flexmarkflexmark-all
- 0.64.0
+ 0.64.8
@@ -132,7 +132,7 @@
org.apache.maven.pluginsmaven-gpg-plugin
- 1.6
+ 3.2.3sign-artifacts
@@ -143,31 +143,61 @@
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.1.0
+
+
+ generate-checksums
+ verify
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ run
+
+
+
+ org.junit.jupiterjunit-jupiter-api
- [5.10.1,)
+ [5.13.3,)testorg.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)testorg.hamcresthamcrest-core
- [2.2,)
+ [3.0,)testorg.zapodotembedded-db-junit-jupiter
- [2.1.1,)
+ [2.2.3,)test
diff --git a/pom-central21.xml b/pom-central21.xml
index fd9c76fb1..211c32598 100644
--- a/pom-central21.xml
+++ b/pom-central21.xml
@@ -4,7 +4,7 @@
com.github.javadevleetcode-in-java21jar
- 1.27
+ 1.49leetcode-in-javaJava-based LeetCode algorithm problem solutions, regularly updatedhttps://github.com/javadev/LeetCode-in-Java
@@ -42,7 +42,7 @@
org.apache.maven.pluginsmaven-compiler-plugin
- 3.11.0
+ 3.14.02121
@@ -56,19 +56,19 @@
org.apache.maven.pluginsmaven-surefire-plugin
- 3.0.0
+ 3.2.5org.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)org.apache.maven.pluginsmaven-jar-plugin
- 3.2.2
+ 3.4.0
@@ -82,7 +82,7 @@
org.apache.maven.pluginsmaven-source-plugin
- 3.2.0
+ 3.3.1attach-sources
@@ -96,7 +96,7 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.6.0
+ 3.11.2attach-sources
@@ -113,7 +113,7 @@
org.jdrupes.mdocletdoclet
- 4.1.0
+ 4.2.0com.vladsch.flexmark
@@ -124,21 +124,21 @@
- -J--add-exports=jdk.javadoc/jdk.javadoc.internal.doclets.toolkit=ALL-UNNAMED-J--add-exports=jdk.javadoc/jdk.javadoc.internal.tool=ALL-UNNAMED
- -J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
- -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
+ -J--add-exports=jdk.javadoc/jdk.javadoc.internal.doclets.toolkit=ALL-UNNAMED
+ -J--add-opens=jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.resources.releases=ALL-UNNAMED-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
- -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED-J--add-exports=jdk.compiler/com.sun.tools.doclint=ALL-UNNAMED
- -J--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMEDorg.apache.maven.pluginsmaven-gpg-plugin
- 1.6
+ 3.2.3sign-artifacts
@@ -149,31 +149,61 @@
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.1.0
+
+
+ generate-checksums
+ verify
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ run
+
+
+
+ org.junit.jupiterjunit-jupiter-api
- [5.10.1,)
+ [5.13.3,)testorg.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)testorg.hamcresthamcrest-core
- [2.2,)
+ [3.0,)testorg.zapodotembedded-db-junit-jupiter
- [2.1.1,)
+ [2.2.3,)test
diff --git a/pom.xml b/pom.xml
index 58f8363d2..11e225a81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.github.javadevleetcode-in-javajar
- 1.27-SNAPSHOT
+ 1.49-SNAPSHOTleetcode-in-javaJava-based LeetCode algorithm problem solutions, regularly updatedhttps://github.com/javadev/LeetCode-in-Java
@@ -41,7 +41,7 @@
org.apache.maven.pluginsmaven-compiler-plugin
- 3.11.0
+ 3.14.11717
@@ -55,19 +55,19 @@
org.apache.maven.pluginsmaven-surefire-plugin
- 3.0.0
+ 3.5.4org.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)org.apache.maven.pluginsmaven-jar-plugin
- 3.2.2
+ 3.5.0
@@ -100,7 +100,7 @@
org.jacocojacoco-maven-plugin
- 0.8.10
+ 0.8.14prepare-agent
@@ -113,17 +113,17 @@
org.apache.maven.pluginsmaven-project-info-reports-plugin
- 2.9
+ 3.9.0org.apache.maven.pluginsmaven-site-plugin
- 3.7.1
+ 3.21.0org.apache.maven.pluginsmaven-source-plugin
- 3.2.0
+ 3.4.0attach-sources
@@ -137,7 +137,7 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.3.1
+ 3.12.0attach-sources
@@ -155,7 +155,7 @@
org.apache.maven.pluginsmaven-gpg-plugin
- 1.6
+ 3.2.8sign-artifacts
@@ -172,25 +172,31 @@
org.junit.jupiterjunit-jupiter-api
- [5.10.1,)
+ [5.13.3,)testorg.junit.jupiterjunit-jupiter-engine
- [5.10.1,)
+ [5.13.3,)
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ [1.13.3,)testorg.hamcresthamcrest-core
- [2.2,)
+ [3.0,)testorg.zapodotembedded-db-junit-jupiter
- [2.1.1,)
+ [2.2.3,)test
diff --git a/src/main/java/com_github_leetcode/Employee.java b/src/main/java/com_github_leetcode/Employee.java
index b5aa800a0..e76f72449 100644
--- a/src/main/java/com_github_leetcode/Employee.java
+++ b/src/main/java/com_github_leetcode/Employee.java
@@ -6,8 +6,10 @@
public class Employee {
/** It's the unique id of each node; unique id of this employee */
public int id;
+
/** the importance value of this employee */
public int importance;
+
/** the id of direct subordinates */
public List subordinates;
diff --git a/src/main/java/com_github_leetcode/Node.java b/src/main/java/com_github_leetcode/Node.java
index 8715cc9f9..430be2004 100644
--- a/src/main/java/com_github_leetcode/Node.java
+++ b/src/main/java/com_github_leetcode/Node.java
@@ -2,7 +2,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.StringJoiner;
@SuppressWarnings("java:S1104")
public class Node {
@@ -24,19 +23,32 @@ public Node(int val, List neighbors) {
this.neighbors = neighbors;
}
+ @Override
public String toString() {
- StringJoiner result = new StringJoiner(",", "[", "]");
- for (Node node : neighbors) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ for (int i = 0; i < neighbors.size(); i++) {
+ Node node = neighbors.get(i);
+ if (i > 0) {
+ result.append(",");
+ }
if (node.neighbors.isEmpty()) {
- result.add(String.valueOf(node.val));
+ result.append(node.val);
} else {
- StringJoiner result2 = new StringJoiner(",", "[", "]");
- for (Node nodeItem : node.neighbors) {
- result2.add(String.valueOf(nodeItem.val));
+ StringBuilder result2 = new StringBuilder();
+ result2.append("[");
+ for (int j = 0; j < node.neighbors.size(); j++) {
+ Node nodeItem = node.neighbors.get(j);
+ if (j > 0) {
+ result2.append(",");
+ }
+ result2.append(nodeItem.val);
}
- result.add(result2.toString());
+ result2.append("]");
+ result.append(result2.toString());
}
}
+ result.append("]");
return result.toString();
}
}
diff --git a/src/main/java/com_github_leetcode/random/Node.java b/src/main/java/com_github_leetcode/random/Node.java
index 7d1e9438c..2c1cf7338 100644
--- a/src/main/java/com_github_leetcode/random/Node.java
+++ b/src/main/java/com_github_leetcode/random/Node.java
@@ -1,55 +1,49 @@
package com_github_leetcode.random;
-import java.util.StringJoiner;
-
@SuppressWarnings("java:S1104")
public class Node {
public int val;
public Node next;
public Node random;
- public Node() {
- this.val = 0;
- }
-
public Node(int val) {
this.val = val;
}
- public Node(int val, Node next, Node random) {
- this.val = val;
- this.next = next;
- this.random = random;
- }
-
+ @Override
public String toString() {
- StringJoiner result = new StringJoiner(",", "[", "]");
- StringJoiner result2 = new StringJoiner(",", "[", "]");
- result2.add(String.valueOf(val));
- if (random == null) {
- result2.add("null");
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ result.append("[");
+ result.append(this.val);
+ result.append(",");
+ if (this.random == null) {
+ result.append("null");
} else {
- result2.add(String.valueOf(random.val));
+ result.append(this.random.val);
}
- result.add(result2.toString());
- Node curr = next;
+ result.append("]");
+ Node curr = this.next;
while (curr != null) {
- StringJoiner result3 = new StringJoiner(",", "[", "]");
- result3.add(String.valueOf(curr.val));
+ result.append(",");
+ result.append("[");
+ result.append(curr.val);
+ result.append(",");
if (curr.random == null) {
- result3.add("null");
+ result.append("null");
} else {
int randomIndex = 0;
- Node curr2 = this;
- while (curr2.next != null && curr2 != curr.random) {
- randomIndex += 1;
- curr2 = curr2.next;
+ Node indexFinder = this;
+ while (indexFinder.next != null && indexFinder != curr.random) {
+ randomIndex++;
+ indexFinder = indexFinder.next;
}
- result3.add(String.valueOf(randomIndex));
+ result.append(randomIndex);
}
- result.add(result3.toString());
+ result.append("]");
curr = curr.next;
}
+ result.append("]");
return result.toString();
}
}
diff --git a/src/main/java/g0001_0100/s0001_two_sum/Solution.java b/src/main/java/g0001_0100/s0001_two_sum/Solution.java
index ea36f099f..3b1cf3be1 100644
--- a/src/main/java/g0001_0100/s0001_two_sum/Solution.java
+++ b/src/main/java/g0001_0100/s0001_two_sum/Solution.java
@@ -1,8 +1,9 @@
package g0001_0100.s0001_two_sum;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table
-// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Big_O_Time_O(n)_Space_O(n)
-// #2023_08_09_Time_1_ms_(99.37%)_Space_43.5_MB_(94.36%)
+// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Top_Interview_150_Hashmap
+// #Big_O_Time_O(n)_Space_O(n) #AI_can_be_used_to_solve_the_task
+// #2024_11_09_Time_2_ms_(98.90%)_Space_44.9_MB_(47.05%)
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/java/g0001_0100/s0001_two_sum/readme.md b/src/main/java/g0001_0100/s0001_two_sum/readme.md
index c4ae4e51c..c51a2d424 100644
--- a/src/main/java/g0001_0100/s0001_two_sum/readme.md
+++ b/src/main/java/g0001_0100/s0001_two_sum/readme.md
@@ -36,3 +36,65 @@ You can return the answer in any order.
* **Only one valid answer exists.**
**Follow-up:** Can you come up with an algorithm that is less than O(n2) time complexity?
+
+To solve the Two Sum problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `twoSum`.
+2. Inside the `twoSum` method, create a hashmap to store elements and their indices.
+3. Iterate through the array:
+ - For each element, calculate the complement required to reach the target sum.
+ - Check if the complement exists in the hashmap.
+ - If found, return the indices of the current element and the complement.
+ - If not found, add the current element and its index to the hashmap.
+4. Handle edge cases:
+ - If no solution is found, return an empty array or null (depending on the problem requirements).
+
+Here's the implementation:
+
+```java
+import java.util.HashMap;
+
+public class Solution {
+
+ public int[] twoSum(int[] nums, int target) {
+ // Create a hashmap to store elements and their indices
+ HashMap map = new HashMap<>();
+
+ // Iterate through the array
+ for (int i = 0; i < nums.length; i++) {
+ int complement = target - nums[i];
+ // Check if the complement exists in the hashmap
+ if (map.containsKey(complement)) {
+ // Return the indices of the current element and the complement
+ return new int[]{map.get(complement), i};
+ }
+ // Add the current element and its index to the hashmap
+ map.put(nums[i], i);
+ }
+ // If no solution is found, return an empty array or null
+ return new int[]{};
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int[] nums1 = {2, 7, 11, 15};
+ int target1 = 9;
+ int[] result1 = solution.twoSum(nums1, target1);
+ System.out.println("Example 1 Output: [" + result1[0] + ", " + result1[1] + "]");
+
+ int[] nums2 = {3, 2, 4};
+ int target2 = 6;
+ int[] result2 = solution.twoSum(nums2, target2);
+ System.out.println("Example 2 Output: [" + result2[0] + ", " + result2[1] + "]");
+
+ int[] nums3 = {3, 3};
+ int target3 = 6;
+ int[] result3 = solution.twoSum(nums3, target3);
+ System.out.println("Example 3 Output: [" + result3[0] + ", " + result3[1] + "]");
+ }
+}
+```
+
+This implementation provides a solution to the Two Sum problem with a time complexity of O(n), where n is the number of elements in the input array.
diff --git a/src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java b/src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java
index 68235d739..9d005b6f0 100644
--- a/src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java
+++ b/src/main/java/g0001_0100/s0002_add_two_numbers/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion
// #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15
-// #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) #2023_08_09_Time_1_ms_(100.00%)_Space_43.1_MB_(78.48%)
+// #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M))
+// #AI_can_be_used_to_solve_the_task #2024_11_09_Time_1_ms_(100.00%)_Space_43.7_MB_(99.52%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0002_add_two_numbers/readme.md b/src/main/java/g0001_0100/s0002_add_two_numbers/readme.md
index 6e67c194c..82855a16b 100644
--- a/src/main/java/g0001_0100/s0002_add_two_numbers/readme.md
+++ b/src/main/java/g0001_0100/s0002_add_two_numbers/readme.md
@@ -32,4 +32,102 @@ You may assume the two numbers do not contain any leading zero, except the numbe
* The number of nodes in each linked list is in the range `[1, 100]`.
* `0 <= Node.val <= 9`
-* It is guaranteed that the list represents a number that does not have leading zeros.
\ No newline at end of file
+* It is guaranteed that the list represents a number that does not have leading zeros.
+
+To solve the Add Two Numbers problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `ListNode` class to represent nodes in a linked list.
+2. Define a `Solution` class with a method named `addTwoNumbers`.
+3. Inside the `addTwoNumbers` method, traverse both input linked lists simultaneously:
+ - Keep track of a carry variable to handle cases where the sum of two digits exceeds 9.
+ - Calculate the sum of the current nodes' values along with the carry.
+ - Update the carry for the next iteration.
+ - Create a new node with the sum % 10 and attach it to the result linked list.
+ - Move to the next nodes in both input lists.
+4. After finishing the traversal, check if there is any remaining carry. If so, add a new node with the carry to the result.
+5. Return the head of the result linked list.
+
+Here's the implementation:
+
+```java
+class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode() {}
+
+ ListNode(int val) {
+ this.val = val;
+ }
+
+ ListNode(int val, ListNode next) {
+ this.val = val;
+ this.next = next;
+ }
+}
+
+public class Solution {
+
+ public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
+ ListNode dummyHead = new ListNode();
+ ListNode curr = dummyHead;
+ int carry = 0;
+
+ while (l1 != null || l2 != null) {
+ int sum = carry;
+ if (l1 != null) {
+ sum += l1.val;
+ l1 = l1.next;
+ }
+ if (l2 != null) {
+ sum += l2.val;
+ l2 = l2.next;
+ }
+ curr.next = new ListNode(sum % 10);
+ curr = curr.next;
+ carry = sum / 10;
+ }
+
+ if (carry > 0) {
+ curr.next = new ListNode(carry);
+ }
+
+ return dummyHead.next;
+ }
+
+ // Helper method to print a linked list
+ public void printList(ListNode head) {
+ ListNode curr = head;
+ while (curr != null) {
+ System.out.print(curr.val + " ");
+ curr = curr.next;
+ }
+ System.out.println();
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ ListNode l1 = new ListNode(2, new ListNode(4, new ListNode(3)));
+ ListNode l2 = new ListNode(5, new ListNode(6, new ListNode(4)));
+ ListNode result1 = solution.addTwoNumbers(l1, l2);
+ System.out.print("Example 1 Output: ");
+ solution.printList(result1);
+
+ ListNode l3 = new ListNode(0);
+ ListNode l4 = new ListNode(0);
+ ListNode result2 = solution.addTwoNumbers(l3, l4);
+ System.out.print("Example 2 Output: ");
+ solution.printList(result2);
+
+ ListNode l5 = new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9)))))));
+ ListNode l6 = new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
+ ListNode result3 = solution.addTwoNumbers(l5, l6);
+ System.out.print("Example 3 Output: ");
+ solution.printList(result3);
+ }
+}
+```
+
+This implementation provides a solution to the Add Two Numbers problem using linked lists in Java.
diff --git a/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java b/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java
index 87498c2e4..5933018ca 100644
--- a/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java
+++ b/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window
// #Algorithm_I_Day_6_Sliding_Window #Level_2_Day_14_Sliding_Window/Two_Pointer #Udemy_Strings
-// #Big_O_Time_O(n)_Space_O(1) #2023_08_09_Time_2_ms_(99.88%)_Space_43.7_MB_(58.61%)
+// #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task
+// #2024_11_09_Time_2_ms_(98.59%)_Space_43.4_MB_(90.39%)
public class Solution {
public int lengthOfLongestSubstring(String s) {
diff --git a/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md b/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md
index bf1ef46e0..447d996d9 100644
--- a/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md
+++ b/src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md
@@ -2,7 +2,7 @@
Medium
-Given a string `s`, find the length of the **longest substring** without repeating characters.
+Given a string `s`, find the length of the **longest** **substring** without duplicate characters.
**Example 1:**
@@ -10,7 +10,7 @@ Given a string `s`, find the length of the **longest substring** without repeati
**Output:** 3
-**Explanation:** The answer is "abc", with the length of 3.
+**Explanation:** The answer is "abc", with the length of 3. Note that `"bca"` and `"cab"` are also correct answers.
**Example 2:**
@@ -28,13 +28,70 @@ Given a string `s`, find the length of the **longest substring** without repeati
**Explanation:** The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
-**Example 4:**
-
-**Input:** s = ""
-
-**Output:** 0
-
**Constraints:**
* 0 <= s.length <= 5 * 104
-* `s` consists of English letters, digits, symbols and spaces.
\ No newline at end of file
+* `s` consists of English letters, digits, symbols and spaces.
+
+To solve the Longest Substring Without Repeating Characters problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `lengthOfLongestSubstring`.
+2. Initialize variables to keep track of the starting index of the substring (`start`), the maximum length (`maxLen`), and a hashmap to store characters and their indices.
+3. Iterate through the string `s`, and for each character:
+ - Check if the character exists in the hashmap and its index is greater than or equal to the `start` index.
+ - If found, update the `start` index to the index after the last occurrence of the character.
+ - Update the maximum length if necessary.
+ - Update the index of the current character in the hashmap.
+4. Return the maximum length found.
+5. Handle the edge case where the input string is empty.
+
+Here's the implementation:
+
+```java
+import java.util.HashMap;
+
+public class Solution {
+
+ public int lengthOfLongestSubstring(String s) {
+ // Initialize variables
+ int start = 0;
+ int maxLen = 0;
+ HashMap map = new HashMap<>();
+
+ // Iterate through the string
+ for (int end = 0; end < s.length(); end++) {
+ char ch = s.charAt(end);
+ // If the character exists in the hashmap and its index is greater than or equal to the start index
+ if (map.containsKey(ch) && map.get(ch) >= start) {
+ // Update the start index to the index after the last occurrence of the character
+ start = map.get(ch) + 1;
+ }
+ // Update the maximum length if necessary
+ maxLen = Math.max(maxLen, end - start + 1);
+ // Update the index of the current character in the hashmap
+ map.put(ch, end);
+ }
+
+ return maxLen;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String s1 = "abcabcbb";
+ System.out.println("Example 1 Output: " + solution.lengthOfLongestSubstring(s1));
+
+ String s2 = "bbbbb";
+ System.out.println("Example 2 Output: " + solution.lengthOfLongestSubstring(s2));
+
+ String s3 = "pwwkew";
+ System.out.println("Example 3 Output: " + solution.lengthOfLongestSubstring(s3));
+
+ String s4 = "";
+ System.out.println("Example 4 Output: " + solution.lengthOfLongestSubstring(s4));
+ }
+}
+```
+
+This implementation provides a solution to the Longest Substring Without Repeating Characters problem in Java.
diff --git a/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.java b/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.java
index 470cb9a01..fbe3e5816 100644
--- a/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.java
+++ b/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.java
@@ -1,7 +1,8 @@
package g0001_0100.s0004_median_of_two_sorted_arrays;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer
-// #Big_O_Time_O(log(min(N,M)))_Space_O(1) #2023_08_09_Time_1_ms_(100.00%)_Space_44.4_MB_(96.42%)
+// #Top_Interview_150_Binary_Search #Big_O_Time_O(log(min(N,M)))_Space_O(1)
+// #AI_can_be_used_to_solve_the_task #2024_11_09_Time_1_ms_(100.00%)_Space_46.1_MB_(40.80%)
@SuppressWarnings("java:S2234")
public class Solution {
diff --git a/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md b/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md
index a46337487..903c7dde0 100644
--- a/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md
+++ b/src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md
@@ -22,24 +22,6 @@ The overall run time complexity should be `O(log (m+n))`.
**Explanation:** merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
-**Example 3:**
-
-**Input:** nums1 = [0,0], nums2 = [0,0]
-
-**Output:** 0.00000
-
-**Example 4:**
-
-**Input:** nums1 = [], nums2 = [1]
-
-**Output:** 1.00000
-
-**Example 5:**
-
-**Input:** nums1 = [2], nums2 = []
-
-**Output:** 2.00000
-
**Constraints:**
* `nums1.length == m`
@@ -47,4 +29,72 @@ The overall run time complexity should be `O(log (m+n))`.
* `0 <= m <= 1000`
* `0 <= n <= 1000`
* `1 <= m + n <= 2000`
-* -106 <= nums1[i], nums2[i] <= 106
\ No newline at end of file
+* -106 <= nums1[i], nums2[i] <= 106
+
+To solve the Median of Two Sorted Arrays problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `findMedianSortedArrays`.
+2. Calculate the total length of the combined array (m + n).
+3. Determine the middle index or indices of the combined array based on its length (for both even and odd lengths).
+4. Implement a binary search algorithm to find the correct position for partitioning the two arrays such that elements to the left are less than or equal to elements on the right.
+5. Calculate the median based on the partitioned arrays.
+6. Handle edge cases where one or both arrays are empty or where the combined length is odd or even.
+7. Return the calculated median.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public double findMedianSortedArrays(int[] nums1, int[] nums2) {
+ int m = nums1.length;
+ int n = nums2.length;
+ int totalLength = m + n;
+ int left = (totalLength + 1) / 2;
+ int right = (totalLength + 2) / 2;
+ return (findKth(nums1, 0, nums2, 0, left) + findKth(nums1, 0, nums2, 0, right)) / 2.0;
+ }
+
+ private int findKth(int[] nums1, int i, int[] nums2, int j, int k) {
+ if (i >= nums1.length) return nums2[j + k - 1];
+ if (j >= nums2.length) return nums1[i + k - 1];
+ if (k == 1) return Math.min(nums1[i], nums2[j]);
+
+ int midVal1 = (i + k / 2 - 1 < nums1.length) ? nums1[i + k / 2 - 1] : Integer.MAX_VALUE;
+ int midVal2 = (j + k / 2 - 1 < nums2.length) ? nums2[j + k / 2 - 1] : Integer.MAX_VALUE;
+
+ if (midVal1 < midVal2) {
+ return findKth(nums1, i + k / 2, nums2, j, k - k / 2);
+ } else {
+ return findKth(nums1, i, nums2, j + k / 2, k - k / 2);
+ }
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int[] nums1_1 = {1, 3};
+ int[] nums2_1 = {2};
+ System.out.println("Example 1 Output: " + solution.findMedianSortedArrays(nums1_1, nums2_1));
+
+ int[] nums1_2 = {1, 2};
+ int[] nums2_2 = {3, 4};
+ System.out.println("Example 2 Output: " + solution.findMedianSortedArrays(nums1_2, nums2_2));
+
+ int[] nums1_3 = {0, 0};
+ int[] nums2_3 = {0, 0};
+ System.out.println("Example 3 Output: " + solution.findMedianSortedArrays(nums1_3, nums2_3));
+
+ int[] nums1_4 = {};
+ int[] nums2_4 = {1};
+ System.out.println("Example 4 Output: " + solution.findMedianSortedArrays(nums1_4, nums2_4));
+
+ int[] nums1_5 = {2};
+ int[] nums2_5 = {};
+ System.out.println("Example 5 Output: " + solution.findMedianSortedArrays(nums1_5, nums2_5));
+ }
+}
+```
+
+This implementation provides a solution to the Median of Two Sorted Arrays problem in Java with a runtime complexity of O(log(min(m, n))).
diff --git a/src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java b/src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java
index ba3ec8d5a..684f2f2d5 100644
--- a/src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java
+++ b/src/main/java/g0001_0100/s0005_longest_palindromic_substring/Solution.java
@@ -2,8 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
// #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming
-// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
-// #2023_08_09_Time_7_ms_(97.94%)_Space_41.9_MB_(56.27%)
+// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_09_Time_7_ms_(97.82%)_Space_43_MB_(66.41%)
public class Solution {
public String longestPalindrome(String s) {
diff --git a/src/main/java/g0001_0100/s0005_longest_palindromic_substring/readme.md b/src/main/java/g0001_0100/s0005_longest_palindromic_substring/readme.md
index 883ff5c72..5e3c1c6f4 100644
--- a/src/main/java/g0001_0100/s0005_longest_palindromic_substring/readme.md
+++ b/src/main/java/g0001_0100/s0005_longest_palindromic_substring/readme.md
@@ -2,13 +2,15 @@
Medium
-Given a string `s`, return _the longest palindromic substring_ in `s`.
+Given a string `s`, return _the longest_ _palindromic_ **substring** in `s`.
**Example 1:**
**Input:** s = "babad"
-**Output:** "bab" **Note:** "aba" is also a valid answer.
+**Output:** "bab"
+
+**Explanation:** "aba" is also a valid answer.
**Example 2:**
@@ -16,19 +18,70 @@ Given a string `s`, return _the longest palindromic substring_ in `s`.
**Output:** "bb"
-**Example 3:**
-
-**Input:** s = "a"
-
-**Output:** "a"
-
-**Example 4:**
-
-**Input:** s = "ac"
-
-**Output:** "a"
-
**Constraints:**
* `1 <= s.length <= 1000`
-* `s` consist of only digits and English letters.
\ No newline at end of file
+* `s` consist of only digits and English letters.
+
+To solve the Longest Palindromic Substring problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `longestPalindrome`.
+2. Initialize variables to keep track of the start and end indices of the longest palindromic substring found so far (`start` and `end`).
+3. Iterate through the string `s`:
+ - For each character in the string, expand around it to check if it forms a palindrome.
+ - Handle both odd-length and even-length palindromes separately.
+ - Update `start` and `end` indices if a longer palindrome is found.
+4. Return the substring from `start` to `end`.
+5. Handle edge cases where the input string is empty or has a length of 1.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public String longestPalindrome(String s) {
+ if (s == null || s.length() < 1) return "";
+ int start = 0;
+ int end = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ int len1 = expandAroundCenter(s, i, i);
+ int len2 = expandAroundCenter(s, i, i + 1);
+ int len = Math.max(len1, len2);
+ if (len > end - start) {
+ start = i - (len - 1) / 2;
+ end = i + len / 2;
+ }
+ }
+
+ return s.substring(start, end + 1);
+ }
+
+ private int expandAroundCenter(String s, int left, int right) {
+ while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
+ left--;
+ right++;
+ }
+ return right - left - 1;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String s1 = "babad";
+ System.out.println("Example 1 Output: " + solution.longestPalindrome(s1));
+
+ String s2 = "cbbd";
+ System.out.println("Example 2 Output: " + solution.longestPalindrome(s2));
+
+ String s3 = "a";
+ System.out.println("Example 3 Output: " + solution.longestPalindrome(s3));
+
+ String s4 = "ac";
+ System.out.println("Example 4 Output: " + solution.longestPalindrome(s4));
+ }
+}
+```
+
+This implementation provides a solution to the Longest Palindromic Substring problem in Java.
diff --git a/src/main/java/g0001_0100/s0006_zigzag_conversion/Solution.java b/src/main/java/g0001_0100/s0006_zigzag_conversion/Solution.java
index 7dd682e35..22a8c168a 100644
--- a/src/main/java/g0001_0100/s0006_zigzag_conversion/Solution.java
+++ b/src/main/java/g0001_0100/s0006_zigzag_conversion/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0006_zigzag_conversion;
-// #Medium #String #2023_08_09_Time_2_ms_(99.99%)_Space_43.2_MB_(99.73%)
+// #Medium #String #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_17_Time_2_ms_(99.71%)_Space_44.5_MB_(94.69%)
public class Solution {
public String convert(String s, int numRows) {
diff --git a/src/main/java/g0001_0100/s0006_zigzag_conversion/readme.md b/src/main/java/g0001_0100/s0006_zigzag_conversion/readme.md
index 4f55d57d3..c0842869e 100644
--- a/src/main/java/g0001_0100/s0006_zigzag_conversion/readme.md
+++ b/src/main/java/g0001_0100/s0006_zigzag_conversion/readme.md
@@ -36,4 +36,72 @@ string convert(string s, int numRows);
* `1 <= s.length <= 1000`
* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`.
-* `1 <= numRows <= 1000`
\ No newline at end of file
+* `1 <= numRows <= 1000`
+
+To solve the Zigzag Conversion problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `convert`.
+2. Create an array of strings to represent each row of the zigzag pattern.
+3. Initialize variables to keep track of the current row (`row`) and the direction of traversal (`down`).
+4. Iterate through each character in the input string `s`.
+ - Append the current character to the string representing the current row.
+ - If we reach the first or last row, change the direction of traversal accordingly.
+ - Update the current row based on the direction of traversal.
+5. Concatenate the strings representing each row to form the final zigzag conversion.
+6. Return the concatenated string.
+7. Handle edge cases where the number of rows is 1 or the input string is empty.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public String convert(String s, int numRows) {
+ if (numRows == 1 || s.length() <= numRows) {
+ return s;
+ }
+
+ StringBuilder[] rows = new StringBuilder[numRows];
+ for (int i = 0; i < numRows; i++) {
+ rows[i] = new StringBuilder();
+ }
+
+ int row = 0;
+ boolean down = false;
+
+ for (char c : s.toCharArray()) {
+ rows[row].append(c);
+ if (row == 0 || row == numRows - 1) {
+ down = !down;
+ }
+ row += down ? 1 : -1;
+ }
+
+ StringBuilder result = new StringBuilder();
+ for (StringBuilder sb : rows) {
+ result.append(sb);
+ }
+
+ return result.toString();
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String s1 = "PAYPALISHIRING";
+ int numRows1 = 3;
+ System.out.println("Example 1 Output: " + solution.convert(s1, numRows1));
+
+ String s2 = "PAYPALISHIRING";
+ int numRows2 = 4;
+ System.out.println("Example 2 Output: " + solution.convert(s2, numRows2));
+
+ String s3 = "A";
+ int numRows3 = 1;
+ System.out.println("Example 3 Output: " + solution.convert(s3, numRows3));
+ }
+}
+```
+
+This implementation provides a solution to the Zigzag Conversion problem in Java.
diff --git a/src/main/java/g0001_0100/s0007_reverse_integer/Solution.java b/src/main/java/g0001_0100/s0007_reverse_integer/Solution.java
index 2233567fc..956541482 100644
--- a/src/main/java/g0001_0100/s0007_reverse_integer/Solution.java
+++ b/src/main/java/g0001_0100/s0007_reverse_integer/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0007_reverse_integer;
-// #Medium #Top_Interview_Questions #Math #Udemy_Integers
-// #2023_08_09_Time_1_ms_(99.69%)_Space_39.5_MB_(82.15%)
+// #Medium #Top_Interview_Questions #Math #Udemy_Integers #Big_O_Time_O(log10(x))_Space_O(1)
+// #2024_11_09_Time_0_ms_(100.00%)_Space_40.9_MB_(36.21%)
public class Solution {
public int reverse(int x) {
diff --git a/src/main/java/g0001_0100/s0007_reverse_integer/readme.md b/src/main/java/g0001_0100/s0007_reverse_integer/readme.md
index 81dbb623e..d2a1aae04 100644
--- a/src/main/java/g0001_0100/s0007_reverse_integer/readme.md
+++ b/src/main/java/g0001_0100/s0007_reverse_integer/readme.md
@@ -24,12 +24,67 @@ Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If rev
**Output:** 21
-**Example 4:**
+**Constraints:**
-**Input:** x = 0
+* -231 <= x <= 231 - 1
-**Output:** 0
+To solve the Reverse Integer problem in Java using a `Solution` class, we'll follow these steps:
-**Constraints:**
+1. Define a `Solution` class with a method named `reverse`.
+2. Initialize variables to keep track of the reversed integer (`rev`), the sign of the input integer (`sign`), and the absolute value of the input integer (`x`).
+3. Iterate through each digit of the input integer `x`:
+ - Extract the least significant digit using the modulo operator.
+ - Update the reversed integer `rev` by multiplying it by 10 and adding the extracted digit.
+ - Update `x` by removing the least significant digit using integer division.
+4. Check if the reversed integer `rev` overflows the signed 32-bit integer range. If so, return 0.
+5. Return the reversed integer `rev` with the appropriate sign.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public int reverse(int x) {
+ int rev = 0;
+ int sign = (x < 0) ? -1 : 1;
+ int limit = Integer.MAX_VALUE / 10;
+ int absX = Math.abs(x);
+
+ while (absX > 0) {
+ int digit = absX % 10;
+ absX /= 10;
+
+ if (rev > limit || (rev == limit && digit > 7)) {
+ return 0;
+ }
+
+ if (rev < -limit || (rev == -limit && digit < -8)) {
+ return 0;
+ }
+
+ rev = rev * 10 + digit;
+ }
+
+ return rev * sign;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int x1 = 123;
+ System.out.println("Example 1 Output: " + solution.reverse(x1));
+
+ int x2 = -123;
+ System.out.println("Example 2 Output: " + solution.reverse(x2));
+
+ int x3 = 120;
+ System.out.println("Example 3 Output: " + solution.reverse(x3));
+
+ int x4 = 0;
+ System.out.println("Example 4 Output: " + solution.reverse(x4));
+ }
+}
+```
-* -231 <= x <= 231 - 1
\ No newline at end of file
+This implementation provides a solution to the Reverse Integer problem in Java.
diff --git a/src/main/java/g0001_0100/s0008_string_to_integer_atoi/Solution.java b/src/main/java/g0001_0100/s0008_string_to_integer_atoi/Solution.java
index 41aaa6cdc..760f2d2c9 100644
--- a/src/main/java/g0001_0100/s0008_string_to_integer_atoi/Solution.java
+++ b/src/main/java/g0001_0100/s0008_string_to_integer_atoi/Solution.java
@@ -1,10 +1,11 @@
package g0001_0100.s0008_string_to_integer_atoi;
-// #Medium #Top_Interview_Questions #String #2023_08_09_Time_1_ms_(100.00%)_Space_41_MB_(98.97%)
+// #Medium #Top_Interview_Questions #String #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_09_Time_1_ms_(100.00%)_Space_42_MB_(95.40%)
public class Solution {
public int myAtoi(String str) {
- if (str == null || str.length() == 0) {
+ if (str == null || str.isEmpty()) {
return 0;
}
int i = 0;
diff --git a/src/main/java/g0001_0100/s0008_string_to_integer_atoi/readme.md b/src/main/java/g0001_0100/s0008_string_to_integer_atoi/readme.md
index af67f64cb..86bc9f4fd 100644
--- a/src/main/java/g0001_0100/s0008_string_to_integer_atoi/readme.md
+++ b/src/main/java/g0001_0100/s0008_string_to_integer_atoi/readme.md
@@ -110,4 +110,75 @@ Since -91283472332 is less than the lower bound of the range [-231, 2
**Constraints:**
* `0 <= s.length <= 200`
-* `s` consists of English letters (lower-case and upper-case), digits (`0-9`), `' '`, `'+'`, `'-'`, and `'.'`.
\ No newline at end of file
+* `s` consists of English letters (lower-case and upper-case), digits (`0-9`), `' '`, `'+'`, `'-'`, and `'.'`.
+
+To solve the String to Integer (atoi) problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `myAtoi`.
+2. Trim leading whitespace from the input string `s`.
+3. Check if the string is empty after trimming. If so, return 0.
+4. Initialize variables to keep track of the sign of the integer (`sign`), the starting index of the numeric characters (`start`), and the result (`result`).
+5. Check if the first character of the trimmed string is `'-'` or `'+'`. Update `sign` accordingly, and move the starting index accordingly.
+6. Iterate through the characters of the trimmed string starting from the `start` index:
+ - Check if the current character is a digit. If not, break the loop.
+ - Convert the character to its numeric value and update the `result`.
+ - Check if the result exceeds the 32-bit integer range. If so, clamp it to the range and return.
+7. Multiply the `result` by the sign and return the final value.
+8. Handle edge cases where the input string is empty, consists of only whitespace, or contains non-numeric characters at the beginning.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public int myAtoi(String s) {
+ s = s.trim();
+ if (s.isEmpty())
+ return 0;
+
+ int sign = 1;
+ int start = 0;
+ long result = 0;
+
+ if (s.charAt(0) == '-' || s.charAt(0) == '+') {
+ sign = (s.charAt(0) == '-') ? -1 : 1;
+ start++;
+ }
+
+ for (int i = start; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (!Character.isDigit(c))
+ break;
+ result = result * 10 + (c - '0');
+ if (result * sign > Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ if (result * sign < Integer.MIN_VALUE)
+ return Integer.MIN_VALUE;
+ }
+
+ return (int) (result * sign);
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String s1 = "42";
+ System.out.println("Example 1 Output: " + solution.myAtoi(s1));
+
+ String s2 = " -42";
+ System.out.println("Example 2 Output: " + solution.myAtoi(s2));
+
+ String s3 = "4193 with words";
+ System.out.println("Example 3 Output: " + solution.myAtoi(s3));
+
+ String s4 = "words and 987";
+ System.out.println("Example 4 Output: " + solution.myAtoi(s4));
+
+ String s5 = "-91283472332";
+ System.out.println("Example 5 Output: " + solution.myAtoi(s5));
+ }
+}
+```
+
+This implementation provides a solution to the String to Integer (atoi) problem in Java.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0009_palindrome_number/Solution.java b/src/main/java/g0001_0100/s0009_palindrome_number/Solution.java
index 264175cdc..9993b4e6e 100644
--- a/src/main/java/g0001_0100/s0009_palindrome_number/Solution.java
+++ b/src/main/java/g0001_0100/s0009_palindrome_number/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0009_palindrome_number;
-// #Easy #Math #Udemy_Integers #2023_08_09_Time_4_ms_(100.00%)_Space_43_MB_(43.42%)
+// #Easy #Math #Udemy_Integers #Top_Interview_150_Math #Big_O_Time_O(log10(x))_Space_O(1)
+// #2024_11_09_Time_4_ms_(100.00%)_Space_44.1_MB_(28.20%)
public class Solution {
public boolean isPalindrome(int x) {
diff --git a/src/main/java/g0001_0100/s0009_palindrome_number/readme.md b/src/main/java/g0001_0100/s0009_palindrome_number/readme.md
index f05939bee..232c883cf 100644
--- a/src/main/java/g0001_0100/s0009_palindrome_number/readme.md
+++ b/src/main/java/g0001_0100/s0009_palindrome_number/readme.md
@@ -2,15 +2,15 @@
Easy
-Given an integer `x`, return `true` if `x` is palindrome integer.
-
-An integer is a **palindrome** when it reads the same backward as forward. For example, `121` is palindrome while `123` is not.
+Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
-**Output:** true
+**Output:** true
+
+**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
@@ -28,14 +28,67 @@ An integer is a **palindrome** when it reads the same backward as forward. For e
**Explanation:** Reads 01 from right to left. Therefore it is not a palindrome.
-**Example 4:**
+**Constraints:**
-**Input:** x = -101
+* -231 <= x <= 231 - 1
-**Output:** false
+**Follow up:** Could you solve it without converting the integer to a string?
-**Constraints:**
+To solve the Palindrome Number problem in Java using a `Solution` class, we'll follow these steps:
-* -231 <= x <= 231 - 1
+1. Define a `Solution` class with a method named `isPalindrome`.
+2. Handle special cases where `x` is negative or divisible by 10 but not equal to zero, as they cannot be palindromes.
+3. Initialize variables to keep track of the reversed number (`reversed`) and the original number (`original`).
+4. Iterate through the digits of the original number `x`:
+ - Extract the least significant digit using the modulo operator and append it to the reversed number.
+ - Update `original` by removing the least significant digit using integer division.
+5. Check if the reversed number is equal to the original number. If so, return `true`; otherwise, return `false`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public boolean isPalindrome(int x) {
+ // Special cases:
+ // As discussed, negative numbers are not palindromes.
+ // Also, if the last digit of the number is 0, it can't be a palindrome unless the number is 0 itself.
+ if (x < 0 || (x % 10 == 0 && x != 0)) {
+ return false;
+ }
+
+ int reversed = 0;
+ int original = x;
+
+ while (original > reversed) {
+ int digit = original % 10;
+ reversed = reversed * 10 + digit;
+ original /= 10;
+ }
+
+ // When the length is an odd number, we can get rid of the middle digit by reversed / 10
+ // For example when the input is 12321, at the end of the while loop we get x = 12, reversed = 123,
+ // since the middle digit doesn't matter in palidrome(it will always equal to itself), we can simply get rid of it.
+ return original == reversed || original == reversed / 10;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int x1 = 121;
+ System.out.println("Example 1 Output: " + solution.isPalindrome(x1));
+
+ int x2 = -121;
+ System.out.println("Example 2 Output: " + solution.isPalindrome(x2));
+
+ int x3 = 10;
+ System.out.println("Example 3 Output: " + solution.isPalindrome(x3));
+
+ int x4 = -101;
+ System.out.println("Example 4 Output: " + solution.isPalindrome(x4));
+ }
+}
+```
-**Follow up:** Could you solve it without converting the integer to a string?
\ No newline at end of file
+This implementation provides a solution to the Palindrome Number problem in Java.
diff --git a/src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java b/src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java
index 449c1147a..a8d0e4d62 100644
--- a/src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java
+++ b/src/main/java/g0001_0100/s0010_regular_expression_matching/Solution.java
@@ -1,8 +1,7 @@
package g0001_0100.s0010_regular_expression_matching;
-// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion
-// #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
-// #2023_08_09_Time_1_ms_(100.00%)_Space_41.1_MB_(61.00%)
+// #Hard #Top_Interview_Questions #String #Dynamic_Programming #Recursion #Udemy_Dynamic_Programming
+// #Big_O_Time_O(m*n)_Space_O(m*n) #2024_11_09_Time_1_ms_(100.00%)_Space_41.8_MB_(87.69%)
public class Solution {
private Boolean[][] cache;
diff --git a/src/main/java/g0001_0100/s0010_regular_expression_matching/readme.md b/src/main/java/g0001_0100/s0010_regular_expression_matching/readme.md
index f614e74d1..2d99ab985 100644
--- a/src/main/java/g0001_0100/s0010_regular_expression_matching/readme.md
+++ b/src/main/java/g0001_0100/s0010_regular_expression_matching/readme.md
@@ -33,24 +33,73 @@ The matching should cover the **entire** input string (not partial).
**Explanation:** ".\*" means "zero or more (\*) of any character (.)".
-**Example 4:**
-
-**Input:** s = "aab", p = "c\*a\*b"
-
-**Output:** true
-
-**Explanation:** c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".
-
-**Example 5:**
-
-**Input:** s = "mississippi", p = "mis\*is\*p\*."
-
-**Output:** false
-
**Constraints:**
* `1 <= s.length <= 20`
-* `1 <= p.length <= 30`
+* `1 <= p.length <= 20`
* `s` contains only lowercase English letters.
* `p` contains only lowercase English letters, `'.'`, and `'*'`.
-* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match.
\ No newline at end of file
+* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match.
+
+To solve the Regular Expression Matching problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `isMatch`.
+2. Implement a recursive approach to check for pattern matching.
+3. Base cases:
+ - If the pattern string is empty, return `s.isEmpty()`.
+ - If the pattern string's length is 1 or the next character after `*` is `.`:
+ - Check if the length of `s` is 1 and the characters match or the pattern is `.`.
+ - If so, return `true`; otherwise, return `false`.
+4. If the second character of the pattern is not `*`, recursively call `isMatch` with the substring starting from the second character.
+5. If the second character of the pattern is `*`, recursively check all possibilities:
+ - Zero occurrences of the preceding character (skipping `*` and the character before it).
+ - One or more occurrences of the preceding character (matching the first character and recursively calling `isMatch` for the remaining part of the string).
+6. Return the result of the recursive checks.
+7. Handle edge cases where the input strings are empty or the pattern contains invalid characters.
+
+Here's the implementation:
+
+```java
+public class Solution {
+
+ public boolean isMatch(String s, String p) {
+ if (p.isEmpty())
+ return s.isEmpty();
+
+ boolean firstMatch = !s.isEmpty() && (p.charAt(0) == s.charAt(0) || p.charAt(0) == '.');
+
+ if (p.length() >= 2 && p.charAt(1) == '*') {
+ return isMatch(s, p.substring(2)) || (firstMatch && isMatch(s.substring(1), p));
+ } else {
+ return firstMatch && isMatch(s.substring(1), p.substring(1));
+ }
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String s1 = "aa";
+ String p1 = "a";
+ System.out.println("Example 1 Output: " + solution.isMatch(s1, p1));
+
+ String s2 = "aa";
+ String p2 = "a*";
+ System.out.println("Example 2 Output: " + solution.isMatch(s2, p2));
+
+ String s3 = "ab";
+ String p3 = ".*";
+ System.out.println("Example 3 Output: " + solution.isMatch(s3, p3));
+
+ String s4 = "aab";
+ String p4 = "c*a*b";
+ System.out.println("Example 4 Output: " + solution.isMatch(s4, p4));
+
+ String s5 = "mississippi";
+ String p5 = "mis*is*p*.";
+ System.out.println("Example 5 Output: " + solution.isMatch(s5, p5));
+ }
+}
+```
+
+This implementation provides a solution to the Regular Expression Matching problem in Java.
diff --git a/src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java b/src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java
index d7cffcc95..425a8ffc6 100644
--- a/src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java
+++ b/src/main/java/g0001_0100/s0011_container_with_most_water/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0011_container_with_most_water;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers
-// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_09_Time_3_ms_(94.75%)_Space_56.2_MB_(5.82%)
+// #LeetCode_75_Two_Pointers #Algorithm_II_Day_4_Two_Pointers #Top_Interview_150_Two_Pointers
+// #Big_O_Time_O(n)_Space_O(1) #2024_11_09_Time_3_ms_(96.01%)_Space_57.8_MB_(52.01%)
public class Solution {
public int maxArea(int[] height) {
diff --git a/src/main/java/g0001_0100/s0011_container_with_most_water/readme.md b/src/main/java/g0001_0100/s0011_container_with_most_water/readme.md
index 56788449e..b7c2b8d36 100644
--- a/src/main/java/g0001_0100/s0011_container_with_most_water/readme.md
+++ b/src/main/java/g0001_0100/s0011_container_with_most_water/readme.md
@@ -2,7 +2,11 @@
Medium
-Given `n` non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). `n` vertical lines are drawn such that the two endpoints of the line `i` is at (i, ai) and `(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
+You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the ith line are `(i, 0)` and `(i, height[i])`.
+
+Find two lines that together with the x-axis form a container, such that the container contains the most water.
+
+Return _the maximum amount of water a container can store_.
**Notice** that you may not slant the container.
@@ -22,20 +26,64 @@ Given `n` non-negative integers a1, a2, ..., an
**Output:** 1
-**Example 3:**
-
-**Input:** height = [4,3,2,1,4]
-
-**Output:** 16
-
-**Example 4:**
-
-**Input:** height = [1,2,1]
-
-**Output:** 2
-
**Constraints:**
* `n == height.length`
* 2 <= n <= 105
-* 0 <= height[i] <= 104
\ No newline at end of file
+* 0 <= height[i] <= 104
+
+To solve the Container With Most Water problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `maxArea` that takes an array of integers `height` as input and returns the maximum area of water that can be contained.
+2. Initialize two pointers, `left` pointing to the start of the array and `right` pointing to the end of the array.
+3. Initialize a variable `maxArea` to store the maximum area encountered so far, initially set to 0.
+4. Iterate while `left` is less than `right`.
+5. Calculate the current area using the formula: `(right - left) * min(height[left], height[right])`.
+6. Update `maxArea` if the current area is greater than `maxArea`.
+7. Move the pointer pointing to the smaller height towards the other pointer. If `height[left] < height[right]`, increment `left`, otherwise decrement `right`.
+8. Continue the iteration until `left` becomes greater than or equal to `right`.
+9. Return `maxArea`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int maxArea(int[] height) {
+ int left = 0;
+ int right = height.length - 1;
+ int maxArea = 0;
+
+ while (left < right) {
+ int currentArea = (right - left) * Math.min(height[left], height[right]);
+ maxArea = Math.max(maxArea, currentArea);
+
+ if (height[left] < height[right]) {
+ left++;
+ } else {
+ right--;
+ }
+ }
+
+ return maxArea;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int[] height1 = {1, 8, 6, 2, 5, 4, 8, 3, 7};
+ System.out.println("Example 1 Output: " + solution.maxArea(height1));
+
+ int[] height2 = {1, 1};
+ System.out.println("Example 2 Output: " + solution.maxArea(height2));
+
+ int[] height3 = {4, 3, 2, 1, 4};
+ System.out.println("Example 3 Output: " + solution.maxArea(height3));
+
+ int[] height4 = {1, 2, 1};
+ System.out.println("Example 4 Output: " + solution.maxArea(height4));
+ }
+}
+```
+
+This implementation provides a solution to the Container With Most Water problem in Java.
diff --git a/src/main/java/g0001_0100/s0012_integer_to_roman/Solution.java b/src/main/java/g0001_0100/s0012_integer_to_roman/Solution.java
index 6d609261e..9d3c7fab8 100644
--- a/src/main/java/g0001_0100/s0012_integer_to_roman/Solution.java
+++ b/src/main/java/g0001_0100/s0012_integer_to_roman/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0012_integer_to_roman;
-// #Medium #String #Hash_Table #Math #2023_08_09_Time_2_ms_(100.00%)_Space_43.2_MB_(81.21%)
+// #Medium #String #Hash_Table #Math #Top_Interview_150_Array/String #Big_O_Time_O(1)_Space_O(1)
+// #2025_03_04_Time_2_ms_(100.00%)_Space_44.30_MB_(83.82%)
public class Solution {
public String intToRoman(int num) {
diff --git a/src/main/java/g0001_0100/s0012_integer_to_roman/readme.md b/src/main/java/g0001_0100/s0012_integer_to_roman/readme.md
index 456e0cfec..4e5d58c77 100644
--- a/src/main/java/g0001_0100/s0012_integer_to_roman/readme.md
+++ b/src/main/java/g0001_0100/s0012_integer_to_roman/readme.md
@@ -2,60 +2,55 @@
Medium
-Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
+Seven different symbols represent Roman numerals with the following values:
- Symbol Value
- I 1
- V 5
- X 10
- L 50
- C 100
- D 500
- M 1000
+| Symbol | Value |
+|--------|-------|
+| I | 1 |
+| V | 5 |
+| X | 10 |
+| L | 50 |
+| C | 100 |
+| D | 500 |
+| M | 1000 |
-For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
+Roman numerals are formed by appending the conversions of decimal place values from highest to lowest. Converting a decimal place value into a Roman numeral has the following rules:
-Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
+* If the value does not start with 4 or 9, select the symbol of the maximal value that can be subtracted from the input, append that symbol to the result, subtract its value, and convert the remainder to a Roman numeral.
+* If the value starts with 4 or 9 use the **subtractive form** representing one symbol subtracted from the following symbol, for example, 4 is 1 (`I`) less than 5 (`V`): `IV` and 9 is 1 (`I`) less than 10 (`X`): `IX`. Only the following subtractive forms are used: 4 (`IV`), 9 (`IX`), 40 (`XL`), 90 (`XC`), 400 (`CD`) and 900 (`CM`).
+* Only powers of 10 (`I`, `X`, `C`, `M`) can be appended consecutively at most 3 times to represent multiples of 10. You cannot append 5 (`V`), 50 (`L`), or 500 (`D`) multiple times. If you need to append a symbol 4 times use the **subtractive form**.
-* `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
-* `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
-* `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
-
-Given an integer, convert it to a roman numeral.
+Given an integer, convert it to a Roman numeral.
**Example 1:**
-**Input:** num = 3
-
-**Output:** "III"
-
-**Example 2:**
-
-**Input:** num = 4
+**Input:** num = 3749
-**Output:** "IV"
+**Output:** "MMMDCCXLIX"
-**Example 3:**
+**Explanation:**
-**Input:** num = 9
+3000 = MMM as 1000 (M) + 1000 (M) + 1000 (M) 700 = DCC as 500 (D) + 100 (C) + 100 (C) 40 = XL as 10 (X) less of 50 (L) 9 = IX as 1 (I) less of 10 (X) Note: 49 is not 1 (I) less of 50 (L) because the conversion is based on decimal places
-**Output:** "IX"
-
-**Example 4:**
+**Example 2:**
**Input:** num = 58
**Output:** "LVIII"
-**Explanation:** L = 50, V = 5, III = 3.
+**Explanation:**
-**Example 5:**
+50 = L 8 = VIII
+
+**Example 3:**
**Input:** num = 1994
**Output:** "MCMXCIV"
-**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
+**Explanation:**
+
+1000 = M 900 = CM 90 = XC 4 = IV
**Constraints:**
diff --git a/src/main/java/g0001_0100/s0013_roman_to_integer/Solution.java b/src/main/java/g0001_0100/s0013_roman_to_integer/Solution.java
index ea2210dda..d90f9ef61 100644
--- a/src/main/java/g0001_0100/s0013_roman_to_integer/Solution.java
+++ b/src/main/java/g0001_0100/s0013_roman_to_integer/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0013_roman_to_integer;
-// #Easy #Top_Interview_Questions #String #Hash_Table #Math
-// #2023_08_09_Time_2_ms_(100.00%)_Space_44.1_MB_(19.16%)
+// #Easy #Top_Interview_Questions #String #Hash_Table #Math #Top_Interview_150_Array/String
+// #Big_O_Time_O(n)_Space_O(1) #2025_03_04_Time_2_ms_(100.00%)_Space_44.54_MB_(91.65%)
public class Solution {
public int romanToInt(String s) {
diff --git a/src/main/java/g0001_0100/s0013_roman_to_integer/readme.md b/src/main/java/g0001_0100/s0013_roman_to_integer/readme.md
index 14bbde8ed..2afcaa520 100644
--- a/src/main/java/g0001_0100/s0013_roman_to_integer/readme.md
+++ b/src/main/java/g0001_0100/s0013_roman_to_integer/readme.md
@@ -4,16 +4,17 @@ Easy
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
- Symbol Value
- I 1
- V 5
- X 10
- L 50
- C 100
- D 500
- M 1000
-
-For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
+| Symbol | Value |
+|--------|-------|
+| I | 1 |
+| V | 5 |
+| X | 10 |
+| L | 50 |
+| C | 100 |
+| D | 500 |
+| M | 1000 |
+
+For example, `2` is written as `II` in Roman numeral, just two ones added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
@@ -27,21 +28,11 @@ Given a roman numeral, convert it to an integer.
**Input:** s = "III"
-**Output:** 3
-
-**Example 2:**
-
-**Input:** s = "IV"
-
-**Output:** 4
+**Output:** 3
-**Example 3:**
-
-**Input:** s = "IX"
-
-**Output:** 9
+**Explanation:** III = 3.
-**Example 4:**
+**Example 2:**
**Input:** s = "LVIII"
@@ -49,7 +40,7 @@ Given a roman numeral, convert it to an integer.
**Explanation:** L = 50, V= 5, III = 3.
-**Example 5:**
+**Example 3:**
**Input:** s = "MCMXCIV"
diff --git a/src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java b/src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java
index e7fb786f4..81724a9e2 100644
--- a/src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java
+++ b/src/main/java/g0001_0100/s0014_longest_common_prefix/Solution.java
@@ -1,7 +1,8 @@
package g0001_0100.s0014_longest_common_prefix;
// #Easy #Top_Interview_Questions #String #Level_2_Day_2_String #Udemy_Strings
-// #2023_08_09_Time_0_ms_(100.00%)_Space_40.2_MB_(83.48%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(n*m)_Space_O(m)
+// #2025_03_04_Time_0_ms_(100.00%)_Space_41.35_MB_(87.42%)
public class Solution {
public String longestCommonPrefix(String[] strs) {
@@ -14,7 +15,7 @@ public String longestCommonPrefix(String[] strs) {
String temp = strs[0];
int i = 1;
String cur;
- while (temp.length() > 0 && i < strs.length) {
+ while (!temp.isEmpty() && i < strs.length) {
if (temp.length() > strs[i].length()) {
temp = temp.substring(0, strs[i].length());
}
diff --git a/src/main/java/g0001_0100/s0014_longest_common_prefix/readme.md b/src/main/java/g0001_0100/s0014_longest_common_prefix/readme.md
index 3f23b8c72..f08c69449 100644
--- a/src/main/java/g0001_0100/s0014_longest_common_prefix/readme.md
+++ b/src/main/java/g0001_0100/s0014_longest_common_prefix/readme.md
@@ -24,4 +24,4 @@ If there is no common prefix, return an empty string `""`.
* `1 <= strs.length <= 200`
* `0 <= strs[i].length <= 200`
-* `strs[i]` consists of only lower-case English letters.
\ No newline at end of file
+* `strs[i]` consists of only lowercase English letters if it is non-empty.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0015_3sum/Solution.java b/src/main/java/g0001_0100/s0015_3sum/Solution.java
index 71beab504..b149119d8 100644
--- a/src/main/java/g0001_0100/s0015_3sum/Solution.java
+++ b/src/main/java/g0001_0100/s0015_3sum/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers
// #Data_Structure_II_Day_1_Array #Algorithm_II_Day_3_Two_Pointers #Udemy_Two_Pointers
-// #Big_O_Time_O(n*log(n))_Space_O(n^2) #2023_08_09_Time_27_ms_(97.93%)_Space_51.7_MB_(23.15%)
+// #Top_Interview_150_Two_Pointers #Big_O_Time_O(n*log(n))_Space_O(n^2)
+// #2024_11_09_Time_29_ms_(72.02%)_Space_52_MB_(33.13%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g0001_0100/s0015_3sum/readme.md b/src/main/java/g0001_0100/s0015_3sum/readme.md
index 5a760272d..4fdae92ce 100644
--- a/src/main/java/g0001_0100/s0015_3sum/readme.md
+++ b/src/main/java/g0001_0100/s0015_3sum/readme.md
@@ -10,21 +10,106 @@ Notice that the solution set must not contain duplicate triplets.
**Input:** nums = [-1,0,1,2,-1,-4]
-**Output:** [[-1,-1,2],[-1,0,1]]
+**Output:** [[-1,-1,2],[-1,0,1]]
+
+**Explanation:** nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0. nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0. The distinct triplets are [-1,0,1] and [-1,-1,2]. Notice that the order of the output and the order of the triplets does not matter.
**Example 2:**
-**Input:** nums = []
+**Input:** nums = [0,1,1]
+
+**Output:** []
-**Output:** []
+**Explanation:** The only possible triplet does not sum up to 0.
**Example 3:**
-**Input:** nums = [0]
+**Input:** nums = [0,0,0]
+
+**Output:** [[0,0,0]]
-**Output:** []
+**Explanation:** The only possible triplet sums up to 0.
**Constraints:**
-* `0 <= nums.length <= 3000`
-* -105 <= nums[i] <= 105
\ No newline at end of file
+* `3 <= nums.length <= 3000`
+* -105 <= nums[i] <= 105
+
+To solve the 3Sum problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `threeSum` that takes an array of integers `nums` as input and returns a list of lists representing the triplets that sum up to zero.
+2. Sort the input array `nums` to ensure that duplicate triplets are avoided.
+3. Initialize an empty list `result` to store the triplets.
+4. Iterate over the elements of the sorted array `nums` up to the second to last element.
+5. Within the outer loop, initialize two pointers, `left` and `right`, where `left` starts at the next element after the current element and `right` starts at the last element of the array.
+6. While `left` is less than `right`, check if the sum of the current element (`nums[i]`), `nums[left]`, and `nums[right]` equals zero.
+7. If the sum is zero, add `[nums[i], nums[left], nums[right]]` to the `result` list.
+8. Move the `left` pointer to the right (increment `left`) and the `right` pointer to the left (decrement `right`).
+9. If the sum is less than zero, increment `left`.
+10. If the sum is greater than zero, decrement `right`.
+11. After the inner loop finishes, increment the outer loop index while skipping duplicates.
+12. Return the `result` list containing all the valid triplets.
+
+Here's the implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Solution {
+ public List> threeSum(int[] nums) {
+ Arrays.sort(nums);
+ List> result = new ArrayList<>();
+
+ for (int i = 0; i < nums.length - 2; i++) {
+ if (i > 0 && nums[i] == nums[i - 1]) {
+ continue; // Skip duplicates
+ }
+
+ int left = i + 1;
+ int right = nums.length - 1;
+
+ while (left < right) {
+ int sum = nums[i] + nums[left] + nums[right];
+ if (sum == 0) {
+ result.add(Arrays.asList(nums[i], nums[left], nums[right]));
+
+ // Skip duplicates
+ while (left < right && nums[left] == nums[left + 1]) {
+ left++;
+ }
+ while (left < right && nums[right] == nums[right - 1]) {
+ right--;
+ }
+
+ left++;
+ right--;
+ } else if (sum < 0) {
+ left++;
+ } else {
+ right--;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int[] nums1 = {-1, 0, 1, 2, -1, -4};
+ System.out.println("Example 1 Output: " + solution.threeSum(nums1));
+
+ int[] nums2 = {};
+ System.out.println("Example 2 Output: " + solution.threeSum(nums2));
+
+ int[] nums3 = {0};
+ System.out.println("Example 3 Output: " + solution.threeSum(nums3));
+ }
+}
+```
+
+This implementation provides a solution to the 3Sum problem in Java.
diff --git a/src/main/java/g0001_0100/s0016_3sum_closest/Solution.java b/src/main/java/g0001_0100/s0016_3sum_closest/Solution.java
index 1bf2926c9..c40b93084 100644
--- a/src/main/java/g0001_0100/s0016_3sum_closest/Solution.java
+++ b/src/main/java/g0001_0100/s0016_3sum_closest/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0016_3sum_closest;
// #Medium #Array #Sorting #Two_Pointers #Level_2_Day_14_Sliding_Window/Two_Pointer
-// #2023_08_09_Time_3_ms_(99.88%)_Space_42.6_MB_(97.42%)
+// #2024_02_11_Time_4_ms_(98.21%)_Space_43.4_MB_(27.39%)
import java.util.Arrays;
diff --git a/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java b/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java
index 46bcc7904..ab0971f2e 100644
--- a/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java
+++ b/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.java
@@ -1,8 +1,9 @@
package g0001_0100.s0017_letter_combinations_of_a_phone_number;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking
-// #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
-// #Big_O_Time_O(4^n)_Space_O(n) #2023_08_09_Time_0_ms_(100.00%)_Space_41.3_MB_(58.39%)
+// #LeetCode_75_Backtracking #Algorithm_II_Day_11_Recursion_Backtracking
+// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(4^n)_Space_O(n)
+// #2024_11_09_Time_0_ms_(100.00%)_Space_42.3_MB_(28.63%)
import java.util.ArrayList;
import java.util.Collections;
diff --git a/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md b/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md
index eb7480d41..7525b8dff 100644
--- a/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md
+++ b/src/main/java/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md
@@ -4,9 +4,9 @@ Medium
Given a string containing digits from `2-9` inclusive, return all possible letter combinations that the number could represent. Return the answer in **any order**.
-A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
+A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
-
+
**Example 1:**
@@ -16,17 +16,84 @@ A mapping of digit to letters (just like on the telephone buttons) is given belo
**Example 2:**
-**Input:** digits = ""
-
-**Output:** []
-
-**Example 3:**
-
**Input:** digits = "2"
**Output:** ["a","b","c"]
**Constraints:**
-* `0 <= digits.length <= 4`
-* `digits[i]` is a digit in the range `['2', '9']`.
\ No newline at end of file
+* `1 <= digits.length <= 4`
+* `digits[i]` is a digit in the range `['2', '9']`.
+
+To solve the Letter Combinations of a Phone Number problem in Java using a `Solution` class, we'll follow these steps:
+
+1. Define a `Solution` class with a method named `letterCombinations` that takes a string `digits` as input and returns a list of all possible letter combinations.
+2. Create a mapping of digits to letters using a hashmap or an array.
+3. Initialize an empty list `result` to store the combinations.
+4. If the input string `digits` is empty, return an empty list `result`.
+5. Call a recursive function `generateCombinations` to generate combinations for each digit.
+6. Within the recursive function:
+ - Base case: If the current combination length equals the length of the input `digits`, add the combination to the `result` list.
+ - Recursive step: For the current digit, iterate over its corresponding letters and append each letter to the current combination, then recursively call the function with the next digit.
+7. Return the `result` list containing all possible combinations.
+
+Here's the implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Solution {
+ private static final Map digitToLetters = new HashMap<>();
+ static {
+ digitToLetters.put('2', "abc");
+ digitToLetters.put('3', "def");
+ digitToLetters.put('4', "ghi");
+ digitToLetters.put('5', "jkl");
+ digitToLetters.put('6', "mno");
+ digitToLetters.put('7', "pqrs");
+ digitToLetters.put('8', "tuv");
+ digitToLetters.put('9', "wxyz");
+ }
+
+ public List letterCombinations(String digits) {
+ List result = new ArrayList<>();
+ if (digits.length() == 0) {
+ return result;
+ }
+ generateCombinations(result, digits, "", 0);
+ return result;
+ }
+
+ private void generateCombinations(List result, String digits, String combination, int index) {
+ if (index == digits.length()) {
+ result.add(combination);
+ return;
+ }
+
+ char digit = digits.charAt(index);
+ String letters = digitToLetters.get(digit);
+ for (char letter : letters.toCharArray()) {
+ generateCombinations(result, digits, combination + letter, index + 1);
+ }
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ String digits1 = "23";
+ System.out.println("Example 1 Output: " + solution.letterCombinations(digits1));
+
+ String digits2 = "";
+ System.out.println("Example 2 Output: " + solution.letterCombinations(digits2));
+
+ String digits3 = "2";
+ System.out.println("Example 3 Output: " + solution.letterCombinations(digits3));
+ }
+}
+```
+
+This implementation provides a solution to the Letter Combinations of a Phone Number problem in Java.
diff --git a/src/main/java/g0001_0100/s0018_4sum/Solution.java b/src/main/java/g0001_0100/s0018_4sum/Solution.java
index 308d28bf9..26c352197 100644
--- a/src/main/java/g0001_0100/s0018_4sum/Solution.java
+++ b/src/main/java/g0001_0100/s0018_4sum/Solution.java
@@ -1,6 +1,6 @@
package g0001_0100.s0018_4sum;
-// #Medium #Array #Sorting #Two_Pointers #2023_08_09_Time_3_ms_(99.77%)_Space_43.9_MB_(82.30%)
+// #Medium #Array #Sorting #Two_Pointers #2024_02_11_Time_3_ms_(99.69%)_Space_44.1_MB_(49.13%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java b/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java
index 0d8b75fcc..3fd85800c 100644
--- a/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java
+++ b/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0019_remove_nth_node_from_end_of_list;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Linked_List
-// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Big_O_Time_O(L)_Space_O(L)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_40.4_MB_(88.65%)
+// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Top_Interview_150_Linked_List
+// #Big_O_Time_O(L)_Space_O(L) #2024_11_09_Time_0_ms_(100.00%)_Space_41.4_MB_(87.28%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/readme.md b/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/readme.md
index f2d135d1c..c9562bcbb 100644
--- a/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/readme.md
+++ b/src/main/java/g0001_0100/s0019_remove_nth_node_from_end_of_list/readme.md
@@ -2,7 +2,7 @@
Medium
-Given the `head` of a linked list, remove the `nth` node from the end of the list and return its head.
+Given the `head` of a linked list, remove the nth node from the end of the list and return its head.
**Example 1:**
@@ -31,4 +31,95 @@ Given the `head` of a linked list, remove the `nth` node from the end of the lis
* `0 <= Node.val <= 100`
* `1 <= n <= sz`
-**Follow up:** Could you do this in one pass?
\ No newline at end of file
+**Follow up:** Could you do this in one pass?
+
+To solve the Remove Nth Node From End of List problem in Java with a `Solution` class, we'll follow these steps:
+
+1. Define a `ListNode` class representing the nodes of the linked list.
+2. Define a `Solution` class with a method named `removeNthFromEnd` that takes the head of the linked list and an integer `n` as input and returns the head of the modified list.
+3. Create two pointers, `fast` and `slow`, and initialize them to point to the head of the list.
+4. Move the `fast` pointer `n` steps forward in the list.
+5. If the `fast` pointer reaches the end of the list (`fast == null`), it means that `n` is equal to the length of the list. In this case, remove the head node by returning `head.next`.
+6. Move both `fast` and `slow` pointers simultaneously until the `fast` pointer reaches the end of the list.
+7. At this point, the `slow` pointer will be pointing to the node just before the node to be removed.
+8. Remove the `nth` node by updating the `next` reference of the node pointed to by the `slow` pointer to skip the `nth` node.
+9. Return the head of the modified list.
+
+Here's the implementation:
+
+```java
+public class ListNode {
+ int val;
+ ListNode next;
+ ListNode(int val) { this.val = val; }
+}
+
+public class Solution {
+ public ListNode removeNthFromEnd(ListNode head, int n) {
+ ListNode dummy = new ListNode(0);
+ dummy.next = head;
+ ListNode fast = dummy;
+ ListNode slow = dummy;
+
+ // Move the fast pointer n steps forward
+ for (int i = 0; i <= n; i++) {
+ fast = fast.next;
+ }
+
+ // Move both pointers until the fast pointer reaches the end
+ while (fast != null) {
+ fast = fast.next;
+ slow = slow.next;
+ }
+
+ // Remove the nth node
+ slow.next = slow.next.next;
+
+ return dummy.next;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Example 1
+ ListNode head1 = new ListNode(1);
+ head1.next = new ListNode(2);
+ head1.next.next = new ListNode(3);
+ head1.next.next.next = new ListNode(4);
+ head1.next.next.next.next = new ListNode(5);
+ int n1 = 2;
+ ListNode result1 = solution.removeNthFromEnd(head1, n1);
+ printList(result1); // Output: [1,2,3,5]
+
+ // Example 2
+ ListNode head2 = new ListNode(1);
+ int n2 = 1;
+ ListNode result2 = solution.removeNthFromEnd(head2, n2);
+ printList(result2); // Output: []
+
+ // Example 3
+ ListNode head3 = new ListNode(1);
+ head3.next = new ListNode(2);
+ int n3 = 1;
+ ListNode result3 = solution.removeNthFromEnd(head3, n3);
+ printList(result3); // Output: [1]
+ }
+
+ private static void printList(ListNode head) {
+ if (head == null) {
+ System.out.println("[]");
+ return;
+ }
+ StringBuilder sb = new StringBuilder("[");
+ while (head != null) {
+ sb.append(head.val).append(",");
+ head = head.next;
+ }
+ sb.setLength(sb.length() - 1);
+ sb.append("]");
+ System.out.println(sb.toString());
+ }
+}
+```
+
+This implementation provides a solution to the Remove Nth Node From End of List problem in Java.
diff --git a/src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java b/src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java
index 9df390696..6a7186abf 100644
--- a/src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java
+++ b/src/main/java/g0001_0100/s0020_valid_parentheses/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0020_valid_parentheses;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack
-// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
-// #2023_08_09_Time_2_ms_(90.49%)_Space_40.1_MB_(98.14%)
+// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Top_Interview_150_Stack
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_09_Time_2_ms_(97.19%)_Space_41.8_MB_(17.32%)
import java.util.Stack;
diff --git a/src/main/java/g0001_0100/s0020_valid_parentheses/readme.md b/src/main/java/g0001_0100/s0020_valid_parentheses/readme.md
index c7b608c03..e0ace3610 100644
--- a/src/main/java/g0001_0100/s0020_valid_parentheses/readme.md
+++ b/src/main/java/g0001_0100/s0020_valid_parentheses/readme.md
@@ -8,38 +8,91 @@ An input string is valid if:
1. Open brackets must be closed by the same type of brackets.
2. Open brackets must be closed in the correct order.
+3. Every close bracket has a corresponding open bracket of the same type.
**Example 1:**
**Input:** s = "()"
-**Output:** true
+**Output:** true
**Example 2:**
**Input:** s = "()[]{}"
-**Output:** true
+**Output:** true
**Example 3:**
**Input:** s = "(]"
-**Output:** false
+**Output:** false
**Example 4:**
-**Input:** s = "([)]"
+**Input:** s = "([])"
-**Output:** false
+**Output:** true
**Example 5:**
-**Input:** s = "{[]}"
+**Input:** s = "([)]"
-**Output:** true
+**Output:** false
**Constraints:**
* 1 <= s.length <= 104
-* `s` consists of parentheses only `'()[]{}'`.
\ No newline at end of file
+* `s` consists of parentheses only `'()[]{}'`.
+
+To solve the Valid Parentheses problem in Java with a `Solution` class, we'll use a stack data structure. Here are the steps:
+
+1. Define a `Solution` class with a method named `isValid` that takes a string `s` as input and returns a boolean indicating whether the string contains valid parentheses.
+2. Create a stack to store opening parentheses.
+3. Iterate through each character in the input string `s`.
+4. If the current character is an opening parenthesis (`'('`, `'{'`, or `'['`), push it onto the stack.
+5. If the current character is a closing parenthesis (`')'`, `'}'`, or `']'`), check if the stack is empty. If it is, return `false` because there's no matching opening parenthesis for the current closing parenthesis.
+6. If the stack is not empty, pop the top element from the stack and check if it matches the current closing parenthesis. If it doesn't match, return `false`.
+7. After iterating through all characters in `s`, check if the stack is empty. If it's not empty, return `false` because there are unmatched opening parentheses remaining.
+8. If the stack is empty after processing all characters, return `true` because all parentheses are valid.
+
+Here's the implementation:
+
+```java
+import java.util.Stack;
+
+public class Solution {
+ public boolean isValid(String s) {
+ Stack stack = new Stack<>();
+
+ for (char c : s.toCharArray()) {
+ if (c == '(' || c == '{' || c == '[') {
+ stack.push(c);
+ } else {
+ if (stack.isEmpty()) {
+ return false;
+ }
+ char top = stack.pop();
+ if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) {
+ return false;
+ }
+ }
+ }
+
+ return stack.isEmpty();
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ System.out.println(solution.isValid("()")); // true
+ System.out.println(solution.isValid("()[]{}")); // true
+ System.out.println(solution.isValid("(]")); // false
+ System.out.println(solution.isValid("([)]")); // false
+ System.out.println(solution.isValid("{[]}")); // true
+ }
+}
+```
+
+This implementation provides a solution to the Valid Parentheses problem in Java using a stack data structure.
diff --git a/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java b/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java
index 20e104611..33e3f5a5a 100644
--- a/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java
+++ b/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java
@@ -2,8 +2,8 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
// #Data_Structure_I_Day_7_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
-// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(m+n)_Space_O(m+n)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_40.9_MB_(99.19%)
+// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
+// #Big_O_Time_O(m+n)_Space_O(m+n) #2024_11_09_Time_0_ms_(100.00%)_Space_43_MB_(5.04%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/readme.md b/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/readme.md
index 91a9f1c4a..699679b01 100644
--- a/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/readme.md
+++ b/src/main/java/g0001_0100/s0021_merge_two_sorted_lists/readme.md
@@ -2,25 +2,29 @@
Easy
-Merge two sorted linked lists and return it as a **sorted** list. The list should be made by splicing together the nodes of the first two lists.
+You are given the heads of two sorted linked lists `list1` and `list2`.
+
+Merge the two lists into one **sorted** list. The list should be made by splicing together the nodes of the first two lists.
+
+Return _the head of the merged linked list_.
**Example 1:**

-**Input:** l1 = [1,2,4], l2 = [1,3,4]
+**Input:** list1 = [1,2,4], list2 = [1,3,4]
**Output:** [1,1,2,3,4,4]
**Example 2:**
-**Input:** l1 = [], l2 = []
+**Input:** list1 = [], list2 = []
**Output:** []
**Example 3:**
-**Input:** l1 = [], l2 = [0]
+**Input:** list1 = [], list2 = [0]
**Output:** [0]
@@ -28,4 +32,71 @@ Merge two sorted linked lists and return it as a **sorted** list. The list shoul
* The number of nodes in both lists is in the range `[0, 50]`.
* `-100 <= Node.val <= 100`
-* Both `l1` and `l2` are sorted in **non-decreasing** order.
\ No newline at end of file
+* Both `list1` and `list2` are sorted in **non-decreasing** order.
+
+To solve the Merge Two Sorted Lists problem in Java with a `Solution` class, we'll implement a recursive approach. Here are the steps:
+
+1. Define a `ListNode` class to represent a node in the linked list.
+2. Define a `Solution` class with a method named `mergeTwoLists` that takes two linked lists `l1` and `l2` as input and returns a merged sorted list.
+3. The base case for the recursion is when either `l1` or `l2` is null. In this case, return the non-null list because it's already sorted.
+4. Compare the values of the heads of `l1` and `l2`. Let `head` be the smaller value of the two heads.
+5. Recursively call `mergeTwoLists` with the next node of the smaller head and the other list that remained unchanged.
+6. Update the `next` pointer of the smaller head to point to the result of the recursive call.
+7. Return the smaller head, which is the merged sorted list.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ static class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int val) {
+ this.val = val;
+ }
+ }
+
+ public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
+ if (l1 == null) {
+ return l2;
+ }
+ if (l2 == null) {
+ return l1;
+ }
+
+ ListNode head;
+ if (l1.val < l2.val) {
+ head = l1;
+ head.next = mergeTwoLists(l1.next, l2);
+ } else {
+ head = l2;
+ head.next = mergeTwoLists(l1, l2.next);
+ }
+
+ return head;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ ListNode l1 = new ListNode(1);
+ l1.next = new ListNode(2);
+ l1.next.next = new ListNode(4);
+
+ ListNode l2 = new ListNode(1);
+ l2.next = new ListNode(3);
+ l2.next.next = new ListNode(4);
+
+ ListNode mergedList = solution.mergeTwoLists(l1, l2);
+ while (mergedList != null) {
+ System.out.print(mergedList.val + " ");
+ mergedList = mergedList.next;
+ }
+ System.out.println(); // newline
+ }
+}
+```
+
+This implementation provides a solution to the Merge Two Sorted Lists problem in Java using a recursive approach.
diff --git a/src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java b/src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java
index 7a89c13e7..6314e2e3c 100644
--- a/src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java
+++ b/src/main/java/g0001_0100/s0022_generate_parentheses/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
// #Backtracking #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
-// #Big_O_Time_O(2^n)_Space_O(n) #2023_08_09_Time_0_ms_(100.00%)_Space_41.7_MB_(97.17%)
+// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_42.8_MB_(84.67%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0001_0100/s0022_generate_parentheses/readme.md b/src/main/java/g0001_0100/s0022_generate_parentheses/readme.md
index 72cab17b6..82fb8c528 100644
--- a/src/main/java/g0001_0100/s0022_generate_parentheses/readme.md
+++ b/src/main/java/g0001_0100/s0022_generate_parentheses/readme.md
@@ -18,4 +18,61 @@ Given `n` pairs of parentheses, write a function to _generate all combinations o
**Constraints:**
-* `1 <= n <= 8`
\ No newline at end of file
+* `1 <= n <= 8`
+
+To solve the "Generate Parentheses" problem in Java with a `Solution` class, we can use a backtracking approach. Here are the steps:
+
+1. Define a `Solution` class.
+2. Define a method named `generateParenthesis` that takes an integer `n` as input and returns a list of strings representing all combinations of well-formed parentheses.
+3. Create an empty list to store the result.
+4. Call the recursive helper function `generateParenthesisHelper` with the empty string `""`, counts of open and close parentheses set to `0`, the value of `n`, and the result list.
+5. In the `generateParenthesisHelper` function:
+ - If the length of the current string is equal to `2 * n`, add it to the result list.
+ - If the count of open parentheses is less than `n`, append an open parenthesis to the current string and call the function recursively with increased open count.
+ - If the count of close parentheses is less than the count of open parentheses, append a close parenthesis to the current string and call the function recursively with increased close count.
+6. Return the result list.
+
+Here's the implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.List;
+
+public class Solution {
+ public List generateParenthesis(int n) {
+ List result = new ArrayList<>();
+ generateParenthesisHelper("", 0, 0, n, result);
+ return result;
+ }
+
+ private void generateParenthesisHelper(String current, int open, int close, int n, List result) {
+ if (current.length() == 2 * n) {
+ result.add(current);
+ return;
+ }
+
+ if (open < n) {
+ generateParenthesisHelper(current + "(", open + 1, close, n, result);
+ }
+
+ if (close < open) {
+ generateParenthesisHelper(current + ")", open, close + 1, n, result);
+ }
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test cases
+ int n1 = 3;
+ System.out.println("Parentheses combinations for n = " + n1 + ":");
+ System.out.println(solution.generateParenthesis(n1));
+
+ int n2 = 1;
+ System.out.println("\nParentheses combinations for n = " + n2 + ":");
+ System.out.println(solution.generateParenthesis(n2));
+ }
+}
+```
+
+This implementation provides a solution to the "Generate Parentheses" problem in Java using a backtracking approach.
diff --git a/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/Solution.java b/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/Solution.java
index ba7be8884..36f8e720a 100644
--- a/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/Solution.java
+++ b/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0023_merge_k_sorted_lists;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List
-// #Divide_and_Conquer #Merge_Sort #Big_O_Time_O(k*n*log(k))_Space_O(log(k))
-// #2023_08_09_Time_1_ms_(100.00%)_Space_42.9_MB_(98.59%)
+// #Divide_and_Conquer #Merge_Sort #Top_Interview_150_Divide_and_Conquer
+// #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) #2024_11_10_Time_1_ms_(99.86%)_Space_44.1_MB_(79.93%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/readme.md b/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/readme.md
index f7a1b18b8..a96a7d090 100644
--- a/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/readme.md
+++ b/src/main/java/g0001_0100/s0023_merge_k_sorted_lists/readme.md
@@ -12,7 +12,7 @@ _Merge all the linked-lists into one sorted linked-list and return it._
**Output:** [1,1,2,3,4,4,5,6]
-**Explanation:** The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6
+**Explanation:** The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted linked list: 1->1->2->3->4->4->5->6
**Example 2:**
@@ -29,8 +29,105 @@ _Merge all the linked-lists into one sorted linked-list and return it._
**Constraints:**
* `k == lists.length`
-* `0 <= k <= 10^4`
+* 0 <= k <= 104
* `0 <= lists[i].length <= 500`
-* `-10^4 <= lists[i][j] <= 10^4`
+* -104 <= lists[i][j] <= 104
* `lists[i]` is sorted in **ascending order**.
-* The sum of `lists[i].length` won't exceed `10^4`.
\ No newline at end of file
+* The sum of `lists[i].length` will not exceed 104.
+
+To solve the "Merge k Sorted Lists" problem in Java with a `Solution` class, we can use a priority queue (min-heap) to efficiently merge the lists. Here are the steps:
+
+1. Define a `Solution` class.
+2. Define a method named `mergeKLists` that takes an array of linked lists `lists` as input and returns a single sorted linked list.
+3. Create a priority queue of ListNode objects. We will use this priority queue to store the heads of each linked list.
+4. Iterate through each linked list in the input array `lists` and add the head node of each list to the priority queue.
+5. Create a dummy ListNode object to serve as the head of the merged sorted linked list.
+6. Initialize a ListNode object named `current` to point to the dummy node.
+7. While the priority queue is not empty:
+ - Remove the ListNode with the smallest value from the priority queue.
+ - Add this node to the merged linked list by setting the `next` pointer of the `current` node to this node.
+ - Move the `current` pointer to the next node in the merged linked list.
+ - If the removed node has a `next` pointer, add the next node from the same list to the priority queue.
+8. Return the `next` pointer of the dummy node, which points to the head of the merged sorted linked list.
+
+Here's the implementation:
+
+```java
+import java.util.PriorityQueue;
+
+public class Solution {
+ public ListNode mergeKLists(ListNode[] lists) {
+ PriorityQueue minHeap = new PriorityQueue<>((a, b) -> a.val - b.val);
+
+ // Add the heads of all lists to the priority queue
+ for (ListNode node : lists) {
+ if (node != null) {
+ minHeap.offer(node);
+ }
+ }
+
+ // Create a dummy node to serve as the head of the merged list
+ ListNode dummy = new ListNode(0);
+ ListNode current = dummy;
+
+ // Merge the lists
+ while (!minHeap.isEmpty()) {
+ ListNode minNode = minHeap.poll();
+ current.next = minNode;
+ current = current.next;
+
+ if (minNode.next != null) {
+ minHeap.offer(minNode.next);
+ }
+ }
+
+ return dummy.next;
+ }
+
+ public static void main(String[] args) {
+ Solution solution = new Solution();
+
+ // Test case
+ ListNode[] lists = new ListNode[] {
+ ListNode.createList(new int[] {1, 4, 5}),
+ ListNode.createList(new int[] {1, 3, 4}),
+ ListNode.createList(new int[] {2, 6})
+ };
+ System.out.println("Merged list:");
+ ListNode.printList(solution.mergeKLists(lists));
+ }
+}
+
+class ListNode {
+ int val;
+ ListNode next;
+
+ ListNode(int val) {
+ this.val = val;
+ }
+
+ static ListNode createList(int[] arr) {
+ if (arr == null || arr.length == 0) {
+ return null;
+ }
+
+ ListNode dummy = new ListNode(0);
+ ListNode current = dummy;
+ for (int num : arr) {
+ current.next = new ListNode(num);
+ current = current.next;
+ }
+ return dummy.next;
+ }
+
+ static void printList(ListNode head) {
+ while (head != null) {
+ System.out.print(head.val + " ");
+ head = head.next;
+ }
+ System.out.println();
+ }
+}
+```
+
+This implementation provides a solution to the "Merge k Sorted Lists" problem in Java using a priority queue.
diff --git a/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java b/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java
index 11e0d4d20..a703090e4 100644
--- a/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java
+++ b/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_12_Linked_List
// #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_40.7_MB_(10.83%)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_41.4_MB_(20.29%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/readme.md b/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/readme.md
index 0bac19e2e..9a33becba 100644
--- a/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/readme.md
+++ b/src/main/java/g0001_0100/s0024_swap_nodes_in_pairs/readme.md
@@ -6,25 +6,82 @@ Given a linked list, swap every two adjacent nodes and return its head. You must
**Example 1:**
-
-
**Input:** head = [1,2,3,4]
-**Output:** [2,1,4,3]
+**Output:** [2,1,4,3]
+
+**Explanation:**
+
+
**Example 2:**
**Input:** head = []
-**Output:** []
+**Output:** []
**Example 3:**
**Input:** head = [1]
-**Output:** [1]
+**Output:** [1]
+
+**Example 4:**
+
+**Input:** head = [1,2,3]
+
+**Output:** [2,1,3]
**Constraints:**
* The number of nodes in the list is in the range `[0, 100]`.
-* `0 <= Node.val <= 100`
\ No newline at end of file
+* `0 <= Node.val <= 100`
+
+To solve the "Swap Nodes in Pairs" problem in Java with a `Solution` class, we can traverse the linked list while swapping pairs of nodes. Here are the steps:
+
+1. Define a `Solution` class.
+2. Define a method named `swapPairs` that takes the head of a linked list as input and returns the head of the modified list.
+3. Create a dummy ListNode object and set its `next` pointer to the head of the input list. This dummy node will serve as the new head of the modified list.
+4. Initialize three pointers: `prev`, `first`, and `second`.
+5. Iterate through the list while `first` and `second` are not null:
+ - Assign `first` to the `next` pointer of `prev`.
+ - Assign `second` to the `next` pointer of `first`.
+ - Assign the `next` pointer of `prev` to the `next` pointer of `second`.
+ - Assign the `next` pointer of `second` to `first`.
+ - Move `prev` to `first`.
+ - Move `first` to `first.next` (which is the next pair of nodes).
+6. Return the `next` pointer of the dummy node, which points to the head of the modified list.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public ListNode swapPairs(ListNode head) {
+ // Create a dummy node and point its next to the head
+ ListNode dummy = new ListNode(0);
+ dummy.next = head;
+
+ // Initialize pointers
+ ListNode prev = dummy;
+ ListNode first, second;
+
+ // Swap pairs of nodes
+ while (prev.next != null && prev.next.next != null) {
+ first = prev.next;
+ second = first.next;
+
+ // Swap nodes
+ prev.next = second;
+ first.next = second.next;
+ second.next = first;
+
+ // Move prev to the next pair of nodes
+ prev = first;
+ }
+
+ return dummy.next;
+ }
+}
+```
+
+This implementation provides a solution to the "Swap Nodes in Pairs" problem in Java without modifying the values in the list's nodes.
diff --git a/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java b/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java
index acc306ca2..867bdb3ca 100644
--- a/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java
+++ b/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0025_reverse_nodes_in_k_group;
// #Hard #Top_100_Liked_Questions #Linked_List #Recursion #Data_Structure_II_Day_13_Linked_List
-// #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(k)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_43_MB_(88.08%)
+// #Udemy_Linked_List #Top_Interview_150_Linked_List #Big_O_Time_O(n)_Space_O(k)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_44.4_MB_(33.90%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/readme.md b/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/readme.md
index 35830983a..5740b8cd6 100644
--- a/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/readme.md
+++ b/src/main/java/g0001_0100/s0025_reverse_nodes_in_k_group/readme.md
@@ -2,9 +2,9 @@
Hard
-Given a linked list, reverse the nodes of a linked list _k_ at a time and return its modified list.
+Given the `head` of a linked list, reverse the nodes of the list `k` at a time, and return _the modified list_.
-_k_ is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of _k_ then left-out nodes, in the end, should remain as it is.
+`k` is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of `k` then left-out nodes, in the end, should remain as it is.
You may not alter the values in the list's nodes, only nodes themselves may be changed.
@@ -24,23 +24,76 @@ You may not alter the values in the list's nodes, only nodes themselves may be c
**Output:** [3,2,1,4,5]
-**Example 3:**
-
-**Input:** head = [1,2,3,4,5], k = 1
-
-**Output:** [1,2,3,4,5]
-
-**Example 4:**
-
-**Input:** head = [1], k = 1
-
-**Output:** [1]
-
**Constraints:**
-* The number of nodes in the list is in the range `sz`.
-* `1 <= sz <= 5000`
+* The number of nodes in the list is `n`.
+* `1 <= k <= n <= 5000`
* `0 <= Node.val <= 1000`
-* `1 <= k <= sz`
-**Follow-up:** Can you solve the problem in O(1) extra memory space?
\ No newline at end of file
+**Follow-up:** Can you solve the problem in `O(1)` extra memory space?
+
+To solve the "Reverse Nodes in k-Group" problem in Java with a `Solution` class, we can reverse the nodes in groups of k using a recursive approach. Here are the steps:
+
+1. Define a `Solution` class.
+2. Define a method named `reverseKGroup` that takes the head of a linked list and an integer k as input and returns the head of the modified list.
+3. Define a helper method named `reverse` that takes the head and tail of a sublist as input and reverses the sublist in place. This method returns the new head of the sublist.
+4. Create a dummy ListNode object and set its `next` pointer to the head of the input list. This dummy node will serve as the new head of the modified list.
+5. Initialize pointers `prev`, `curr`, `next`, and `tail`. Set `prev` and `tail` to the dummy node, and `curr` to the head of the input list.
+6. Iterate through the list:
+ - Move `curr` k steps forward. If it's not possible (i.e., there are less than k nodes left), break the loop.
+ - Set `next` to the `next` pointer of `curr`.
+ - Reverse the sublist from `curr` to `next` using the `reverse` method. Update `prev` and `tail` accordingly.
+ - Move `prev` and `tail` k steps forward to the last node of the reversed sublist.
+ - Move `curr` to `next`.
+7. Return the `next` pointer of the dummy node, which points to the head of the modified list.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public ListNode reverseKGroup(ListNode head, int k) {
+ // Create a dummy node and point its next to the head
+ ListNode dummy = new ListNode(0);
+ dummy.next = head;
+
+ // Initialize pointers
+ ListNode prev = dummy, curr = head, next, tail;
+
+ // Iterate through the list and reverse in groups of k
+ while (true) {
+ // Move curr k steps forward
+ tail = prev;
+ for (int i = 0; i < k; i++) {
+ tail = tail.next;
+ if (tail == null) return dummy.next; // Less than k nodes left
+ }
+
+ next = tail.next; // Save the next pointer of the sublist
+ tail.next = null; // Disconnect the sublist from the rest of the list
+
+ // Reverse the sublist and update prev and tail pointers
+ prev.next = reverse(curr, tail);
+ tail.next = next; // Connect the reversed sublist back to the rest of the list
+
+ // Move prev, tail, and curr to the next group
+ prev = curr;
+ curr = next;
+ }
+ }
+
+ // Helper method to reverse a sublist from head to tail
+ private ListNode reverse(ListNode head, ListNode tail) {
+ ListNode prev = null, curr = head, next;
+ while (curr != null) {
+ next = curr.next;
+ curr.next = prev;
+ prev = curr;
+ curr = next;
+ if (prev == tail) break;
+ }
+ return prev; // Return the new head of the reversed sublist
+ }
+}
+```
+
+This implementation provides a solution to the "Reverse Nodes in k-Group" problem in Java without modifying the values in the list's nodes. It recursively reverses the nodes in groups of k.
diff --git a/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java b/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java
index 08b3d31a8..fbb8ec9e8 100644
--- a/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java
+++ b/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0026_remove_duplicates_from_sorted_array;
// #Easy #Top_Interview_Questions #Array #Two_Pointers #Udemy_Two_Pointers
-// #2023_08_09_Time_1_ms_(98.56%)_Space_43.9_MB_(51.95%)
+// #Top_Interview_150_Array/String #2025_03_04_Time_0_ms_(100.00%)_Space_44.59_MB_(95.49%)
public class Solution {
public int removeDuplicates(int[] nums) {
diff --git a/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md b/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md
index b4e776e2b..9df434879 100644
--- a/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md
+++ b/src/main/java/g0001_0100/s0026_remove_duplicates_from_sorted_array/readme.md
@@ -4,11 +4,9 @@ Easy
Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears only **once**. The **relative order** of the elements should be kept the **same**.
-Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.
+Consider the number of _unique elements_ in `nums` to be `k`. After removing duplicates, return the number of unique elements `k`.
-Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`.
-
-Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.
+The first `k` elements of `nums` should contain the unique numbers in **sorted order**. The remaining elements beyond index `k - 1` can be ignored.
**Custom Judge:**
@@ -22,7 +20,7 @@ The judge will test your solution with the following code:
assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
assert nums[i] == expectedNums[i];
- }
+ }
If all assertions pass, then your solution will be **accepted**.
@@ -44,6 +42,6 @@ If all assertions pass, then your solution will be **accepted**.
**Constraints:**
-* 0 <= nums.length <= 3 * 104
+* 1 <= nums.length <= 3 * 104
* `-100 <= nums[i] <= 100`
-* `nums` is sorted in **non-decreasing** order.
\ No newline at end of file
+* `nums` is sorted in **non-decreasing** order.
diff --git a/src/main/java/g0001_0100/s0027_remove_element/Solution.java b/src/main/java/g0001_0100/s0027_remove_element/Solution.java
index 40269cd1f..daec6473f 100644
--- a/src/main/java/g0001_0100/s0027_remove_element/Solution.java
+++ b/src/main/java/g0001_0100/s0027_remove_element/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0027_remove_element;
-// #Easy #Array #Two_Pointers #2023_08_09_Time_0_ms_(100.00%)_Space_40.9_MB_(87.68%)
+// #Easy #Array #Two_Pointers #Top_Interview_150_Array/String
+// #2025_03_04_Time_0_ms_(100.00%)_Space_42.15_MB_(29.50%)
public class Solution {
public int removeElement(int[] nums, int val) {
diff --git a/src/main/java/g0001_0100/s0027_remove_element/readme.md b/src/main/java/g0001_0100/s0027_remove_element/readme.md
index 027b058d6..a0baa21ba 100644
--- a/src/main/java/g0001_0100/s0027_remove_element/readme.md
+++ b/src/main/java/g0001_0100/s0027_remove_element/readme.md
@@ -2,13 +2,12 @@
Easy
-Given an integer array `nums` and an integer `val`, remove all occurrences of `val` in `nums` [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm). The relative order of the elements may be changed.
+Given an integer array `nums` and an integer `val`, remove all occurrences of `val` in `nums` [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm). The order of the elements may be changed. Then return _the number of elements in_ `nums` _which are not equal to_ `val`.
-Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.
+Consider the number of elements in `nums` which are not equal to `val` be `k`, to get accepted, you need to do the following things:
-Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`.
-
-Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.
+* Change the array `nums` such that the first `k` elements of `nums` contain the elements which are not equal to `val`. The remaining elements of `nums` are not important as well as the size of `nums`.
+* Return `k`.
**Custom Judge:**
@@ -25,7 +24,7 @@ The judge will test your solution with the following code:
sort(nums, 0, k); // Sort the first k elements of nums
for (int i = 0; i < actualLength; i++) {
assert nums[i] == expectedNums[i];
- }
+ }
If all assertions pass, then your solution will be **accepted**.
@@ -49,4 +48,4 @@ If all assertions pass, then your solution will be **accepted**.
* `0 <= nums.length <= 100`
* `0 <= nums[i] <= 50`
-* `0 <= val <= 100`
\ No newline at end of file
+* `0 <= val <= 100`
diff --git a/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java b/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java
index e4c83db91..5ee8841d3 100644
--- a/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java
+++ b/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.java
@@ -1,7 +1,8 @@
package g0001_0100.s0028_find_the_index_of_the_first_occurrence_in_a_string;
// #Easy #Top_Interview_Questions #String #Two_Pointers #String_Matching
-// #Programming_Skills_II_Day_1 #2023_08_09_Time_0_ms_(100.00%)_Space_40.5_MB_(71.14%)
+// #Programming_Skills_II_Day_1 #Top_Interview_150_Array/String
+// #2025_03_04_Time_0_ms_(100.00%)_Space_41.19_MB_(97.77%)
public class Solution {
public int strStr(String haystack, String needle) {
diff --git a/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md b/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md
index 098bd2485..16b5a75d9 100644
--- a/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md
+++ b/src/main/java/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/readme.md
@@ -1,36 +1,26 @@
-28\. Implement strStr()
+28\. Find the Index of the First Occurrence in a String
Easy
-Implement [strStr()](http://www.cplusplus.com/reference/cstring/strstr/).
-
-Return the index of the first occurrence of needle in haystack, or `-1` if `needle` is not part of `haystack`.
-
-**Clarification:**
-
-What should we return when `needle` is an empty string? This is a great question to ask during an interview.
-
-For the purpose of this problem, we will return 0 when `needle` is an empty string. This is consistent to C's [strstr()](http://www.cplusplus.com/reference/cstring/strstr/) and Java's [indexOf()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)).
+Given two strings `needle` and `haystack`, return the index of the first occurrence of `needle` in `haystack`, or `-1` if `needle` is not part of `haystack`.
**Example 1:**
-**Input:** haystack = "hello", needle = "ll"
+**Input:** haystack = "sadbutsad", needle = "sad"
-**Output:** 2
+**Output:** 0
-**Example 2:**
-
-**Input:** haystack = "aaaaa", needle = "bba"
+**Explanation:** "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0.
-**Output:** -1
+**Example 2:**
-**Example 3:**
+**Input:** haystack = "leetcode", needle = "leeto"
-**Input:** haystack = "", needle = ""
+**Output:** -1
-**Output:** 0
+**Explanation:** "leeto" did not occur in "leetcode", so we return -1.
**Constraints:**
-* 0 <= haystack.length, needle.length <= 5 * 104
-* `haystack` and `needle` consist of only lower-case English characters.
\ No newline at end of file
+* 1 <= haystack.length, needle.length <= 104
+* `haystack` and `needle` consist of only lowercase English characters.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/Solution.java b/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/Solution.java
index fc5555626..38f97036a 100644
--- a/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/Solution.java
+++ b/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/Solution.java
@@ -1,50 +1,50 @@
package g0001_0100.s0030_substring_with_concatenation_of_all_words;
-// #Hard #String #Hash_Table #Sliding_Window #2023_08_09_Time_1472_ms_(34.43%)_Space_45_MB_(24.98%)
+// #Hard #String #Hash_Table #Sliding_Window #Top_Interview_150_Sliding_Window
+// #2025_03_04_Time_11_ms_(97.43%)_Space_45.96_MB_(24.38%)
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-@SuppressWarnings("java:S127")
public class Solution {
public List findSubstring(String s, String[] words) {
- List indices = new ArrayList<>();
- if (words.length == 0) {
- return indices;
+ List ans = new ArrayList<>();
+ int n1 = words[0].length();
+ int n2 = s.length();
+ Map map1 = new HashMap<>();
+ for (String ch : words) {
+ map1.put(ch, map1.getOrDefault(ch, 0) + 1);
}
- // Put each word into a HashMap and calculate word frequency
- Map wordMap = new HashMap<>();
- for (String word : words) {
- wordMap.put(word, wordMap.getOrDefault(word, 0) + 1);
- }
- int wordLength = words[0].length();
- int window = words.length * wordLength;
- for (int i = 0; i < wordLength; i++) {
- // move a word's length each time
- for (int j = i; j + window <= s.length(); j = j + wordLength) {
- // get the subStr
- String subStr = s.substring(j, j + window);
- Map map = new HashMap<>();
- // start from the last word
- for (int k = words.length - 1; k >= 0; k--) {
- // get the word from subStr
- String word = subStr.substring(k * wordLength, (k + 1) * wordLength);
- int count = map.getOrDefault(word, 0) + 1;
- // if the num of the word is greater than wordMap's, move (k * wordLength) and
- // break
- if (count > wordMap.getOrDefault(word, 0)) {
- j = j + k * wordLength;
- break;
- } else if (k == 0) {
- indices.add(j);
- } else {
- map.put(word, count);
+ for (int i = 0; i < n1; i++) {
+ int left = i;
+ int j = i;
+ int c = 0;
+ Map map2 = new HashMap<>();
+ while (j + n1 <= n2) {
+ String word1 = s.substring(j, j + n1);
+ j += n1;
+ if (map1.containsKey(word1)) {
+ map2.put(word1, map2.getOrDefault(word1, 0) + 1);
+ c++;
+ while (map2.get(word1) > map1.get(word1)) {
+ String word2 = s.substring(left, left + n1);
+ map2.put(word2, map2.get(word2) - 1);
+ left += n1;
+ c--;
+ }
+ if (c == words.length) {
+ ans.add(left);
}
+ } else {
+ map2.clear();
+ c = 0;
+ left = j;
}
}
}
- return indices;
+
+ return ans;
}
}
diff --git a/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md b/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md
index e4075f47a..a288f65e2 100644
--- a/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md
+++ b/src/main/java/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md
@@ -2,9 +2,13 @@
Hard
-You are given a string `s` and an array of strings `words` of **the same length**. Return all starting indices of substring(s) in `s` that is a concatenation of each word in `words` **exactly once**, **in any order**, and **without any intervening characters**.
+You are given a string `s` and an array of strings `words`. All the strings of `words` are of **the same length**.
-You can return the answer in **any order**.
+A **concatenated string** is a string that exactly contains all the strings of any permutation of `words` concatenated.
+
+* For example, if `words = ["ab","cd","ef"]`, then `"abcdef"`, `"abefcd"`, `"cdabef"`, `"cdefab"`, `"efabcd"`, and `"efcdab"` are all concatenated strings. `"acdbef"` is not a concatenated string because it is not the concatenation of any permutation of `words`.
+
+Return an array of _the starting indices_ of all the concatenated substrings in `s`. You can return the answer in **any order**.
**Example 1:**
@@ -12,24 +16,36 @@ You can return the answer in **any order**.
**Output:** [0,9]
-**Explanation:** Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively. The output order does not matter, returning [9,0] is fine too.
+**Explanation:**
+
+The substring starting at 0 is `"barfoo"`. It is the concatenation of `["bar","foo"]` which is a permutation of `words`.
+ The substring starting at 9 is `"foobar"`. It is the concatenation of `["foo","bar"]` which is a permutation of `words`.
**Example 2:**
**Input:** s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
-**Output:** []
+**Output:** []
+
+**Explanation:**
+
+There is no concatenated substring.
**Example 3:**
**Input:** s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
-**Output:** [6,9,12]
+**Output:** [6,9,12]
+
+**Explanation:**
+
+The substring starting at 6 is `"foobarthe"`. It is the concatenation of `["foo","bar","the"]`.
+ The substring starting at 9 is `"barthefoo"`. It is the concatenation of `["bar","the","foo"]`.
+ The substring starting at 12 is `"thefoobar"`. It is the concatenation of `["the","foo","bar"]`.
**Constraints:**
* 1 <= s.length <= 104
-* `s` consists of lower-case English letters.
* `1 <= words.length <= 5000`
* `1 <= words[i].length <= 30`
-* `words[i]` consists of lower-case English letters.
\ No newline at end of file
+* `s` and `words[i]` consist of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0031_next_permutation/Solution.java b/src/main/java/g0001_0100/s0031_next_permutation/Solution.java
index 5df1412a6..302912114 100644
--- a/src/main/java/g0001_0100/s0031_next_permutation/Solution.java
+++ b/src/main/java/g0001_0100/s0031_next_permutation/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0031_next_permutation;
// #Medium #Top_100_Liked_Questions #Array #Two_Pointers #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_42_MB_(90.28%)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_43_MB_(39.33%)
public class Solution {
public void nextPermutation(int[] nums) {
diff --git a/src/main/java/g0001_0100/s0031_next_permutation/readme.md b/src/main/java/g0001_0100/s0031_next_permutation/readme.md
index bf3ed98b9..ceb7d0b9a 100644
--- a/src/main/java/g0001_0100/s0031_next_permutation/readme.md
+++ b/src/main/java/g0001_0100/s0031_next_permutation/readme.md
@@ -2,9 +2,17 @@
Medium
-Implement **next permutation**, which rearranges numbers into the lexicographically next greater permutation of numbers.
+A **permutation** of an array of integers is an arrangement of its members into a sequence or linear order.
-If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).
+* For example, for `arr = [1,2,3]`, the following are all the permutations of `arr`: `[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]`.
+
+The **next permutation** of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the **next permutation** of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).
+
+* For example, the next permutation of `arr = [1,2,3]` is `[1,3,2]`.
+* Similarly, the next permutation of `arr = [2,3,1]` is `[3,1,2]`.
+* While the next permutation of `arr = [3,2,1]` is `[1,2,3]` because `[3,2,1]` does not have a lexicographical larger rearrangement.
+
+Given an array of integers `nums`, _find the next permutation of_ `nums`.
The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algorithm)** and use only constant extra memory.
@@ -26,13 +34,68 @@ The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algor
**Output:** [1,5,1]
-**Example 4:**
-
-**Input:** nums = [1]
-
-**Output:** [1]
-
**Constraints:**
* `1 <= nums.length <= 100`
-* `0 <= nums[i] <= 100`
\ No newline at end of file
+* `0 <= nums[i] <= 100`
+
+To solve the "Next Permutation" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `nextPermutation` that takes an integer array `nums` as input and modifies it to find the next permutation in lexicographic order.
+3. Find the first index `i` from the right such that `nums[i] > nums[i - 1]`. If no such index exists, reverse the entire array, as it's already the last permutation.
+4. Find the smallest index `j` from the right such that `nums[j] > nums[i - 1]`.
+5. Swap `nums[i - 1]` with `nums[j]`.
+6. Reverse the suffix of the array starting from index `i`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public void nextPermutation(int[] nums) {
+ int n = nums.length;
+
+ // Step 1: Find the first index i from the right such that nums[i] > nums[i - 1]
+ int i = n - 1;
+ while (i > 0 && nums[i] <= nums[i - 1]) {
+ i--;
+ }
+
+ // Step 2: If no such index exists, reverse the entire array
+ if (i == 0) {
+ reverse(nums, 0, n - 1);
+ return;
+ }
+
+ // Step 3: Find the smallest index j from the right such that nums[j] > nums[i - 1]
+ int j = n - 1;
+ while (nums[j] <= nums[i - 1]) {
+ j--;
+ }
+
+ // Step 4: Swap nums[i - 1] with nums[j]
+ swap(nums, i - 1, j);
+
+ // Step 5: Reverse the suffix of the array starting from index i
+ reverse(nums, i, n - 1);
+ }
+
+ // Helper method to reverse a portion of the array
+ private void reverse(int[] nums, int start, int end) {
+ while (start < end) {
+ swap(nums, start, end);
+ start++;
+ end--;
+ }
+ }
+
+ // Helper method to swap two elements in the array
+ private void swap(int[] nums, int i, int j) {
+ int temp = nums[i];
+ nums[i] = nums[j];
+ nums[j] = temp;
+ }
+}
+```
+
+This implementation provides a solution to the "Next Permutation" problem in Java. It finds the next lexicographically greater permutation of the given array `nums` and modifies it in place.
diff --git a/src/main/java/g0001_0100/s0032_longest_valid_parentheses/Solution.java b/src/main/java/g0001_0100/s0032_longest_valid_parentheses/Solution.java
index 89a313ae3..6189d4256 100644
--- a/src/main/java/g0001_0100/s0032_longest_valid_parentheses/Solution.java
+++ b/src/main/java/g0001_0100/s0032_longest_valid_parentheses/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0032_longest_valid_parentheses;
// #Hard #Top_100_Liked_Questions #String #Dynamic_Programming #Stack #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_09_Time_1_ms_(100.00%)_Space_41.4_MB_(85.22%)
+// #2024_11_10_Time_1_ms_(99.74%)_Space_42.2_MB_(80.93%)
public class Solution {
public int longestValidParentheses(String s) {
diff --git a/src/main/java/g0001_0100/s0032_longest_valid_parentheses/readme.md b/src/main/java/g0001_0100/s0032_longest_valid_parentheses/readme.md
index f11141d48..4f7ba516e 100644
--- a/src/main/java/g0001_0100/s0032_longest_valid_parentheses/readme.md
+++ b/src/main/java/g0001_0100/s0032_longest_valid_parentheses/readme.md
@@ -2,7 +2,7 @@
Hard
-Given a string containing just the characters `'('` and `')'`, find the length of the longest valid (well-formed) parentheses substring.
+Given a string containing just the characters `'('` and `')'`, return _the length of the longest valid (well-formed) parentheses_ **substring**.
**Example 1:**
@@ -29,4 +29,51 @@ Given a string containing just the characters `'('` and `')'`, find the length o
**Constraints:**
* 0 <= s.length <= 3 * 104
-* `s[i]` is `'('`, or `')'`.
\ No newline at end of file
+* `s[i]` is `'('`, or `')'`.
+
+To solve the "Longest Valid Parentheses" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `longestValidParentheses` that takes a string `s` as input and returns an integer representing the length of the longest valid parentheses substring.
+3. Initialize a stack to store the indices of characters.
+4. Initialize a variable `maxLen` to store the maximum length of valid parentheses found so far.
+5. Push `-1` onto the stack to mark the starting point of a potential valid substring.
+6. Iterate through each character of the string:
+ - If the character is `'('`, push its index onto the stack.
+ - If the character is `')'`:
+ - Pop the top index from the stack.
+ - If the stack is empty after popping, push the current index onto the stack to mark the starting point of the next potential valid substring.
+ - Otherwise, update `maxLen` with the maximum of the current `maxLen` and `i - stack.peek()`, where `i` is the current index and `stack.peek()` is the index at the top of the stack.
+7. Return `maxLen`.
+
+Here's the implementation:
+
+```java
+import java.util.Stack;
+
+public class Solution {
+ public int longestValidParentheses(String s) {
+ int maxLen = 0;
+ Stack stack = new Stack<>();
+ stack.push(-1); // Mark the starting point of a potential valid substring
+
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c == '(') {
+ stack.push(i);
+ } else { // c == ')'
+ stack.pop();
+ if (stack.isEmpty()) {
+ stack.push(i); // Mark the starting point of the next potential valid substring
+ } else {
+ maxLen = Math.max(maxLen, i - stack.peek());
+ }
+ }
+ }
+
+ return maxLen;
+ }
+}
+```
+
+This implementation provides a solution to the "Longest Valid Parentheses" problem in Java. It finds the length of the longest valid parentheses substring in the given string `s`.
diff --git a/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java b/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java
index 732b96a5e..97708900a 100644
--- a/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java
+++ b/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.java
@@ -2,8 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search
// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_11 #Level_2_Day_8_Binary_Search
-// #Udemy_Binary_Search #Big_O_Time_O(log_n)_Space_O(1)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_40.6_MB_(92.43%)
+// #Udemy_Binary_Search #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_42.2_MB_(21.10%)
public class Solution {
public int search(int[] nums, int target) {
diff --git a/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md b/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md
index ebfff914f..5ed3224c9 100644
--- a/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md
+++ b/src/main/java/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md
@@ -4,7 +4,7 @@ Medium
There is an integer array `nums` sorted in ascending order (with **distinct** values).
-Prior to being passed to your function, `nums` is **possibly rotated** at an unknown pivot index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be rotated at pivot index `3` and become `[4,5,6,7,0,1,2]`.
+Prior to being passed to your function, `nums` is **possibly left rotated** at an unknown index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be left rotated by `3` indices and become `[4,5,6,7,0,1,2]`.
Given the array `nums` **after** the possible rotation and an integer `target`, return _the index of_ `target` _if it is in_ `nums`_, or_ `-1` _if it is not in_ `nums`.
@@ -34,4 +34,58 @@ You must write an algorithm with `O(log n)` runtime complexity.
* -104 <= nums[i] <= 104
* All values of `nums` are **unique**.
* `nums` is an ascending array that is possibly rotated.
-* -104 <= target <= 104
\ No newline at end of file
+* -104 <= target <= 104
+
+To solve the "Search in Rotated Sorted Array" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `search` that takes an integer array `nums` and an integer `target` as input and returns an integer representing the index of `target` in `nums`. If `target` is not found, return `-1`.
+3. Implement the binary search algorithm to find the index of `target` in the rotated sorted array.
+4. Set the left pointer `left` to 0 and the right pointer `right` to the length of `nums` minus 1.
+5. While `left` is less than or equal to `right`:
+ - Calculate the middle index `mid` as `(left + right) / 2`.
+ - If `nums[mid]` is equal to `target`, return `mid`.
+ - Check if the left half of the array (`nums[left]` to `nums[mid]`) is sorted:
+ - If `nums[left] <= nums[mid]` and `nums[left] <= target < nums[mid]`, update `right = mid - 1`.
+ - Otherwise, update `left = mid + 1`.
+ - Otherwise, check if the right half of the array (`nums[mid]` to `nums[right]`) is sorted:
+ - If `nums[mid] <= nums[right]` and `nums[mid] < target <= nums[right]`, update `left = mid + 1`.
+ - Otherwise, update `right = mid - 1`.
+6. If `target` is not found, return `-1`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int search(int[] nums, int target) {
+ int left = 0;
+ int right = nums.length - 1;
+
+ while (left <= right) {
+ int mid = left + (right - left) / 2;
+
+ if (nums[mid] == target) {
+ return mid;
+ }
+
+ if (nums[left] <= nums[mid]) {
+ if (nums[left] <= target && target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ } else {
+ if (nums[mid] < target && target <= nums[right]) {
+ left = mid + 1;
+ } else {
+ right = mid - 1;
+ }
+ }
+ }
+
+ return -1;
+ }
+}
+```
+
+This implementation provides a solution to the "Search in Rotated Sorted Array" problem in Java. It searches for the index of `target` in the rotated sorted array `nums`. The algorithm has a time complexity of O(log n).
diff --git a/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java b/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java
index 6501932f1..cdb4b7035 100644
--- a/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java
+++ b/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0034_find_first_and_last_position_of_element_in_sorted_array;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search
-// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Big_O_Time_O(log_n)_Space_O(1)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_44.3_MB_(89.57%)
+// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Top_Interview_150_Binary_Search
+// #Big_O_Time_O(log_n)_Space_O(1) #2024_11_10_Time_0_ms_(100.00%)_Space_45.7_MB_(82.78%)
public class Solution {
public int[] searchRange(int[] nums, int target) {
diff --git a/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md b/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md
index 7c04eb2ed..0e1036e1f 100644
--- a/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md
+++ b/src/main/java/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md
@@ -31,4 +31,72 @@ You must write an algorithm with `O(log n)` runtime complexity.
* 0 <= nums.length <= 105
* -109 <= nums[i] <= 109
* `nums` is a non-decreasing array.
-* -109 <= target <= 109
\ No newline at end of file
+* -109 <= target <= 109
+
+To solve the "Find First and Last Position of Element in Sorted Array" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `searchRange` that takes an integer array `nums` and an integer `target` as input and returns an integer array representing the starting and ending positions of `target` in `nums`. If `target` is not found, return `[-1, -1]`.
+3. Implement binary search to find the first and last occurrences of `target`.
+4. Set the left pointer `left` to 0 and the right pointer `right` to the length of `nums` minus 1.
+5. Initialize two variables `firstOccurrence` and `lastOccurrence` to -1.
+6. Perform two binary search operations:
+ - First, find the first occurrence of `target`:
+ - While `left` is less than or equal to `right`:
+ - Calculate the middle index `mid` as `(left + right) / 2`.
+ - If `nums[mid]` is equal to `target`, update `firstOccurrence = mid` and continue searching on the left half by updating `right = mid - 1`.
+ - Otherwise, if `target` is less than `nums[mid]`, update `right = mid - 1`.
+ - Otherwise, update `left = mid + 1`.
+ - Second, find the last occurrence of `target`:
+ - Reset `left` to 0 and `right` to the length of `nums` minus 1.
+ - While `left` is less than or equal to `right`:
+ - Calculate the middle index `mid` as `(left + right) / 2`.
+ - If `nums[mid]` is equal to `target`, update `lastOccurrence = mid` and continue searching on the right half by updating `left = mid + 1`.
+ - Otherwise, if `target` is greater than `nums[mid]`, update `left = mid + 1`.
+ - Otherwise, update `right = mid - 1`.
+7. Return the array `[firstOccurrence, lastOccurrence]`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int[] searchRange(int[] nums, int target) {
+ int left = 0;
+ int right = nums.length - 1;
+ int firstOccurrence = -1;
+ int lastOccurrence = -1;
+
+ // Find first occurrence
+ while (left <= right) {
+ int mid = left + (right - left) / 2;
+ if (nums[mid] == target) {
+ firstOccurrence = mid;
+ right = mid - 1;
+ } else if (target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ }
+
+ // Find last occurrence
+ left = 0;
+ right = nums.length - 1;
+ while (left <= right) {
+ int mid = left + (right - left) / 2;
+ if (nums[mid] == target) {
+ lastOccurrence = mid;
+ left = mid + 1;
+ } else if (target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ }
+
+ return new int[]{firstOccurrence, lastOccurrence};
+ }
+}
+```
+
+This implementation provides a solution to the "Find First and Last Position of Element in Sorted Array" problem in Java. It returns the starting and ending positions of `target` in `nums` using binary search, with a time complexity of O(log n).
diff --git a/src/main/java/g0001_0100/s0035_search_insert_position/Solution.java b/src/main/java/g0001_0100/s0035_search_insert_position/Solution.java
index 29430a943..b459e4b03 100644
--- a/src/main/java/g0001_0100/s0035_search_insert_position/Solution.java
+++ b/src/main/java/g0001_0100/s0035_search_insert_position/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0035_search_insert_position;
// #Easy #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_I_Day_1_Binary_Search
-// #Binary_Search_I_Day_2 #Big_O_Time_O(log_n)_Space_O(1)
-// #2023_08_09_Time_0_ms_(100.00%)_Space_43.3_MB_(58.21%)
+// #Binary_Search_I_Day_2 #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_43_MB_(40.42%)
public class Solution {
public int searchInsert(int[] nums, int target) {
diff --git a/src/main/java/g0001_0100/s0035_search_insert_position/readme.md b/src/main/java/g0001_0100/s0035_search_insert_position/readme.md
index 94ead0ddd..b178a53bc 100644
--- a/src/main/java/g0001_0100/s0035_search_insert_position/readme.md
+++ b/src/main/java/g0001_0100/s0035_search_insert_position/readme.md
@@ -24,21 +24,48 @@ You must write an algorithm with `O(log n)` runtime complexity.
**Output:** 4
-**Example 4:**
-
-**Input:** nums = [1,3,5,6], target = 0
-
-**Output:** 0
-
-**Example 5:**
-
-**Input:** nums = [1], target = 0
-
-**Output:** 0
-
**Constraints:**
* 1 <= nums.length <= 104
* -104 <= nums[i] <= 104
* `nums` contains **distinct** values sorted in **ascending** order.
-* -104 <= target <= 104
\ No newline at end of file
+* -104 <= target <= 104
+
+To solve the "Search Insert Position" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `searchInsert` that takes an integer array `nums` and an integer `target` as input and returns an integer representing the index where `target` would be inserted in order.
+3. Implement binary search to find the insertion position of `target`.
+4. Set the left pointer `left` to 0 and the right pointer `right` to the length of `nums` minus 1.
+5. While `left` is less than or equal to `right`:
+ - Calculate the middle index `mid` as `(left + right) / 2`.
+ - If `nums[mid]` is equal to `target`, return `mid`.
+ - If `target` is less than `nums[mid]`, update `right = mid - 1`.
+ - If `target` is greater than `nums[mid]`, update `left = mid + 1`.
+6. If `target` is not found in `nums`, return the value of `left`, which represents the index where `target` would be inserted in order.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int searchInsert(int[] nums, int target) {
+ int left = 0;
+ int right = nums.length - 1;
+
+ while (left <= right) {
+ int mid = left + (right - left) / 2;
+ if (nums[mid] == target) {
+ return mid;
+ } else if (target < nums[mid]) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ }
+
+ return left;
+ }
+}
+```
+
+This implementation provides a solution to the "Search Insert Position" problem in Java. It returns the index where `target` would be inserted in `nums` using binary search, with a time complexity of O(log n).
diff --git a/src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java b/src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java
index 92248a472..0de210a89 100644
--- a/src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java
+++ b/src/main/java/g0001_0100/s0036_valid_sudoku/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0036_valid_sudoku;
// #Medium #Top_Interview_Questions #Array #Hash_Table #Matrix #Data_Structure_I_Day_5_Array
-// #2023_08_09_Time_1_ms_(100.00%)_Space_43.8_MB_(30.47%)
+// #Top_Interview_150_Matrix #2025_03_04_Time_1_ms_(100.00%)_Space_44.50_MB_(57.83%)
public class Solution {
private int j1;
diff --git a/src/main/java/g0001_0100/s0039_combination_sum/Solution.java b/src/main/java/g0001_0100/s0039_combination_sum/Solution.java
index 46297edf6..5d6d21a55 100644
--- a/src/main/java/g0001_0100/s0039_combination_sum/Solution.java
+++ b/src/main/java/g0001_0100/s0039_combination_sum/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking
// #Level_2_Day_20_Brute_Force/Backtracking #Udemy_Backtracking/Recursion
-// #Big_O_Time_O(2^n)_Space_O(n+2^n) #2023_08_09_Time_1_ms_(100.00%)_Space_43.6_MB_(90.84%)
+// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n+2^n)
+// #2024_11_10_Time_1_ms_(99.99%)_Space_44.5_MB_(51.73%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0001_0100/s0039_combination_sum/readme.md b/src/main/java/g0001_0100/s0039_combination_sum/readme.md
index 1f2c6369a..2130d52f7 100644
--- a/src/main/java/g0001_0100/s0039_combination_sum/readme.md
+++ b/src/main/java/g0001_0100/s0039_combination_sum/readme.md
@@ -6,7 +6,7 @@ Given an array of **distinct** integers `candidates` and a target integer `targe
The **same** number may be chosen from `candidates` an **unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different.
-It is **guaranteed** that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input.
+The test cases are generated such that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input.
**Example 1:**
@@ -14,11 +14,7 @@ It is **guaranteed** that the number of unique combinations that sum up to `targ
**Output:** [[2,2,3],[7]]
-**Explanation:**
-
- 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.
- 7 is a candidate, and 7 = 7.
- These are the only two combinations.
+**Explanation:** 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times. 7 is a candidate, and 7 = 7. These are the only two combinations.
**Example 2:**
@@ -32,21 +28,60 @@ It is **guaranteed** that the number of unique combinations that sum up to `targ
**Output:** []
-**Example 4:**
-
-**Input:** candidates = [1], target = 1
-
-**Output:** [[1]]
-
-**Example 5:**
-
-**Input:** candidates = [1], target = 2
-
-**Output:** [[1,1]]
-
**Constraints:**
* `1 <= candidates.length <= 30`
-* `1 <= candidates[i] <= 200`
+* `2 <= candidates[i] <= 40`
* All elements of `candidates` are **distinct**.
-* `1 <= target <= 500`
\ No newline at end of file
+* `1 <= target <= 40`
+
+To solve the "Combination Sum" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `combinationSum` that takes an array of integers `candidates` and an integer `target` as input and returns a list of lists containing all unique combinations of `candidates` where the chosen numbers sum to `target`.
+3. Implement backtracking to explore all possible combinations of candidates.
+4. Sort the `candidates` array to ensure that duplicates are grouped together.
+5. Create a recursive helper method named `backtrack` that takes parameters:
+ - A list to store the current combination.
+ - An integer representing the starting index in the `candidates` array.
+ - The current sum of the combination.
+6. In the `backtrack` method:
+ - If the current sum equals the target, add the current combination to the result list.
+ - Iterate over the candidates starting from the current index.
+ - Add the current candidate to the combination.
+ - Recursively call the `backtrack` method with the updated combination, index, and sum.
+ - Remove the last added candidate from the combination to backtrack.
+7. Call the `backtrack` method with an empty combination list, starting index 0, and sum 0.
+8. Return the result list containing all unique combinations.
+
+Here's the implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Solution {
+ public List> combinationSum(int[] candidates, int target) {
+ List> result = new ArrayList<>();
+ Arrays.sort(candidates); // Sort the candidates to ensure duplicates are grouped together
+ backtrack(result, new ArrayList<>(), candidates, target, 0);
+ return result;
+ }
+
+ private void backtrack(List> result, List combination, int[] candidates, int target, int start) {
+ if (target == 0) {
+ result.add(new ArrayList<>(combination));
+ return;
+ }
+
+ for (int i = start; i < candidates.length && candidates[i] <= target; i++) {
+ combination.add(candidates[i]);
+ backtrack(result, combination, candidates, target - candidates[i], i); // Use the same candidate again
+ combination.remove(combination.size() - 1); // Backtrack by removing the last candidate
+ }
+ }
+}
+```
+
+This implementation provides a solution to the "Combination Sum" problem in Java. It explores all possible combinations of candidates using backtracking and returns the unique combinations whose sum equals the target.
diff --git a/src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java b/src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java
index 3b4c042fd..f8c832fca 100644
--- a/src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java
+++ b/src/main/java/g0001_0100/s0041_first_missing_positive/Solution.java
@@ -1,15 +1,16 @@
package g0001_0100.s0041_first_missing_positive;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays
-// #Big_O_Time_O(n)_Space_O(n) #2023_08_11_Time_2_ms_(57.59%)_Space_59.2_MB_(51.48%)
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_10_Time_1_ms_(100.00%)_Space_57.5_MB_(31.18%)
public class Solution {
public int firstMissingPositive(int[] nums) {
for (int i = 0; i < nums.length; i++) {
- if (nums[i] <= 0 || nums[i] > nums.length || nums[i] == i + 1) {
- continue;
+ while (nums[i] <= nums.length && nums[i] > 0 && nums[nums[i] - 1] != nums[i]) {
+ int temp = nums[nums[i] - 1];
+ nums[nums[i] - 1] = nums[i];
+ nums[i] = temp;
}
- dfs(nums, nums[i]);
}
for (int i = 0; i < nums.length; i++) {
if (nums[i] != i + 1) {
@@ -18,13 +19,4 @@ public int firstMissingPositive(int[] nums) {
}
return nums.length + 1;
}
-
- private void dfs(int[] nums, int val) {
- if (val <= 0 || val > nums.length || val == nums[val - 1]) {
- return;
- }
- int temp = nums[val - 1];
- nums[val - 1] = val;
- dfs(nums, temp);
- }
}
diff --git a/src/main/java/g0001_0100/s0041_first_missing_positive/readme.md b/src/main/java/g0001_0100/s0041_first_missing_positive/readme.md
index 4cd0b1dcc..32df8d6ae 100644
--- a/src/main/java/g0001_0100/s0041_first_missing_positive/readme.md
+++ b/src/main/java/g0001_0100/s0041_first_missing_positive/readme.md
@@ -2,29 +2,78 @@
Hard
-Given an unsorted integer array `nums`, return the smallest missing positive integer.
+Given an unsorted integer array `nums`. Return the _smallest positive integer_ that is _not present_ in `nums`.
-You must implement an algorithm that runs in `O(n)` time and uses constant extra space.
+You must implement an algorithm that runs in `O(n)` time and uses `O(1)` auxiliary space.
**Example 1:**
**Input:** nums = [1,2,0]
-**Output:** 3
+**Output:** 3
+
+**Explanation:** The numbers in the range [1,2] are all in the array.
**Example 2:**
**Input:** nums = [3,4,-1,1]
-**Output:** 2
+**Output:** 2
+
+**Explanation:** 1 is in the array but 2 is missing.
**Example 3:**
**Input:** nums = [7,8,9,11,12]
-**Output:** 1
+**Output:** 1
+
+**Explanation:** The smallest positive integer 1 is missing.
**Constraints:**
-* 1 <= nums.length <= 5 * 105
-* -231 <= nums[i] <= 231 - 1
\ No newline at end of file
+* 1 <= nums.length <= 105
+* -231 <= nums[i] <= 231 - 1
+
+To solve the "First Missing Positive" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `firstMissingPositive` that takes an array of integers `nums` as input and returns the smallest missing positive integer.
+3. Iterate through the array and mark the positive integers found by negating the value at the corresponding index.
+4. Iterate through the modified array again and return the index of the first positive number (which is the smallest missing positive integer).
+5. If no positive number is found, return `nums.length + 1`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int firstMissingPositive(int[] nums) {
+ int n = nums.length;
+
+ // Mark positive integers found by negating the value at the corresponding index
+ for (int i = 0; i < n; i++) {
+ if (nums[i] > 0 && nums[i] <= n) {
+ int pos = nums[i] - 1;
+ if (nums[pos] != nums[i]) {
+ int temp = nums[pos];
+ nums[pos] = nums[i];
+ nums[i] = temp;
+ i--; // Revisit the swapped number
+ }
+ }
+ }
+
+ // Find the first positive number (smallest missing positive integer)
+ for (int i = 0; i < n; i++) {
+ if (nums[i] != i + 1) {
+ return i + 1;
+ }
+ }
+
+ // If no positive number is found, return nums.length + 1
+ return n + 1;
+ }
+}
+```
+
+This implementation provides a solution to the "First Missing Positive" problem in Java. It marks positive integers found by negating the value at the corresponding index and then iterates through the modified array to find the smallest missing positive integer. If no positive number is found, it returns `nums.length + 1`.
diff --git a/src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java b/src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java
index f853ebcd7..104c930c2 100644
--- a/src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java
+++ b/src/main/java/g0001_0100/s0042_trapping_rain_water/Solution.java
@@ -2,7 +2,8 @@
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Two_Pointers
// #Stack #Monotonic_Stack #Dynamic_Programming_I_Day_9 #Udemy_Two_Pointers
-// #Big_O_Time_O(n)_Space_O(1) #2023_08_11_Time_0_ms_(100.00%)_Space_44.3_MB_(62.40%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_46.2_MB_(57.86%)
public class Solution {
public int trap(int[] height) {
diff --git a/src/main/java/g0001_0100/s0042_trapping_rain_water/readme.md b/src/main/java/g0001_0100/s0042_trapping_rain_water/readme.md
index b57de86dd..d400d21b9 100644
--- a/src/main/java/g0001_0100/s0042_trapping_rain_water/readme.md
+++ b/src/main/java/g0001_0100/s0042_trapping_rain_water/readme.md
@@ -24,4 +24,46 @@ Given `n` non-negative integers representing an elevation map where the width of
* `n == height.length`
* 1 <= n <= 2 * 104
-* 0 <= height[i] <= 105
\ No newline at end of file
+* 0 <= height[i] <= 105
+
+To solve the "Trapping Rain Water" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `trap` that takes an array of integers `height` as input and returns the amount of water it can trap after raining.
+3. Initialize two pointers `left` and `right` at the beginning and end of the array respectively.
+4. Initialize two variables `leftMax` and `rightMax` to keep track of the maximum height of bars encountered from the left and right directions respectively.
+5. Iterate through the array using the two pointers:
+ - Update `leftMax` as the maximum of `leftMax` and `height[left]`.
+ - Update `rightMax` as the maximum of `rightMax` and `height[right]`.
+ - If `height[left] < height[right]`, calculate the water trapped at the current position using `leftMax` and subtract the height of the current bar. Move `left` pointer to the right.
+ - Otherwise, calculate the water trapped at the current position using `rightMax` and subtract the height of the current bar. Move `right` pointer to the left.
+6. Continue this process until the two pointers meet.
+7. Return the total amount of water trapped.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int trap(int[] height) {
+ int left = 0, right = height.length - 1;
+ int leftMax = 0, rightMax = 0;
+ int trappedWater = 0;
+
+ while (left < right) {
+ if (height[left] < height[right]) {
+ leftMax = Math.max(leftMax, height[left]);
+ trappedWater += leftMax - height[left];
+ left++;
+ } else {
+ rightMax = Math.max(rightMax, height[right]);
+ trappedWater += rightMax - height[right];
+ right--;
+ }
+ }
+
+ return trappedWater;
+ }
+}
+```
+
+This implementation provides a solution to the "Trapping Rain Water" problem in Java. It calculates the amount of water that can be trapped between bars by using two pointers to track the left and right boundaries and two variables to track the maximum heights of bars encountered from the left and right directions.
diff --git a/src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java b/src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java
index 81e31a7d8..a074b4421 100644
--- a/src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0045_jump_game_ii/Solution.java
@@ -2,25 +2,30 @@
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Greedy
// #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4
-// #Big_O_Time_O(n)_Space_O(1) #2023_08_11_Time_2_ms_(49.02%)_Space_44.7_MB_(52.72%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_45_MB_(64.44%)
public class Solution {
+ private int getMax(int[] nums, int l, int r) {
+ int max = -1;
+ int curr;
+ for (int i = l; i <= r; i++) {
+ curr = i + nums[i];
+ max = Math.max(max, curr);
+ }
+ return max;
+ }
+
public int jump(int[] nums) {
- int length = 0;
- int maxLength = 0;
- int minJump = 0;
- for (int i = 0; i < nums.length - 1; ++i) {
- length--;
- maxLength--;
- maxLength = Math.max(maxLength, nums[i]);
- if (length <= 0) {
- length = maxLength;
- minJump++;
- }
- if (length >= nums.length - i - 1) {
- return minJump;
- }
+ int l = 0;
+ int r = 0;
+ int jumps = 0;
+ while (r < nums.length - 1) {
+ int prev = r;
+ r = getMax(nums, l, r);
+ l = prev + 1;
+ jumps++;
}
- return minJump;
+ return jumps;
}
}
diff --git a/src/main/java/g0001_0100/s0045_jump_game_ii/readme.md b/src/main/java/g0001_0100/s0045_jump_game_ii/readme.md
index 10a43da26..1622fd539 100644
--- a/src/main/java/g0001_0100/s0045_jump_game_ii/readme.md
+++ b/src/main/java/g0001_0100/s0045_jump_game_ii/readme.md
@@ -2,13 +2,14 @@
Medium
-Given an array of non-negative integers `nums`, you are initially positioned at the first index of the array.
+You are given a **0-indexed** array of integers `nums` of length `n`. You are initially positioned at index 0.
-Each element in the array represents your maximum jump length at that position.
+Each element `nums[i]` represents the maximum length of a forward jump from index `i`. In other words, if you are at index `i`, you can jump to any index `(i + j)` where:
-Your goal is to reach the last index in the minimum number of jumps.
+* `0 <= j <= nums[i]` and
+* `i + j < n`
-You can assume that you can always reach the last index.
+Return _the minimum number of jumps to reach index_ `n - 1`. The test cases are generated such that you can reach index `n - 1`.
**Example 1:**
@@ -27,4 +28,39 @@ You can assume that you can always reach the last index.
**Constraints:**
* 1 <= nums.length <= 104
-* `0 <= nums[i] <= 1000`
\ No newline at end of file
+* `0 <= nums[i] <= 1000`
+* It's guaranteed that you can reach `nums[n - 1]`.
+
+To solve the "Jump Game II" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `jump` that takes an array of non-negative integers `nums` as input and returns the minimum number of jumps required to reach the last index.
+3. Initialize variables `maxReach`, `steps`, and `end` to keep track of the maximum reachable position, the number of steps taken, and the end position respectively. Initialize `maxReach` to 0 and `end` to 0.
+4. Iterate through the array from index 0 to `nums.length - 2`:
+ - Update `maxReach` as the maximum of `maxReach` and `i + nums[i]`.
+ - If the current index `i` equals `end`, update `end` to `maxReach` and increment `steps`.
+5. Return `steps`.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public int jump(int[] nums) {
+ int maxReach = 0;
+ int steps = 0;
+ int end = 0;
+
+ for (int i = 0; i < nums.length - 1; i++) {
+ maxReach = Math.max(maxReach, i + nums[i]);
+ if (i == end) {
+ end = maxReach;
+ steps++;
+ }
+ }
+
+ return steps;
+ }
+}
+```
+
+This implementation provides a solution to the "Jump Game II" problem in Java. It calculates the minimum number of jumps required to reach the last index by iterating through the array and updating the maximum reachable position and the end position accordingly.
diff --git a/src/main/java/g0001_0100/s0046_permutations/Solution.java b/src/main/java/g0001_0100/s0046_permutations/Solution.java
index 18943b511..a62bc1fa0 100644
--- a/src/main/java/g0001_0100/s0046_permutations/Solution.java
+++ b/src/main/java/g0001_0100/s0046_permutations/Solution.java
@@ -2,8 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Backtracking
// #Algorithm_I_Day_11_Recursion_Backtracking #Level_2_Day_20_Brute_Force/Backtracking
-// #Udemy_Backtracking/Recursion #Big_O_Time_O(n*n!)_Space_O(n+n!)
-// #2023_08_11_Time_1_ms_(95.07%)_Space_43.7_MB_(87.98%)
+// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(n*n!)_Space_O(n+n!)
+// #2024_11_10_Time_1_ms_(94.08%)_Space_45.1_MB_(6.84%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0001_0100/s0046_permutations/readme.md b/src/main/java/g0001_0100/s0046_permutations/readme.md
index 4d95634ff..31b15e6dd 100644
--- a/src/main/java/g0001_0100/s0046_permutations/readme.md
+++ b/src/main/java/g0001_0100/s0046_permutations/readme.md
@@ -2,7 +2,7 @@
Medium
-Given an array `nums` of distinct integers, return _all the possible permutations_. You can return the answer in **any order**.
+Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in **any order**.
**Example 1:**
@@ -26,4 +26,49 @@ Given an array `nums` of distinct integers, return _all the possible permutation
* `1 <= nums.length <= 6`
* `-10 <= nums[i] <= 10`
-* All the integers of `nums` are **unique**.
\ No newline at end of file
+* All the integers of `nums` are **unique**.
+
+To solve the "Permutations" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `permute` that takes an array of distinct integers `nums` as input and returns a list of all possible permutations.
+3. Create an empty list to store the result permutations.
+4. Call a recursive helper function named `permuteHelper` to generate permutations.
+5. Inside the `permuteHelper` function:
+ - If the current permutation size equals the length of the input array `nums`, add a copy of the current permutation to the result list.
+ - Otherwise, iterate through each element of `nums`:
+ - If the current element is not already in the permutation, add it to the current permutation, and recursively call `permuteHelper` with the updated permutation and the remaining elements of `nums`.
+ - After the recursive call, remove the last element from the permutation to backtrack.
+6. Return the result list.
+
+Here's the implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.List;
+
+public class Solution {
+ public List> permute(int[] nums) {
+ List> result = new ArrayList<>();
+ permuteHelper(nums, new ArrayList<>(), result);
+ return result;
+ }
+
+ private void permuteHelper(int[] nums, List current, List> result) {
+ if (current.size() == nums.length) {
+ result.add(new ArrayList<>(current));
+ return;
+ }
+
+ for (int num : nums) {
+ if (!current.contains(num)) {
+ current.add(num);
+ permuteHelper(nums, current, result);
+ current.remove(current.size() - 1);
+ }
+ }
+ }
+}
+```
+
+This implementation provides a solution to the "Permutations" problem in Java. It generates all possible permutations of the given array of distinct integers using backtracking.
diff --git a/src/main/java/g0001_0100/s0048_rotate_image/Solution.java b/src/main/java/g0001_0100/s0048_rotate_image/Solution.java
index 79c98b0f2..de0c8b8d3 100644
--- a/src/main/java/g0001_0100/s0048_rotate_image/Solution.java
+++ b/src/main/java/g0001_0100/s0048_rotate_image/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Matrix
// #Data_Structure_II_Day_3_Array #Programming_Skills_II_Day_7 #Udemy_2D_Arrays/Matrix
-// #Big_O_Time_O(n^2)_Space_O(1) #2023_08_11_Time_0_ms_(100.00%)_Space_41.5_MB_(34.96%)
+// #Top_Interview_150_Matrix #Big_O_Time_O(n^2)_Space_O(1)
+// #2024_11_10_Time_0_ms_(100.00%)_Space_42.2_MB_(43.71%)
public class Solution {
public void rotate(int[][] matrix) {
diff --git a/src/main/java/g0001_0100/s0048_rotate_image/readme.md b/src/main/java/g0001_0100/s0048_rotate_image/readme.md
index 7441873b9..5077707b7 100644
--- a/src/main/java/g0001_0100/s0048_rotate_image/readme.md
+++ b/src/main/java/g0001_0100/s0048_rotate_image/readme.md
@@ -22,21 +22,54 @@ You have to rotate the image [**in-place**](https://en.wikipedia.org/wiki/In-pla
**Output:** [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
-**Example 3:**
-
-**Input:** matrix = [[1]]
-
-**Output:** [[1]]
-
-**Example 4:**
-
-**Input:** matrix = [[1,2],[3,4]]
-
-**Output:** [[3,1],[4,2]]
-
**Constraints:**
-* `matrix.length == n`
-* `matrix[i].length == n`
+* `n == matrix.length == matrix[i].length`
* `1 <= n <= 20`
-* `-1000 <= matrix[i][j] <= 1000`
\ No newline at end of file
+* `-1000 <= matrix[i][j] <= 1000`
+
+To solve the "Rotate Image" problem in Java with a `Solution` class, we can follow these steps:
+
+1. Define a `Solution` class.
+2. Define a method named `rotate` that takes a 2D array `matrix` representing an image as input and rotates the image by 90 degrees clockwise.
+3. Determine the number of layers in the matrix, which is equal to half of the matrix's size.
+4. Iterate through each layer from outer to inner layers.
+5. For each layer:
+ - Iterate through each element in the current layer.
+ - Swap the elements of the current layer in a clockwise manner.
+6. Return the rotated matrix.
+
+Here's the implementation:
+
+```java
+public class Solution {
+ public void rotate(int[][] matrix) {
+ int n = matrix.length;
+ int layers = n / 2;
+
+ for (int layer = 0; layer < layers; layer++) {
+ int first = layer;
+ int last = n - 1 - layer;
+
+ for (int i = first; i < last; i++) {
+ int offset = i - first;
+ int top = matrix[first][i];
+
+ // Move left to top
+ matrix[first][i] = matrix[last - offset][first];
+
+ // Move bottom to left
+ matrix[last - offset][first] = matrix[last][last - offset];
+
+ // Move right to bottom
+ matrix[last][last - offset] = matrix[i][last];
+
+ // Move top to right
+ matrix[i][last] = top;
+ }
+ }
+ }
+}
+```
+
+This implementation provides a solution to the "Rotate Image" problem in Java. It rotates the given 2D matrix representing an image by 90 degrees clockwise in-place.
diff --git a/src/main/java/g0001_0100/s0049_group_anagrams/Solution.java b/src/main/java/g0001_0100/s0049_group_anagrams/Solution.java
index ca80a13e8..463f78881 100644
--- a/src/main/java/g0001_0100/s0049_group_anagrams/Solution.java
+++ b/src/main/java/g0001_0100/s0049_group_anagrams/Solution.java
@@ -2,24 +2,29 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #String #Hash_Table #Sorting
// #Data_Structure_II_Day_8_String #Programming_Skills_II_Day_11 #Udemy_Strings
-// #Big_O_Time_O(n*k_log_k)_Space_O(n) #2023_08_11_Time_6_ms_(92.28%)_Space_46.4_MB_(98.50%)
+// #Top_Interview_150_Hashmap #Big_O_Time_O(n*k_log_k)_Space_O(n)
+// #2024_11_11_Time_6_ms_(97.61%)_Space_47.7_MB_(69.56%)
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+@SuppressWarnings("java:S3824")
public class Solution {
public List> groupAnagrams(String[] strs) {
- Map> hm = new HashMap<>();
- for (String s : strs) {
- char[] ch = s.toCharArray();
- Arrays.sort(ch);
- String temp = new String(ch);
- hm.computeIfAbsent(temp, k -> new ArrayList<>());
- hm.get(temp).add(s);
+ Map> anagrams = new HashMap<>();
+ for (String word : strs) {
+ char[] freq = new char[26];
+ for (char c : word.toCharArray()) {
+ freq[c - 'a']++;
+ }
+ String keyString = new String(freq);
+ if (!anagrams.containsKey(keyString)) {
+ anagrams.put(keyString, new ArrayList<>());
+ }
+ anagrams.get(keyString).add(word);
}
- return (new ArrayList<>(hm.values()));
+ return new ArrayList<>(anagrams.values());
}
}
diff --git a/src/main/java/g0001_0100/s0049_group_anagrams/readme.md b/src/main/java/g0001_0100/s0049_group_anagrams/readme.md
index c1641cec1..3d2d7723f 100644
--- a/src/main/java/g0001_0100/s0049_group_anagrams/readme.md
+++ b/src/main/java/g0001_0100/s0049_group_anagrams/readme.md
@@ -2,30 +2,82 @@
Medium
-Given an array of strings `strs`, group **the anagrams** together. You can 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 an array of strings `strs`, group the anagrams together. You can return the answer in **any order**.
**Example 1:**
**Input:** strs = ["eat","tea","tan","ate","nat","bat"]
-**Output:** [["bat"],["nat","tan"],["ate","eat","tea"]]
+**Output:** [["bat"],["nat","tan"],["ate","eat","tea"]]
+
+**Explanation:**
+
+* There is no string in strs that can be rearranged to form `"bat"`.
+* The strings `"nat"` and `"tan"` are anagrams as they can be rearranged to form each other.
+* The strings `"ate"`, `"eat"`, and `"tea"` are anagrams as they can be rearranged to form each other.
**Example 2:**
**Input:** strs = [""]
-**Output:** [[""]]
+**Output:** [[""]]
**Example 3:**
**Input:** strs = ["a"]
-**Output:** [["a"]]
+**Output:** [["a"]]
**Constraints:**
* 1 <= strs.length <= 104
* `0 <= strs[i].length <= 100`
-* `strs[i]` consists of lowercase English letters.
\ No newline at end of file
+* `strs[i]` consists of lowercase English letters.
+
+To solve the "Group Anagrams" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `groupAnagrams` in the `Solution` class that takes an array of strings `strs` as input and returns a list of lists of strings.
+2. Initialize an empty HashMap to store the groups of anagrams. The key will be the sorted string, and the value will be a list of strings.
+3. Iterate through each string `str` in the input array `strs`.
+4. Sort the characters of the current string `str` to create a key for the HashMap.
+5. Check if the sorted string exists as a key in the HashMap:
+ - If it does, add the original string `str` to the corresponding list of strings.
+ - If it doesn't, create a new entry in the HashMap with the sorted string as the key and a new list containing `str` as the value.
+6. After iterating through all strings, return the values of the HashMap as the result.
+
+Here's the implementation of the `groupAnagrams` method in Java:
+
+```java
+import java.util.*;
+
+class Solution {
+ public List> groupAnagrams(String[] strs) {
+ // Initialize a HashMap to store the groups of anagrams
+ Map> anagramGroups = new HashMap<>();
+
+ // Iterate through each string in the input array
+ for (String str : strs) {
+ // Sort the characters of the current string
+ char[] chars = str.toCharArray();
+ Arrays.sort(chars);
+ String sortedStr = new String(chars);
+
+ // Check if the sorted string exists as a key in the HashMap
+ if (anagramGroups.containsKey(sortedStr)) {
+ // If it does, add the original string to the corresponding list
+ anagramGroups.get(sortedStr).add(str);
+ } else {
+ // If it doesn't, create a new entry in the HashMap
+ List group = new ArrayList<>();
+ group.add(str);
+ anagramGroups.put(sortedStr, group);
+ }
+ }
+
+ // Return the values of the HashMap as the result
+ return new ArrayList<>(anagramGroups.values());
+ }
+}
+```
+
+This implementation ensures that all anagrams are grouped together efficiently using a HashMap.
diff --git a/src/main/java/g0001_0100/s0050_powx_n/Solution.java b/src/main/java/g0001_0100/s0050_powx_n/Solution.java
index aec45d138..4ecaadde7 100644
--- a/src/main/java/g0001_0100/s0050_powx_n/Solution.java
+++ b/src/main/java/g0001_0100/s0050_powx_n/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0050_powx_n;
-// #Medium #Top_Interview_Questions #Math #Recursion #Udemy_Integers
-// #2023_08_11_Time_0_ms_(100.00%)_Space_41.2_MB_(14.99%)
+// #Medium #Top_Interview_Questions #Math #Recursion #Udemy_Integers #Top_Interview_150_Math
+// #2025_03_04_Time_0_ms_(100.00%)_Space_41.72_MB_(93.18%)
public class Solution {
public double myPow(double x, int n) {
diff --git a/src/main/java/g0001_0100/s0050_powx_n/readme.md b/src/main/java/g0001_0100/s0050_powx_n/readme.md
index 3e93a2f3a..426d83a07 100644
--- a/src/main/java/g0001_0100/s0050_powx_n/readme.md
+++ b/src/main/java/g0001_0100/s0050_powx_n/readme.md
@@ -28,4 +28,6 @@ Implement [pow(x, n)](http://www.cplusplus.com/reference/valarray/pow/), which c
* `-100.0 < x < 100.0`
* -231 <= n <= 231-1
+* `n` is an integer.
+* Either `x` is not zero or `n > 0`.
* -104 <= xn <= 104
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0051_n_queens/Solution.java b/src/main/java/g0001_0100/s0051_n_queens/Solution.java
index b782e2da6..0e518da82 100644
--- a/src/main/java/g0001_0100/s0051_n_queens/Solution.java
+++ b/src/main/java/g0001_0100/s0051_n_queens/Solution.java
@@ -1,50 +1,61 @@
package g0001_0100.s0051_n_queens;
// #Hard #Top_100_Liked_Questions #Array #Backtracking #Big_O_Time_O(N!)_Space_O(N)
-// #2023_08_11_Time_1_ms_(100.00%)_Space_43.6_MB_(97.17%)
+// #2024_11_11_Time_1_ms_(99.77%)_Space_44.8_MB_(61.16%)
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
public class Solution {
public List> solveNQueens(int n) {
- boolean[] pos = new boolean[n + 2 * n - 1 + 2 * n - 1];
- int[] pos2 = new int[n];
- List> ans = new ArrayList<>();
- helper(n, 0, pos, pos2, ans);
- return ans;
+ char[][] board = new char[n][n];
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < n; j++) {
+ board[i][j] = '.';
+ }
+ }
+ List> res = new ArrayList<>();
+ int[] leftRow = new int[n];
+ int[] upperDiagonal = new int[2 * n - 1];
+ int[] lowerDiagonal = new int[2 * n - 1];
+ solve(0, board, res, leftRow, lowerDiagonal, upperDiagonal);
+ return res;
}
- private void helper(int n, int row, boolean[] pos, int[] pos2, List> ans) {
- if (row == n) {
- construct(n, pos2, ans);
+ void solve(
+ int col,
+ char[][] board,
+ List> res,
+ int[] leftRow,
+ int[] lowerDiagonal,
+ int[] upperDiagonal) {
+ if (col == board.length) {
+ res.add(construct(board));
return;
}
- for (int i = 0; i < n; i++) {
- int index = n + 2 * n - 1 + n - 1 + i - row;
- if (pos[i] || pos[n + i + row] || pos[index]) {
- continue;
+ for (int row = 0; row < board.length; row++) {
+ if (leftRow[row] == 0
+ && lowerDiagonal[row + col] == 0
+ && upperDiagonal[board.length - 1 + col - row] == 0) {
+ board[row][col] = 'Q';
+ leftRow[row] = 1;
+ lowerDiagonal[row + col] = 1;
+ upperDiagonal[board.length - 1 + col - row] = 1;
+ solve(col + 1, board, res, leftRow, lowerDiagonal, upperDiagonal);
+ board[row][col] = '.';
+ leftRow[row] = 0;
+ lowerDiagonal[row + col] = 0;
+ upperDiagonal[board.length - 1 + col - row] = 0;
}
- pos[i] = true;
- pos[n + i + row] = true;
- pos[index] = true;
- pos2[row] = i;
- helper(n, row + 1, pos, pos2, ans);
- pos[i] = false;
- pos[n + i + row] = false;
- pos[index] = false;
}
}
- private void construct(int n, int[] pos, List> ans) {
- List sol = new ArrayList<>();
- for (int r = 0; r < n; r++) {
- char[] queenRow = new char[n];
- Arrays.fill(queenRow, '.');
- queenRow[pos[r]] = 'Q';
- sol.add(new String(queenRow));
+ List construct(char[][] board) {
+ List res = new ArrayList<>();
+ for (char[] chars : board) {
+ String s = new String(chars);
+ res.add(s);
}
- ans.add(sol);
+ return res;
}
}
diff --git a/src/main/java/g0001_0100/s0051_n_queens/readme.md b/src/main/java/g0001_0100/s0051_n_queens/readme.md
index 4227951e4..56be2333b 100644
--- a/src/main/java/g0001_0100/s0051_n_queens/readme.md
+++ b/src/main/java/g0001_0100/s0051_n_queens/readme.md
@@ -26,4 +26,83 @@ Each solution contains a distinct board configuration of the n-queens' placement
**Constraints:**
-* `1 <= n <= 9`
\ No newline at end of file
+* `1 <= n <= 9`
+
+To solve the "N-Queens" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `solveNQueens` in the `Solution` class that takes an integer `n` as input and returns a list of lists of strings.
+2. Initialize a board represented as a 2D character array of size `n x n`. Initialize all cells to `'.'`, indicating an empty space.
+3. Define a recursive backtracking function `backtrack` to explore all possible configurations of queens on the board.
+4. In the `backtrack` function:
+ - Base case: If the current row index `row` is equal to `n`, it means we have successfully placed `n` queens on the board. Add the current board configuration to the result.
+ - Iterate through each column index `col` from `0` to `n - 1`:
+ - Check if it's safe to place a queen at position `(row, col)` by calling a helper function `isSafe`.
+ - If it's safe, place a queen at position `(row, col)` on the board, mark it as `'Q'`.
+ - Recur to the next row by calling `backtrack(row + 1)`.
+ - Backtrack: After exploring all possibilities, remove the queen from position `(row, col)` by marking it as `'.'`.
+5. In the `solveNQueens` method, initialize an empty list `result` to store the solutions.
+6. Call the `backtrack` function with initial parameters `0` for the row index.
+7. Return the `result` list containing all distinct solutions.
+
+Here's the implementation of the `solveNQueens` method in Java:
+
+```java
+import java.util.*;
+
+class Solution {
+ public List> solveNQueens(int n) {
+ List> result = new ArrayList<>();
+ char[][] board = new char[n][n];
+ for (int i = 0; i < n; i++) {
+ Arrays.fill(board[i], '.');
+ }
+ backtrack(board, 0, result);
+ return result;
+ }
+
+ private void backtrack(char[][] board, int row, List> result) {
+ int n = board.length;
+ if (row == n) {
+ result.add(constructBoard(board));
+ return;
+ }
+ for (int col = 0; col < n; col++) {
+ if (isSafe(board, row, col)) {
+ board[row][col] = 'Q';
+ backtrack(board, row + 1, result);
+ board[row][col] = '.';
+ }
+ }
+ }
+
+ private boolean isSafe(char[][] board, int row, int col) {
+ int n = board.length;
+ for (int i = 0; i < row; i++) {
+ if (board[i][col] == 'Q') {
+ return false;
+ }
+ }
+ for (int i = row - 1, j = col - 1; i >= 0 && j >= 0; i--, j--) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+ for (int i = row - 1, j = col + 1; i >= 0 && j < n; i--, j++) {
+ if (board[i][j] == 'Q') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private List constructBoard(char[][] board) {
+ List solution = new ArrayList<>();
+ for (char[] row : board) {
+ solution.add(new String(row));
+ }
+ return solution;
+ }
+}
+```
+
+This implementation efficiently finds all distinct solutions to the N-Queens problem using backtracking.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0052_n_queens_ii/Solution.java b/src/main/java/g0001_0100/s0052_n_queens_ii/Solution.java
index d366742ec..1fb8f11ab 100644
--- a/src/main/java/g0001_0100/s0052_n_queens_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0052_n_queens_ii/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0052_n_queens_ii;
-// #Hard #Backtracking #2023_08_11_Time_1_ms_(96.99%)_Space_39.8_MB_(38.70%)
+// #Hard #Backtracking #Top_Interview_150_Backtracking
+// #2025_03_04_Time_0_ms_(100.00%)_Space_41.18_MB_(24.45%)
public class Solution {
public int totalNQueens(int n) {
diff --git a/src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java b/src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java
index a11e531ea..c2367a1e0 100644
--- a/src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java
+++ b/src/main/java/g0001_0100/s0053_maximum_subarray/Solution.java
@@ -1,9 +1,9 @@
package g0001_0100.s0053_maximum_subarray;
-// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
+// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Divide_and_Conquer #Data_Structure_I_Day_1_Array #Dynamic_Programming_I_Day_5
-// #Udemy_Famous_Algorithm #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_11_Time_1_ms_(100.00%)_Space_57.7_MB_(90.58%)
+// #Udemy_Famous_Algorithm #Top_Interview_150_Kadane's_Algorithm #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_11_Time_1_ms_(99.32%)_Space_56.9_MB_(54.82%)
public class Solution {
public int maxSubArray(int[] nums) {
diff --git a/src/main/java/g0001_0100/s0053_maximum_subarray/readme.md b/src/main/java/g0001_0100/s0053_maximum_subarray/readme.md
index 521093b4c..f85358539 100644
--- a/src/main/java/g0001_0100/s0053_maximum_subarray/readme.md
+++ b/src/main/java/g0001_0100/s0053_maximum_subarray/readme.md
@@ -1,10 +1,8 @@
53\. Maximum Subarray
-Easy
+Medium
-Given an integer array `nums`, find the contiguous subarray (containing at least one number) which has the largest sum and return _its sum_.
-
-A **subarray** is a **contiguous** part of an array.
+Given an integer array `nums`, find the **non-empty subarrays** with the largest sum, and return _its sum_.
**Example 1:**
@@ -12,23 +10,57 @@ A **subarray** is a **contiguous** part of an array.
**Output:** 6
-**Explanation:** [4,-1,2,1] has the largest sum = 6.
+**Explanation:** The subarray [4,-1,2,1] has the largest sum 6.
**Example 2:**
**Input:** nums = [1]
-**Output:** 1
+**Output:** 1
+
+**Explanation:** The subarray [1] has the largest sum 1.
**Example 3:**
**Input:** nums = [5,4,-1,7,8]
-**Output:** 23
+**Output:** 23
+
+**Explanation:** The subarray [5,4,-1,7,8] has the largest sum 23.
**Constraints:**
* 1 <= nums.length <= 105
* -104 <= nums[i] <= 104
-**Follow up:** If you have figured out the `O(n)` solution, try coding another solution using the **divide and conquer** approach, which is more subtle.
\ No newline at end of file
+**Follow up:** If you have figured out the `O(n)` solution, try coding another solution using the **divide and conquer** approach, which is more subtle.
+
+To solve the "Maximum Subarray" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `maxSubArray` in the `Solution` class that takes an integer array `nums` as input and returns an integer representing the largest sum of a contiguous subarray.
+2. Initialize two variables `maxSum` and `currentSum` to store the maximum sum found so far and the sum of the current subarray being considered, respectively. Set both to the value of the first element in `nums`.
+3. Iterate through the array `nums` from index `1` to `nums.length - 1`:
+ - Update `currentSum` as the maximum of the current element and the sum of the current element plus `currentSum`.
+ - Update `maxSum` as the maximum of `maxSum` and `currentSum`.
+4. After iterating through all elements in `nums`, return `maxSum`.
+
+Here's the implementation of the `maxSubArray` method in Java:
+
+```java
+class Solution {
+ public int maxSubArray(int[] nums) {
+ if (nums == null || nums.length == 0) {
+ return 0;
+ }
+ int maxSum = nums[0];
+ int currentSum = nums[0];
+ for (int i = 1; i < nums.length; i++) {
+ currentSum = Math.max(nums[i], currentSum + nums[i]);
+ maxSum = Math.max(maxSum, currentSum);
+ }
+ return maxSum;
+ }
+}
+```
+
+This implementation efficiently finds the largest sum of a contiguous subarray in the given array `nums` using the Kadane's algorithm, which has a time complexity of O(n).
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java b/src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java
index 73fc143dc..e3d442103 100644
--- a/src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java
+++ b/src/main/java/g0001_0100/s0054_spiral_matrix/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0054_spiral_matrix;
-// #Medium #Top_Interview_Questions #Array #Matrix #Simulation #Programming_Skills_II_Day_8
-// #Level_2_Day_1_Implementation/Simulation #Udemy_2D_Arrays/Matrix
-// #2023_08_11_Time_0_ms_(100.00%)_Space_41_MB_(9.67%)
+// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Simulation
+// #Programming_Skills_II_Day_8 #Level_2_Day_1_Implementation/Simulation #Udemy_2D_Arrays/Matrix
+// #Top_Interview_150_Matrix #2025_03_04_Time_0_ms_(100.00%)_Space_41.08_MB_(99.19%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0001_0100/s0055_jump_game/Solution.java b/src/main/java/g0001_0100/s0055_jump_game/Solution.java
index c56c0a17a..fedf07899 100644
--- a/src/main/java/g0001_0100/s0055_jump_game/Solution.java
+++ b/src/main/java/g0001_0100/s0055_jump_game/Solution.java
@@ -2,41 +2,23 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Greedy
// #Algorithm_II_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_4 #Udemy_Arrays
-// #Big_O_Time_O(n)_Space_O(1) #2023_08_11_Time_2_ms_(79.47%)_Space_44.8_MB_(22.14%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_11_Time_1_ms_(100.00%)_Space_45.6_MB_(44.48%)
public class Solution {
public boolean canJump(int[] nums) {
- int sz = nums.length;
- // we set 1 so it won't break on the first iteration
- int tmp = 1;
- for (int i = 0; i < sz; i++) {
- // we always deduct tmp for every iteration
- tmp--;
- if (tmp < 0) {
- // if from previous iteration tmp is already 0, it will be <0 here
- // leading to false value
- return false;
- }
- // we get the maximum value because this value is supposed
- // to be our iterator, if both values are 0, then the next
- // iteration we will return false
- // if either both or one of them are not 0 then we will keep doing this and check.
-
- // We can stop the whole iteration with this condition. without this condition the code
- // runs in 2ms 79.6%, adding this condition improves the performance into 1ms 100%
- // because if the test case jump value is quite large, instead of just iterate, we can
- // just check using this condition
- // example: [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -> we can just jump to the end without
- // iterating whole array
- tmp = Math.max(tmp, nums[i]);
- if (i + tmp >= sz - 1) {
- return true;
+ if (nums.length == 1) {
+ return true;
+ }
+ if (nums[0] == 0) {
+ return false;
+ }
+ int fin = nums.length - 1;
+ for (int i = nums.length - 2; i >= 0; i--) {
+ if ((nums[i] + i) >= fin) {
+ fin = i;
}
}
- // we can just return true at the end, because if tmp is 0 on previous
- // iteration,
- // even though the next iteration index is the last one, it will return false under the
- // tmp<0 condition
- return true;
+ return fin == 0;
}
}
diff --git a/src/main/java/g0001_0100/s0055_jump_game/readme.md b/src/main/java/g0001_0100/s0055_jump_game/readme.md
index 0f4d2dbde..12f07317a 100644
--- a/src/main/java/g0001_0100/s0055_jump_game/readme.md
+++ b/src/main/java/g0001_0100/s0055_jump_game/readme.md
@@ -25,4 +25,38 @@ Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Constraints:**
* 1 <= nums.length <= 104
-* 0 <= nums[i] <= 105
\ No newline at end of file
+* 0 <= nums[i] <= 105
+
+To solve the "Jump Game" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `canJump` in the `Solution` class that takes an integer array `nums` as input and returns a boolean indicating whether it's possible to reach the last index.
+2. Initialize a variable `maxReach` to keep track of the maximum index that can be reached.
+3. Iterate through the array `nums` from index `0` to `nums.length - 1`:
+ - Check if the current index `i` is greater than `maxReach`. If it is, return `false` as it's not possible to reach the last index.
+ - Update `maxReach` as the maximum of `maxReach` and `i + nums[i]`, which represents the furthest index that can be reached from the current position.
+4. After iterating through all elements in `nums`, return `true` as it's possible to reach the last index.
+
+Here's the implementation of the `canJump` method in Java:
+
+```java
+class Solution {
+ public boolean canJump(int[] nums) {
+ if (nums == null || nums.length == 0) {
+ return false;
+ }
+ int maxReach = 0;
+ for (int i = 0; i < nums.length; i++) {
+ if (i > maxReach) {
+ return false;
+ }
+ maxReach = Math.max(maxReach, i + nums[i]);
+ if (maxReach >= nums.length - 1) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+```
+
+This implementation efficiently determines whether it's possible to reach the last index in the given array `nums` using a greedy approach, with a time complexity of O(n).
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0056_merge_intervals/Solution.java b/src/main/java/g0001_0100/s0056_merge_intervals/Solution.java
index 451550860..dbc4360e7 100644
--- a/src/main/java/g0001_0100/s0056_merge_intervals/Solution.java
+++ b/src/main/java/g0001_0100/s0056_merge_intervals/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting
// #Data_Structure_II_Day_2_Array #Level_2_Day_17_Interval #Udemy_2D_Arrays/Matrix
-// #Big_O_Time_O(n_log_n)_Space_O(n) #2023_08_11_Time_8_ms_(96.27%)_Space_45.2_MB_(90.13%)
+// #Top_Interview_150_Intervals #Big_O_Time_O(n_log_n)_Space_O(n)
+// #2024_11_11_Time_7_ms_(98.37%)_Space_46.8_MB_(11.43%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g0001_0100/s0056_merge_intervals/readme.md b/src/main/java/g0001_0100/s0056_merge_intervals/readme.md
index d4409dbb1..64ab839c6 100644
--- a/src/main/java/g0001_0100/s0056_merge_intervals/readme.md
+++ b/src/main/java/g0001_0100/s0056_merge_intervals/readme.md
@@ -10,7 +10,7 @@ Given an array of `intervals` where intervals[i] = [starti, end
**Output:** [[1,6],[8,10],[15,18]]
-**Explanation:** Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
+**Explanation:** Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
**Example 2:**
@@ -20,8 +20,49 @@ Given an array of `intervals` where intervals[i] = [starti, end
**Explanation:** Intervals [1,4] and [4,5] are considered overlapping.
+**Example 3:**
+
+**Input:** intervals = [[4,7],[1,4]]
+
+**Output:** [[1,7]]
+
+**Explanation:** Intervals [1,4] and [4,7] are considered overlapping.
+
**Constraints:**
* 1 <= intervals.length <= 104
* `intervals[i].length == 2`
-* 0 <= starti <= endi <= 104
\ No newline at end of file
+* 0 <= starti <= endi <= 104
+
+To solve the "Merge Intervals" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `merge` in the `Solution` class that takes an array of integer arrays `intervals` as input and returns an array of the non-overlapping intervals that cover all the intervals in the input.
+2. Sort the intervals based on the start times.
+3. Initialize an ArrayList to store the merged intervals.
+4. Iterate through the sorted intervals:
+ - If the list of merged intervals is empty or the current interval's start time is greater than the end time of the last merged interval, add the current interval to the list of merged intervals.
+ - Otherwise, merge the current interval with the last merged interval by updating its end time if needed.
+5. Convert the ArrayList of merged intervals into an array and return it as the result.
+
+Here's the implementation of the `merge` method in Java:
+
+```java
+import java.util.*;
+
+class Solution {
+ public int[][] merge(int[][] intervals) {
+ Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0]));
+ List merged = new ArrayList<>();
+ for (int[] interval : intervals) {
+ if (merged.isEmpty() || interval[0] > merged.get(merged.size() - 1)[1]) {
+ merged.add(interval);
+ } else {
+ merged.get(merged.size() - 1)[1] = Math.max(merged.get(merged.size() - 1)[1], interval[1]);
+ }
+ }
+ return merged.toArray(new int[merged.size()][]);
+ }
+}
+```
+
+This implementation efficiently merges overlapping intervals in the given array `intervals` using sorting and iteration, with a time complexity of O(n log n) due to sorting.
diff --git a/src/main/java/g0001_0100/s0057_insert_interval/Solution.java b/src/main/java/g0001_0100/s0057_insert_interval/Solution.java
index 3396d94ca..be5b6e722 100644
--- a/src/main/java/g0001_0100/s0057_insert_interval/Solution.java
+++ b/src/main/java/g0001_0100/s0057_insert_interval/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0057_insert_interval;
-// #Medium #Array #Level_2_Day_17_Interval #2023_08_11_Time_0_ms_(100.00%)_Space_43.7_MB_(95.60%)
+// #Medium #Array #Level_2_Day_17_Interval #Top_Interview_150_Intervals
+// #2025_03_04_Time_0_ms_(100.00%)_Space_44.76_MB_(89.09%)
import java.util.Arrays;
diff --git a/src/main/java/g0001_0100/s0057_insert_interval/readme.md b/src/main/java/g0001_0100/s0057_insert_interval/readme.md
index 1b94c0138..a179bde23 100644
--- a/src/main/java/g0001_0100/s0057_insert_interval/readme.md
+++ b/src/main/java/g0001_0100/s0057_insert_interval/readme.md
@@ -8,6 +8,8 @@ Insert `newInterval` into `intervals` such that `intervals` is still sorted in a
Return `intervals` _after the insertion_.
+**Note** that you don't need to modify `intervals` in-place. You can make a new array and return it.
+
**Example 1:**
**Input:** intervals = [[1,3],[6,9]], newInterval = [2,5]
@@ -20,25 +22,7 @@ Return `intervals` _after the insertion_.
**Output:** [[1,2],[3,10],[12,16]]
-**Explanation:** Because the new interval `[4,8]` overlaps with `[3,5],[6,7],[8,10]`.
-
-**Example 3:**
-
-**Input:** intervals = [], newInterval = [5,7]
-
-**Output:** [[5,7]]
-
-**Example 4:**
-
-**Input:** intervals = [[1,5]], newInterval = [2,3]
-
-**Output:** [[1,5]]
-
-**Example 5:**
-
-**Input:** intervals = [[1,5]], newInterval = [2,7]
-
-**Output:** [[1,7]]
+**Explanation:** Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
**Constraints:**
diff --git a/src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java b/src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java
index 0d39a23e7..7543b7ae6 100644
--- a/src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java
+++ b/src/main/java/g0001_0100/s0058_length_of_last_word/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0058_length_of_last_word;
-// #Easy #String #Programming_Skills_II_Day_6 #Udemy_Arrays
-// #2023_08_11_Time_0_ms_(100.00%)_Space_40.3_MB_(97.60%)
+// #Easy #String #Programming_Skills_II_Day_6 #Udemy_Arrays #Top_Interview_150_Array/String
+// #2025_03_04_Time_0_ms_(100.00%)_Space_41.72_MB_(64.92%)
public class Solution {
public int lengthOfLastWord(String s) {
diff --git a/src/main/java/g0001_0100/s0058_length_of_last_word/readme.md b/src/main/java/g0001_0100/s0058_length_of_last_word/readme.md
index 96b92534e..578da4752 100644
--- a/src/main/java/g0001_0100/s0058_length_of_last_word/readme.md
+++ b/src/main/java/g0001_0100/s0058_length_of_last_word/readme.md
@@ -2,9 +2,9 @@
Easy
-Given a string `s` consisting of some words separated by some number of spaces, return _the length of the **last** word in the string._
+Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
-A **word** is a maximal substring consisting of non-space characters only.
+A **word** is a maximal **substring** consisting of non-space characters only.
**Example 1:**
diff --git a/src/main/java/g0001_0100/s0061_rotate_list/Solution.java b/src/main/java/g0001_0100/s0061_rotate_list/Solution.java
index b068e3eb7..ebbaf2f9d 100644
--- a/src/main/java/g0001_0100/s0061_rotate_list/Solution.java
+++ b/src/main/java/g0001_0100/s0061_rotate_list/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0061_rotate_list;
// #Medium #Two_Pointers #Linked_List #Programming_Skills_II_Day_16 #Udemy_Linked_List
-// #2023_08_11_Time_0_ms_(100.00%)_Space_41.1_MB_(94.89%)
+// #Top_Interview_150_Linked_List #2025_03_04_Time_0_ms_(100.00%)_Space_42.42_MB_(78.37%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0062_unique_paths/Solution.java b/src/main/java/g0001_0100/s0062_unique_paths/Solution.java
index 5d17eabe0..9e8802538 100644
--- a/src/main/java/g0001_0100/s0062_unique_paths/Solution.java
+++ b/src/main/java/g0001_0100/s0062_unique_paths/Solution.java
@@ -1,9 +1,9 @@
package g0001_0100.s0062_unique_paths;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math
-// #Combinatorics #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_15
-// #Level_1_Day_11_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
-// #2023_08_11_Time_0_ms_(100.00%)_Space_39.2_MB_(67.74%)
+// #Combinatorics #LeetCode_75_DP/Multidimensional #Algorithm_II_Day_13_Dynamic_Programming
+// #Dynamic_Programming_I_Day_15 #Level_1_Day_11_Dynamic_Programming
+// #Big_O_Time_O(m*n)_Space_O(m*n) #2024_11_11_Time_0_ms_(100.00%)_Space_40.7_MB_(12.56%)
public class Solution {
public int uniquePaths(int m, int n) {
diff --git a/src/main/java/g0001_0100/s0062_unique_paths/readme.md b/src/main/java/g0001_0100/s0062_unique_paths/readme.md
index eaf4311e2..ec2431fa9 100644
--- a/src/main/java/g0001_0100/s0062_unique_paths/readme.md
+++ b/src/main/java/g0001_0100/s0062_unique_paths/readme.md
@@ -2,11 +2,11 @@
Medium
-A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below).
+There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
-The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
+Given the two integers `m` and `n`, return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
-How many possible unique paths are there?
+The test cases are generated so that the answer will be less than or equal to 2 * 109.
**Example 1:**
@@ -22,26 +22,42 @@ How many possible unique paths are there?
**Output:** 3
-**Explanation:**
-
- From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
- 1. Right -> Down -> Down
- 2. Down -> Down -> Right
- 3. Down -> Right -> Down
-
-**Example 3:**
-
-**Input:** m = 7, n = 3
-
-**Output:** 28
-
-**Example 4:**
-
-**Input:** m = 3, n = 3
-
-**Output:** 6
+**Explanation:** From the top-left corner, there are a total of 3 ways to reach the bottom-right corner: 1. Right -> Down -> Down 2. Down -> Down -> Right 3. Down -> Right -> Down
**Constraints:**
* `1 <= m, n <= 100`
-* It's guaranteed that the answer will be less than or equal to 2 * 109.
\ No newline at end of file
+* It's guaranteed that the answer will be less than or equal to 2 * 109.
+
+To solve the "Unique Paths" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `uniquePaths` in the `Solution` class that takes two integers `m` and `n` as input and returns the number of unique paths from the top-left corner to the bottom-right corner of an `m x n` grid.
+2. Initialize a 2D array `dp` of size `m x n` to store the number of unique paths for each position in the grid.
+3. Initialize the first row and first column of `dp` to 1 since there is only one way to reach any position in the first row or column (by moving only right or down).
+4. Iterate over each position `(i, j)` in the grid, starting from the second row and second column:
+ - Update `dp[i][j]` by adding the number of unique paths from the cell above `(i-1, j)` and the cell to the left `(i, j-1)`.
+5. Return the value of `dp[m-1][n-1]`, which represents the number of unique paths to reach the bottom-right corner of the grid.
+
+Here's the implementation of the `uniquePaths` method in Java:
+
+```java
+class Solution {
+ public int uniquePaths(int m, int n) {
+ int[][] dp = new int[m][n];
+ for (int i = 0; i < m; i++) {
+ dp[i][0] = 1; // Initialize first column to 1
+ }
+ for (int j = 0; j < n; j++) {
+ dp[0][j] = 1; // Initialize first row to 1
+ }
+ for (int i = 1; i < m; i++) {
+ for (int j = 1; j < n; j++) {
+ dp[i][j] = dp[i-1][j] + dp[i][j-1]; // Calculate number of paths for current cell
+ }
+ }
+ return dp[m-1][n-1]; // Return number of unique paths for bottom-right corner
+ }
+}
+```
+
+This implementation efficiently calculates the number of unique paths using dynamic programming, with a time complexity of O(m * n) and a space complexity of O(m * n).
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java b/src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java
index 3252ca3d8..350e1203e 100644
--- a/src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0063_unique_paths_ii/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0063_unique_paths_ii;
// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_15
-// #2023_08_11_Time_0_ms_(100.00%)_Space_40.6_MB_(73.18%)
+// #Top_Interview_150_Multidimensional_DP #2025_03_04_Time_0_ms_(100.00%)_Space_41.62_MB_(79.66%)
public class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
diff --git a/src/main/java/g0001_0100/s0063_unique_paths_ii/readme.md b/src/main/java/g0001_0100/s0063_unique_paths_ii/readme.md
index 2d511b1af..f4351a18f 100644
--- a/src/main/java/g0001_0100/s0063_unique_paths_ii/readme.md
+++ b/src/main/java/g0001_0100/s0063_unique_paths_ii/readme.md
@@ -2,13 +2,13 @@
Medium
-A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below).
+You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
-The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
+An obstacle and space are marked as `1` or `0` respectively in `grid`. A path that the robot takes cannot include **any** square that is an obstacle.
-Now consider if some obstacles are added to the grids. How many unique paths would there be?
+Return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
-An obstacle and space is marked as `1` and `0` respectively in the grid.
+The testcases are generated so that the answer will be less than or equal to 2 * 109.
**Example 1:**
diff --git a/src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java b/src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java
index 4d9fc66f0..b456882a2 100644
--- a/src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java
+++ b/src/main/java/g0001_0100/s0064_minimum_path_sum/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0064_minimum_path_sum;
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix
-// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
-// #2023_08_11_Time_0_ms_(100.00%)_Space_44_MB_(58.56%)
+// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP
+// #Big_O_Time_O(m*n)_Space_O(m*n) #2024_11_11_Time_1_ms_(99.73%)_Space_47.5_MB_(44.29%)
public class Solution {
public int minPathSum(int[][] grid) {
diff --git a/src/main/java/g0001_0100/s0064_minimum_path_sum/readme.md b/src/main/java/g0001_0100/s0064_minimum_path_sum/readme.md
index fa60cb1ae..2a49e04ab 100644
--- a/src/main/java/g0001_0100/s0064_minimum_path_sum/readme.md
+++ b/src/main/java/g0001_0100/s0064_minimum_path_sum/readme.md
@@ -27,4 +27,45 @@ Given a `m x n` `grid` filled with non-negative numbers, find a path from top le
* `m == grid.length`
* `n == grid[i].length`
* `1 <= m, n <= 200`
-* `0 <= grid[i][j] <= 100`
\ No newline at end of file
+* `0 <= grid[i][j] <= 200`
+
+To solve the "Minimum Path Sum" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `minPathSum` in the `Solution` class that takes a 2D grid of non-negative numbers as input and returns the minimum sum of all numbers along the path from the top-left corner to the bottom-right corner of the grid.
+2. Initialize a 2D array `dp` of size `m x n`, where `dp[i][j]` represents the minimum sum of the path from the top-left corner to position `(i, j)` in the grid.
+3. Initialize `dp[0][0]` to the value of the top-left cell in the grid.
+4. Initialize the first row and first column of `dp` based on the grid values and the previous cells in the same row or column.
+5. Iterate over each position `(i, j)` in the grid, starting from the second row and second column:
+ - Update `dp[i][j]` by adding the current grid value at `(i, j)` to the minimum of the values of the previous cells `(i-1, j)` and `(i, j-1)` in `dp`.
+6. Return `dp[m-1][n-1]`, which represents the minimum path sum from the top-left corner to the bottom-right corner of the grid.
+
+Here's the implementation of the `minPathSum` method in Java:
+
+```java
+class Solution {
+ public int minPathSum(int[][] grid) {
+ int m = grid.length;
+ int n = grid[0].length;
+ int[][] dp = new int[m][n];
+
+ dp[0][0] = grid[0][0];
+ // Initialize first row
+ for (int j = 1; j < n; j++) {
+ dp[0][j] = dp[0][j-1] + grid[0][j];
+ }
+ // Initialize first column
+ for (int i = 1; i < m; i++) {
+ dp[i][0] = dp[i-1][0] + grid[i][0];
+ }
+ // Fill in the rest of the dp array
+ for (int i = 1; i < m; i++) {
+ for (int j = 1; j < n; j++) {
+ dp[i][j] = grid[i][j] + Math.min(dp[i-1][j], dp[i][j-1]);
+ }
+ }
+ return dp[m-1][n-1];
+ }
+}
+```
+
+This implementation efficiently calculates the minimum path sum using dynamic programming, with a time complexity of O(m * n) and a space complexity of O(m * n).
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0065_valid_number/Solution.java b/src/main/java/g0001_0100/s0065_valid_number/Solution.java
index 5eedfe73b..8faf9de03 100644
--- a/src/main/java/g0001_0100/s0065_valid_number/Solution.java
+++ b/src/main/java/g0001_0100/s0065_valid_number/Solution.java
@@ -4,7 +4,7 @@
public class Solution {
public boolean isNumber(String s) {
- if (s == null || s.length() == 0) {
+ if (s == null || s.isEmpty()) {
return false;
}
boolean eSeen = false;
diff --git a/src/main/java/g0001_0100/s0066_plus_one/Solution.java b/src/main/java/g0001_0100/s0066_plus_one/Solution.java
index 9633842c4..d74906e39 100644
--- a/src/main/java/g0001_0100/s0066_plus_one/Solution.java
+++ b/src/main/java/g0001_0100/s0066_plus_one/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0066_plus_one;
// #Easy #Top_Interview_Questions #Array #Math #Programming_Skills_II_Day_3 #Udemy_Arrays
-// #2023_08_11_Time_0_ms_(100.00%)_Space_40.8_MB_(76.07%)
+// #Top_Interview_150_Math #2025_03_05_Time_0_ms_(100.00%)_Space_41.78_MB_(81.75%)
public class Solution {
public int[] plusOne(int[] digits) {
diff --git a/src/main/java/g0001_0100/s0066_plus_one/readme.md b/src/main/java/g0001_0100/s0066_plus_one/readme.md
index c2e467dcd..9ad61754e 100644
--- a/src/main/java/g0001_0100/s0066_plus_one/readme.md
+++ b/src/main/java/g0001_0100/s0066_plus_one/readme.md
@@ -2,7 +2,7 @@
Easy
-You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
+You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and return _the resulting array of digits_.
@@ -24,14 +24,6 @@ Increment the large integer by one and return _the resulting array of digits_.
**Example 3:**
-**Input:** digits = [0]
-
-**Output:** [1]
-
-**Explanation:** The array represents the integer 0. Incrementing by one gives 0 + 1 = 1. Thus, the result should be [1].
-
-**Example 4:**
-
**Input:** digits = [9]
**Output:** [1,0]
diff --git a/src/main/java/g0001_0100/s0067_add_binary/Solution.java b/src/main/java/g0001_0100/s0067_add_binary/Solution.java
index 138084f40..02096bf9b 100644
--- a/src/main/java/g0001_0100/s0067_add_binary/Solution.java
+++ b/src/main/java/g0001_0100/s0067_add_binary/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0067_add_binary;
// #Easy #String #Math #Bit_Manipulation #Simulation #Programming_Skills_II_Day_5
-// #2023_08_11_Time_1_ms_(100.00%)_Space_41.6_MB_(36.86%)
+// #Top_Interview_150_Bit_Manipulation #2025_03_05_Time_1_ms_(99.82%)_Space_42.31_MB_(52.66%)
public class Solution {
public String addBinary(String a, String b) {
diff --git a/src/main/java/g0001_0100/s0068_text_justification/Solution.java b/src/main/java/g0001_0100/s0068_text_justification/Solution.java
index c04e06ab9..fad81ce8a 100644
--- a/src/main/java/g0001_0100/s0068_text_justification/Solution.java
+++ b/src/main/java/g0001_0100/s0068_text_justification/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0068_text_justification;
-// #Hard #Array #String #Simulation #2023_08_11_Time_0_ms_(100.00%)_Space_40.8_MB_(72.37%)
+// #Hard #Array #String #Simulation #Top_Interview_150_Array/String
+// #2025_03_05_Time_0_ms_(100.00%)_Space_42.06_MB_(29.81%)
import java.util.ArrayList;
import java.util.List;
@@ -43,9 +44,8 @@ public List fullJustify(String[] words, int maxWidth) {
sb.append(' ');
}
// appending the rest of the required spaces
- for (int k = 0; k < (maxWidth - lineTotal) / (numWordsOnLine - 1); k++) {
- sb.append(' ');
- }
+ int max = Math.max(0, (maxWidth - lineTotal) / (numWordsOnLine - 1));
+ sb.append(" ".repeat(max));
}
// appending the last word of the line
sb.append(words[startWord + numWordsOnLine - 1]);
diff --git a/src/main/java/g0001_0100/s0068_text_justification/readme.md b/src/main/java/g0001_0100/s0068_text_justification/readme.md
index 78e9dd708..8340865ce 100644
--- a/src/main/java/g0001_0100/s0068_text_justification/readme.md
+++ b/src/main/java/g0001_0100/s0068_text_justification/readme.md
@@ -8,12 +8,12 @@ You should pack your words in a greedy approach; that is, pack as many words as
Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
-For the last line of text, it should be left-justified and no extra space is inserted between words.
+For the last line of text, it should be left-justified, and no extra space is inserted between words.
**Note:**
* A word is defined as a character sequence consisting of non-space characters only.
-* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
+* Each word's length is guaranteed to be greater than `0` and not exceed `maxWidth`.
* The input array `words` contains at least one word.
**Example 1:**
@@ -28,7 +28,7 @@ For the last line of text, it should be left-justified and no extra space is ins
**Output:** [ "What must be", "acknowledgment ", "shall be " ]
-**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word.
+**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified because it contains only one word.
**Example 3:**
diff --git a/src/main/java/g0001_0100/s0069_sqrtx/Solution.java b/src/main/java/g0001_0100/s0069_sqrtx/Solution.java
index d12f15189..4875ff397 100644
--- a/src/main/java/g0001_0100/s0069_sqrtx/Solution.java
+++ b/src/main/java/g0001_0100/s0069_sqrtx/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0069_sqrtx;
// #Easy #Top_Interview_Questions #Math #Binary_Search #Binary_Search_I_Day_4
-// #2023_08_11_Time_1_ms_(99.51%)_Space_39.5_MB_(78.13%)
+// #Top_Interview_150_Math #2025_03_05_Time_1_ms_(86.67%)_Space_41.11_MB_(29.05%)
public class Solution {
public int mySqrt(int x) {
diff --git a/src/main/java/g0001_0100/s0069_sqrtx/readme.md b/src/main/java/g0001_0100/s0069_sqrtx/readme.md
index 005177f31..4c91b62ca 100644
--- a/src/main/java/g0001_0100/s0069_sqrtx/readme.md
+++ b/src/main/java/g0001_0100/s0069_sqrtx/readme.md
@@ -2,17 +2,19 @@
Easy
-Given a non-negative integer `x`, compute and return _the square root of_ `x`.
+Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
-Since the return type is an integer, the decimal digits are **truncated**, and only **the integer part** of the result is returned.
+You **must not use** any built-in exponent function or operator.
-**Note:** You are not allowed to use any built-in exponent function or operator, such as `pow(x, 0.5)` or `x ** 0.5`.
+* For example, do not use `pow(x, 0.5)` in c++ or x ** 0.5 in python.
**Example 1:**
**Input:** x = 4
-**Output:** 2
+**Output:** 2
+
+**Explanation:** The square root of 4 is 2, so we return 2.
**Example 2:**
@@ -20,8 +22,8 @@ Since the return type is an integer, the decimal digits are **truncated**, and o
**Output:** 2
-**Explanation:** The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
+**Explanation:** The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
**Constraints:**
-* 0 <= x <= 231 - 1
+* 0 <= x <= 231 - 1
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java b/src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java
index ae3115191..f966dfa72 100644
--- a/src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java
+++ b/src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java
@@ -2,8 +2,8 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math #Memoization
// #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_2
-// #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Big_O_Time_O(n)_Space_O(n)
-// #2023_08_11_Time_0_ms_(100.00%)_Space_39.2_MB_(71.51%)
+// #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_11_Time_0_ms_(100.00%)_Space_40.3_MB_(41.06%)
public class Solution {
public int climbStairs(int n) {
diff --git a/src/main/java/g0001_0100/s0070_climbing_stairs/readme.md b/src/main/java/g0001_0100/s0070_climbing_stairs/readme.md
index 41c3a2a54..93180a257 100644
--- a/src/main/java/g0001_0100/s0070_climbing_stairs/readme.md
+++ b/src/main/java/g0001_0100/s0070_climbing_stairs/readme.md
@@ -24,4 +24,36 @@ Each time you can either climb `1` or `2` steps. In how many distinct ways can y
**Constraints:**
-* `1 <= n <= 45`
\ No newline at end of file
+* `1 <= n <= 45`
+
+To solve the "Climbing Stairs" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `climbStairs` in the `Solution` class that takes an integer `n` as input and returns the number of distinct ways to climb to the top of the staircase with `n` steps.
+2. Initialize an array `dp` of size `n+1` to store the number of distinct ways to reach each step.
+3. Set `dp[0] = 1` and `dp[1] = 1` since there is only one way to reach the first and second steps.
+4. Iterate over the steps from `2` to `n`:
+ - At each step `i`, the number of distinct ways to reach step `i` is the sum of the number of ways to reach steps `i-1` and `i-2`.
+ - Store this sum in `dp[i]`.
+5. Return `dp[n]`, which represents the number of distinct ways to climb to the top of the staircase with `n` steps.
+
+Here's the implementation of the `climbStairs` method in Java:
+
+```java
+class Solution {
+ public int climbStairs(int n) {
+ if (n == 1) return 1;
+
+ int[] dp = new int[n + 1];
+ dp[0] = 1;
+ dp[1] = 1;
+
+ for (int i = 2; i <= n; i++) {
+ dp[i] = dp[i - 1] + dp[i - 2];
+ }
+
+ return dp[n];
+ }
+}
+```
+
+This implementation efficiently calculates the number of distinct ways to climb the stairs using dynamic programming, with a time complexity of O(n) and a space complexity of O(n).
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0071_simplify_path/Solution.java b/src/main/java/g0001_0100/s0071_simplify_path/Solution.java
index 484bd3d43..162cefc70 100644
--- a/src/main/java/g0001_0100/s0071_simplify_path/Solution.java
+++ b/src/main/java/g0001_0100/s0071_simplify_path/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0071_simplify_path;
-// #Medium #String #Stack #2023_08_11_Time_2_ms_(99.80%)_Space_41.7_MB_(99.37%)
+// #Medium #String #Stack #Top_Interview_150_Stack
+// #2025_03_05_Time_2_ms_(99.86%)_Space_43.12_MB_(91.80%)
import java.util.ArrayDeque;
import java.util.Deque;
@@ -32,6 +33,6 @@ public String simplifyPath(String path) {
ans.insert(0, stk.pop());
ans.insert(0, "/");
}
- return ans.length() > 0 ? ans.toString() : "/";
+ return !ans.isEmpty() ? ans.toString() : "/";
}
}
diff --git a/src/main/java/g0001_0100/s0071_simplify_path/readme.md b/src/main/java/g0001_0100/s0071_simplify_path/readme.md
index af8fa8b02..6f56e3d62 100644
--- a/src/main/java/g0001_0100/s0071_simplify_path/readme.md
+++ b/src/main/java/g0001_0100/s0071_simplify_path/readme.md
@@ -2,18 +2,23 @@
Medium
-Given a string `path`, which is an **absolute path** (starting with a slash `'/'`) to a file or directory in a Unix-style file system, convert it to the simplified **canonical path**.
+You are given an _absolute_ path for a Unix-style file system, which always begins with a slash `'/'`. Your task is to transform this absolute path into its **simplified canonical path**.
-In a Unix-style file system, a period `'.'` refers to the current directory, a double period `'..'` refers to the directory up a level, and any multiple consecutive slashes (i.e. `'//'`) are treated as a single slash `'/'`. For this problem, any other format of periods such as `'...'` are treated as file/directory names.
+The _rules_ of a Unix-style file system are as follows:
-The **canonical path** should have the following format:
+* A single period `'.'` represents the current directory.
+* A double period `'..'` represents the previous/parent directory.
+* Multiple consecutive slashes such as `'//'` and `'///'` are treated as a single slash `'/'`.
+* Any sequence of periods that does **not match** the rules above should be treated as a **valid directory or** **file** **name**. For example, `'...'` and `'....'` are valid directory or file names.
-* The path starts with a single slash `'/'`.
-* Any two directories are separated by a single slash `'/'`.
-* The path does not end with a trailing `'/'`.
-* The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period `'.'` or double period `'..'`)
+The simplified canonical path should follow these _rules_:
-Return _the simplified **canonical path**_.
+* The path must start with a single slash `'/'`.
+* Directories within the path must be separated by exactly one slash `'/'`.
+* The path must not end with a slash `'/'`, unless it is the root directory.
+* The path must not have any single or double periods (`'.'` and `'..'`) used to denote current or parent directories.
+
+Return the **simplified canonical path**.
**Example 1:**
@@ -21,29 +26,49 @@ Return _the simplified **canonical path**_.
**Output:** "/home"
-**Explanation:** Note that there is no trailing slash after the last directory name.
+**Explanation:**
+
+The trailing slash should be removed.
**Example 2:**
-**Input:** path = "/../"
+**Input:** path = "/home//foo/"
-**Output:** "/"
+**Output:** "/home/foo"
+
+**Explanation:**
-**Explanation:** Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
+Multiple consecutive slashes are replaced by a single one.
**Example 3:**
-**Input:** path = "/home//foo/"
+**Input:** path = "/home/user/Documents/../Pictures"
-**Output:** "/home/foo"
+**Output:** "/home/user/Pictures"
+
+**Explanation:**
-**Explanation:** In the canonical path, multiple consecutive slashes are replaced by a single one.
+A double period `".."` refers to the directory up a level (the parent directory).
**Example 4:**
-**Input:** path = "/a/./b/../../c/"
+**Input:** path = "/../"
+
+**Output:** "/"
+
+**Explanation:**
+
+Going one level up from the root directory is not possible.
+
+**Example 5:**
+
+**Input:** path = "/.../a/../b/c/../d/./"
+
+**Output:** "/.../b/d"
+
+**Explanation:**
-**Output:** "/c"
+`"..."` is a valid name for a directory in this problem.
**Constraints:**
diff --git a/src/main/java/g0001_0100/s0072_edit_distance/Solution.java b/src/main/java/g0001_0100/s0072_edit_distance/Solution.java
index 471752cce..8e65757cd 100644
--- a/src/main/java/g0001_0100/s0072_edit_distance/Solution.java
+++ b/src/main/java/g0001_0100/s0072_edit_distance/Solution.java
@@ -1,9 +1,9 @@
package g0001_0100.s0072_edit_distance;
-// #Hard #Top_100_Liked_Questions #String #Dynamic_Programming
+// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional
// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_19
-// #Udemy_Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n2)
-// #2023_08_11_Time_4_ms_(90.13%)_Space_41.8_MB_(99.78%)
+// #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(n^2)_Space_O(n2)
+// #2024_11_11_Time_3_ms_(97.19%)_Space_43.2_MB_(98.23%)
@SuppressWarnings("java:S2234")
public class Solution {
diff --git a/src/main/java/g0001_0100/s0072_edit_distance/readme.md b/src/main/java/g0001_0100/s0072_edit_distance/readme.md
index fbd054c97..b7ca3feb5 100644
--- a/src/main/java/g0001_0100/s0072_edit_distance/readme.md
+++ b/src/main/java/g0001_0100/s0072_edit_distance/readme.md
@@ -1,6 +1,6 @@
72\. Edit Distance
-Hard
+Medium
Given two strings `word1` and `word2`, return _the minimum number of operations required to convert `word1` to `word2`_.
@@ -29,4 +29,53 @@ You have the following three operations permitted on a word:
**Constraints:**
* `0 <= word1.length, word2.length <= 500`
-* `word1` and `word2` consist of lowercase English letters.
\ No newline at end of file
+* `word1` and `word2` consist of lowercase English letters.
+
+To solve the "Edit Distance" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `minDistance` in the `Solution` class that takes two strings `word1` and `word2` as input and returns the minimum number of operations required to convert `word1` to `word2`.
+2. Initialize a 2D array `dp` of size `(m+1) x (n+1)`, where `m` is the length of `word1` and `n` is the length of `word2`.
+3. Set `dp[i][0] = i` for all `i` from `0` to `m`, as the minimum number of operations to convert a string of length `i` to an empty string is `i` deletions.
+4. Set `dp[0][j] = j` for all `j` from `0` to `n`, as the minimum number of operations to convert an empty string to a string of length `j` is `j` insertions.
+5. Iterate over the characters of `word1` and `word2`:
+ - If `word1.charAt(i-1)` is equal to `word2.charAt(j-1)`, set `dp[i][j] = dp[i-1][j-1]`, as no operation is required to match these characters.
+ - Otherwise, set `dp[i][j]` to the minimum of the following three options:
+ - `dp[i-1][j] + 1`: Delete the character at position `i` from `word1`.
+ - `dp[i][j-1] + 1`: Insert the character at position `j` from `word2` into `word1`.
+ - `dp[i-1][j-1] + 1`: Replace the character at position `i` in `word1` with the character at position `j` in `word2`.
+6. Return `dp[m][n]`, which represents the minimum number of operations required to convert `word1` to `word2`.
+
+Here's the implementation of the `minDistance` method in Java:
+
+```java
+class Solution {
+ public int minDistance(String word1, String word2) {
+ int m = word1.length();
+ int n = word2.length();
+
+ int[][] dp = new int[m + 1][n + 1];
+
+ for (int i = 0; i <= m; i++) {
+ dp[i][0] = i;
+ }
+
+ for (int j = 0; j <= n; j++) {
+ dp[0][j] = j;
+ }
+
+ for (int i = 1; i <= m; i++) {
+ for (int j = 1; j <= n; j++) {
+ if (word1.charAt(i - 1) == word2.charAt(j - 1)) {
+ dp[i][j] = dp[i - 1][j - 1];
+ } else {
+ dp[i][j] = Math.min(dp[i - 1][j], Math.min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
+ }
+ }
+ }
+
+ return dp[m][n];
+ }
+}
+```
+
+This implementation efficiently calculates the minimum edit distance between two strings using dynamic programming, with a time complexity of O(m * n) and a space complexity of O(m * n), where m is the length of `word1` and n is the length of `word2`.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java b/src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java
index 3860b031d..d986ccbf7 100644
--- a/src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java
+++ b/src/main/java/g0001_0100/s0073_set_matrix_zeroes/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0073_set_matrix_zeroes;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Matrix
-// #Udemy_2D_Arrays/Matrix #Big_O_Time_O(m*n)_Space_O(1)
-// #2023_08_11_Time_1_ms_(79.07%)_Space_44.4_MB_(94.19%)
+// #Udemy_2D_Arrays/Matrix #Top_Interview_150_Matrix #Big_O_Time_O(m*n)_Space_O(1)
+// #2024_11_11_Time_0_ms_(100.00%)_Space_45.6_MB_(50.86%)
public class Solution {
// Approach: Use first row and first column for storing whether in future
diff --git a/src/main/java/g0001_0100/s0073_set_matrix_zeroes/readme.md b/src/main/java/g0001_0100/s0073_set_matrix_zeroes/readme.md
index 404b556e9..ad83c82ad 100644
--- a/src/main/java/g0001_0100/s0073_set_matrix_zeroes/readme.md
+++ b/src/main/java/g0001_0100/s0073_set_matrix_zeroes/readme.md
@@ -2,7 +2,7 @@
Medium
-Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s, and return _the matrix_.
+Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s.
You must do it [in place](https://en.wikipedia.org/wiki/In-place_algorithm).
@@ -33,4 +33,57 @@ You must do it [in place](https://en.wikipedia.org/wiki/In-place_algorithm).
* A straightforward solution using `O(mn)` space is probably a bad idea.
* A simple improvement uses `O(m + n)` space, but still not the best solution.
-* Could you devise a constant space solution?
\ No newline at end of file
+* Could you devise a constant space solution?
+
+To solve the "Set Matrix Zeroes" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `setZeroes` in the `Solution` class that takes a 2D integer matrix `matrix` as input and modifies it in place to set the entire row and column to zeros if an element is zero.
+2. Initialize two boolean arrays `rowZero` and `colZero` of size `m` and `n` respectively, where `m` is the number of rows in the matrix and `n` is the number of columns. These arrays will track whether a row or column needs to be set to zero.
+3. Iterate over the matrix to mark the rows and columns that contain zeros:
+ - If `matrix[i][j]` is zero, set `rowZero[i] = true` and `colZero[j] = true`.
+4. Iterate over the matrix again and set the entire row to zeros if `rowZero[i] = true` or the entire column to zeros if `colZero[j] = true`.
+5. Return the modified matrix.
+
+Here's the implementation of the `setZeroes` method in Java:
+
+```java
+class Solution {
+ public void setZeroes(int[][] matrix) {
+ int m = matrix.length;
+ int n = matrix[0].length;
+
+ boolean[] rowZero = new boolean[m];
+ boolean[] colZero = new boolean[n];
+
+ // Mark rows and columns containing zeros
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ if (matrix[i][j] == 0) {
+ rowZero[i] = true;
+ colZero[j] = true;
+ }
+ }
+ }
+
+ // Set rows to zero
+ for (int i = 0; i < m; i++) {
+ if (rowZero[i]) {
+ for (int j = 0; j < n; j++) {
+ matrix[i][j] = 0;
+ }
+ }
+ }
+
+ // Set columns to zero
+ for (int j = 0; j < n; j++) {
+ if (colZero[j]) {
+ for (int i = 0; i < m; i++) {
+ matrix[i][j] = 0;
+ }
+ }
+ }
+ }
+}
+```
+
+This implementation modifies the matrix in place to set entire rows and columns to zeros, with a time complexity of O(m * n) and a space complexity of O(m + n), where `m` is the number of rows and `n` is the number of columns in the matrix.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java b/src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java
index 4378f55f2..774633290 100644
--- a/src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java
+++ b/src/main/java/g0001_0100/s0074_search_a_2d_matrix/Solution.java
@@ -2,8 +2,8 @@
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Data_Structure_I_Day_5_Array
// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_8 #Level_2_Day_8_Binary_Search
-// #Udemy_2D_Arrays/Matrix #Big_O_Time_O(endRow+endCol)_Space_O(1)
-// #2023_08_11_Time_0_ms_(100.00%)_Space_40.9_MB_(71.91%)
+// #Udemy_2D_Arrays/Matrix #Top_Interview_150_Binary_Search #Big_O_Time_O(endRow+endCol)_Space_O(1)
+// #2024_11_11_Time_0_ms_(100.00%)_Space_42.2_MB_(40.02%)
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
diff --git a/src/main/java/g0001_0100/s0074_search_a_2d_matrix/readme.md b/src/main/java/g0001_0100/s0074_search_a_2d_matrix/readme.md
index ce4e033be..896f23130 100644
--- a/src/main/java/g0001_0100/s0074_search_a_2d_matrix/readme.md
+++ b/src/main/java/g0001_0100/s0074_search_a_2d_matrix/readme.md
@@ -2,11 +2,15 @@
Medium
-Write an efficient algorithm that searches for a value in an `m x n` matrix. This matrix has the following properties:
+You are given an `m x n` integer matrix `matrix` with the following two properties:
-* Integers in each row are sorted from left to right.
+* Each row is sorted in non-decreasing order.
* The first integer of each row is greater than the last integer of the previous row.
+Given an integer `target`, return `true` _if_ `target` _is in_ `matrix` _or_ `false` _otherwise_.
+
+You must write a solution in `O(log(m * n))` time complexity.
+
**Example 1:**

@@ -28,4 +32,42 @@ Write an efficient algorithm that searches for a value in an `m x n` matrix. Thi
* `m == matrix.length`
* `n == matrix[i].length`
* `1 <= m, n <= 100`
-* -104 <= matrix[i][j], target <= 104
\ No newline at end of file
+* -104 <= matrix[i][j], target <= 104
+
+To solve the "Search a 2D Matrix" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `searchMatrix` in the `Solution` class that takes a 2D integer matrix `matrix` and an integer `target` as input and returns `true` if the target value is found in the matrix, otherwise returns `false`.
+2. Initialize two pointers `row` and `col` to start at the top-right corner of the matrix. `row` starts from 0 and `col` starts from the last column.
+3. Loop until `row` is less than the number of rows in the matrix and `col` is greater than or equal to 0:
+ - If `matrix[row][col]` is equal to the target, return `true`.
+ - If `matrix[row][col]` is greater than the target, decrement `col`.
+ - If `matrix[row][col]` is less than the target, increment `row`.
+4. If the target is not found after the loop, return `false`.
+
+Here's the implementation of the `searchMatrix` method in Java:
+
+```java
+class Solution {
+ public boolean searchMatrix(int[][] matrix, int target) {
+ int m = matrix.length;
+ int n = matrix[0].length;
+
+ int row = 0;
+ int col = n - 1;
+
+ while (row < m && col >= 0) {
+ if (matrix[row][col] == target) {
+ return true;
+ } else if (matrix[row][col] > target) {
+ col--;
+ } else {
+ row++;
+ }
+ }
+
+ return false;
+ }
+}
+```
+
+This implementation searches for the target value efficiently in the given matrix by starting from the top-right corner and moving either left or down based on the comparison with the target value. The time complexity of this solution is O(m + n), where m is the number of rows and n is the number of columns in the matrix.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0075_sort_colors/Solution.java b/src/main/java/g0001_0100/s0075_sort_colors/Solution.java
index 53272c181..d11998782 100644
--- a/src/main/java/g0001_0100/s0075_sort_colors/Solution.java
+++ b/src/main/java/g0001_0100/s0075_sort_colors/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers
// #Data_Structure_II_Day_2_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
-// #2023_08_11_Time_0_ms_(100.00%)_Space_41_MB_(50.59%)
+// #2024_11_11_Time_0_ms_(100.00%)_Space_41.5_MB_(91.22%)
public class Solution {
public void sortColors(int[] nums) {
diff --git a/src/main/java/g0001_0100/s0075_sort_colors/readme.md b/src/main/java/g0001_0100/s0075_sort_colors/readme.md
index 4062c6f11..f64e105ca 100644
--- a/src/main/java/g0001_0100/s0075_sort_colors/readme.md
+++ b/src/main/java/g0001_0100/s0075_sort_colors/readme.md
@@ -20,22 +20,53 @@ You must solve this problem without using the library's sort function.
**Output:** [0,1,2]
-**Example 3:**
-
-**Input:** nums = [0]
-
-**Output:** [0]
-
-**Example 4:**
-
-**Input:** nums = [1]
-
-**Output:** [1]
-
**Constraints:**
* `n == nums.length`
* `1 <= n <= 300`
-* `nums[i]` is `0`, `1`, or `2`.
-
-**Follow up:** Could you come up with a one-pass algorithm using only constant extra space?
\ No newline at end of file
+* `nums[i]` is either `0`, `1`, or `2`.
+
+**Follow up:** Could you come up with a one-pass algorithm using only constant extra space?
+
+To solve the "Sort Colors" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `sortColors` in the `Solution` class that takes an array of integers `nums` as input and sorts it in-place according to the colors red, white, and blue.
+2. Initialize three pointers: `low`, `mid`, and `high`. `low` points to the beginning of the array, `mid` points to the current element being processed, and `high` points to the end of the array.
+3. Loop while `mid` is less than or equal to `high`:
+ - If `nums[mid]` is 0, swap `nums[low]` with `nums[mid]`, increment `low` and `mid`.
+ - If `nums[mid]` is 1, increment `mid`.
+ - If `nums[mid]` is 2, swap `nums[mid]` with `nums[high]`, decrement `high`.
+4. After the loop, the array will be sorted in-place according to the colors red, white, and blue.
+
+Here's the implementation of the `sortColors` method in Java:
+
+```java
+class Solution {
+ public void sortColors(int[] nums) {
+ int low = 0;
+ int mid = 0;
+ int high = nums.length - 1;
+
+ while (mid <= high) {
+ if (nums[mid] == 0) {
+ swap(nums, low, mid);
+ low++;
+ mid++;
+ } else if (nums[mid] == 1) {
+ mid++;
+ } else {
+ swap(nums, mid, high);
+ high--;
+ }
+ }
+ }
+
+ private void swap(int[] nums, int i, int j) {
+ int temp = nums[i];
+ nums[i] = nums[j];
+ nums[j] = temp;
+ }
+}
+```
+
+This implementation sorts the array in-place using a one-pass algorithm with constant extra space. It iterates through the array and swaps elements as needed to group them according to their colors. The time complexity of this solution is O(n), where n is the length of the array.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java b/src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java
index cc9db5e6e..7039227ba 100644
--- a/src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java
+++ b/src/main/java/g0001_0100/s0076_minimum_window_substring/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0076_minimum_window_substring;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window
-// #Level_2_Day_14_Sliding_Window/Two_Pointer #Big_O_Time_O(s.length())_Space_O(1)
-// #2023_08_11_Time_2_ms_(99.94%)_Space_43.6_MB_(93.87%)
+// #Level_2_Day_14_Sliding_Window/Two_Pointer #Top_Interview_150_Sliding_Window
+// #Big_O_Time_O(s.length())_Space_O(1) #2024_11_11_Time_2_ms_(99.83%)_Space_44.5_MB_(89.46%)
public class Solution {
public String minWindow(String s, String t) {
diff --git a/src/main/java/g0001_0100/s0076_minimum_window_substring/readme.md b/src/main/java/g0001_0100/s0076_minimum_window_substring/readme.md
index 7c7d492f9..cbe4b8e9a 100644
--- a/src/main/java/g0001_0100/s0076_minimum_window_substring/readme.md
+++ b/src/main/java/g0001_0100/s0076_minimum_window_substring/readme.md
@@ -2,12 +2,10 @@
Hard
-Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window substring** of_ `s` _such that every character in_ `t` _(**including duplicates**) is included in the window. If there is no such substring__, return the empty string_ `""`_._
+Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window**_ **substring** _of_ `s` _such that every character in_ `t` _(**including duplicates**) is included in the window_. If there is no such substring, return _the empty string_ `""`.
The testcases will be generated such that the answer is **unique**.
-A **substring** is a contiguous sequence of characters within the string.
-
**Example 1:**
**Input:** s = "ADOBECODEBANC", t = "ABC"
@@ -39,4 +37,75 @@ A **substring** is a contiguous sequence of characters within the string.
* 1 <= m, n <= 105
* `s` and `t` consist of uppercase and lowercase English letters.
-**Follow up:** Could you find an algorithm that runs in `O(m + n)` time?
\ No newline at end of file
+**Follow up:** Could you find an algorithm that runs in `O(m + n)` time?
+
+To solve the "Minimum Window Substring" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `minWindow` in the `Solution` class that takes two strings `s` and `t` as input and returns the minimum window substring of `s` containing all characters from `t`.
+2. Create two frequency maps: `tFreqMap` to store the frequency of characters in string `t`, and `sFreqMap` to store the frequency of characters in the current window of string `s`.
+3. Initialize two pointers `left` and `right` to track the window boundaries. Initialize a variable `minLength` to store the minimum window length found so far.
+4. Iterate over string `s` using the `right` pointer until the end of the string:
+ - Update the frequency map `sFreqMap` for the character at index `right`.
+ - Check if the current window contains all characters from `t`. If it does, move the `left` pointer to minimize the window while maintaining the condition.
+ - Update the `minLength` if the current window length is smaller.
+ - Move the `right` pointer to expand the window.
+5. Return the minimum window substring found, or an empty string if no such substring exists.
+
+Here's the implementation of the `minWindow` method in Java:
+
+```java
+import java.util.HashMap;
+import java.util.Map;
+
+class Solution {
+ public String minWindow(String s, String t) {
+ Map tFreqMap = new HashMap<>();
+ Map sFreqMap = new HashMap<>();
+
+ // Initialize tFreqMap with character frequencies from string t
+ for (char ch : t.toCharArray()) {
+ tFreqMap.put(ch, tFreqMap.getOrDefault(ch, 0) + 1);
+ }
+
+ int left = 0;
+ int right = 0;
+ int minLength = Integer.MAX_VALUE;
+ int minStart = 0;
+
+ while (right < s.length()) {
+ char rightChar = s.charAt(right);
+ sFreqMap.put(rightChar, sFreqMap.getOrDefault(rightChar, 0) + 1);
+ right++;
+
+ // Check if the current window contains all characters from t
+ while (containsAllChars(sFreqMap, tFreqMap)) {
+ // Update the minimum window length
+ if (right - left < minLength) {
+ minLength = right - left;
+ minStart = left;
+ }
+
+ char leftChar = s.charAt(left);
+ sFreqMap.put(leftChar, sFreqMap.get(leftChar) - 1);
+ left++;
+ }
+ }
+
+ return minLength == Integer.MAX_VALUE ? "" : s.substring(minStart, minStart + minLength);
+ }
+
+ // Helper method to check if sFreqMap contains all characters from tFreqMap
+ private boolean containsAllChars(Map sFreqMap, Map tFreqMap) {
+ for (Map.Entry entry : tFreqMap.entrySet()) {
+ char ch = entry.getKey();
+ int count = entry.getValue();
+ if (sFreqMap.getOrDefault(ch, 0) < count) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+```
+
+This implementation finds the minimum window substring in `O(m + n)` time complexity, where `m` is the length of string `s` and `n` is the length of string `t`. It uses two frequency maps to keep track of character frequencies and adjusts the window boundaries to find the minimum window containing all characters from `t`.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0077_combinations/Solution.java b/src/main/java/g0001_0100/s0077_combinations/Solution.java
index 960f2af9a..6276ed8f2 100644
--- a/src/main/java/g0001_0100/s0077_combinations/Solution.java
+++ b/src/main/java/g0001_0100/s0077_combinations/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0077_combinations;
-// #Medium #Backtracking #Algorithm_I_Day_11_Recursion_Backtracking
-// #2023_08_11_Time_11_ms_(77.40%)_Space_93_MB_(5.21%)
+// #Medium #Backtracking #Algorithm_I_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking
+// #2025_03_05_Time_15_ms_(92.38%)_Space_92.30_MB_(94.55%)
import java.util.ArrayDeque;
import java.util.ArrayList;
diff --git a/src/main/java/g0001_0100/s0077_combinations/readme.md b/src/main/java/g0001_0100/s0077_combinations/readme.md
index eaae4b479..2266cb505 100644
--- a/src/main/java/g0001_0100/s0077_combinations/readme.md
+++ b/src/main/java/g0001_0100/s0077_combinations/readme.md
@@ -2,7 +2,7 @@
Medium
-Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers out of the range_ `[1, n]`.
+Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers chosen from the range_ `[1, n]`.
You may return the answer in **any order**.
@@ -10,13 +10,17 @@ You may return the answer in **any order**.
**Input:** n = 4, k = 2
-**Output:** [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
+**Output:** [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
+
+**Explanation:** There are 4 choose 2 = 6 total combinations. Note that combinations are unordered, i.e., [1,2] and [2,1] are considered to be the same combination.
**Example 2:**
**Input:** n = 1, k = 1
-**Output:** [[1]]
+**Output:** [[1]]
+
+**Explanation:** There is 1 choose 1 = 1 total combination.
**Constraints:**
diff --git a/src/main/java/g0001_0100/s0078_subsets/Solution.java b/src/main/java/g0001_0100/s0078_subsets/Solution.java
index 329dc1965..4cc1f469f 100644
--- a/src/main/java/g0001_0100/s0078_subsets/Solution.java
+++ b/src/main/java/g0001_0100/s0078_subsets/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation #Backtracking
// #Algorithm_II_Day_9_Recursion_Backtracking #Udemy_Backtracking/Recursion
-// #Big_O_Time_O(2^n)_Space_O(n*2^n) #2023_08_11_Time_1_ms_(70.60%)_Space_41.8_MB_(71.73%)
+// #Big_O_Time_O(2^n)_Space_O(n*2^n) #2024_11_11_Time_0_ms_(100.00%)_Space_43_MB_(12.48%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0001_0100/s0078_subsets/readme.md b/src/main/java/g0001_0100/s0078_subsets/readme.md
index 2bd42eef1..788b97254 100644
--- a/src/main/java/g0001_0100/s0078_subsets/readme.md
+++ b/src/main/java/g0001_0100/s0078_subsets/readme.md
@@ -2,7 +2,7 @@
Medium
-Given an integer array `nums` of **unique** elements, return _all possible subsets (the power set)_.
+Given an integer array `nums` of **unique** elements, return _all possible_ **subset** _(the power set)_.
The solution set **must not** contain duplicate subsets. Return the solution in **any order**.
@@ -22,4 +22,49 @@ The solution set **must not** contain duplicate subsets. Return the solution in
* `1 <= nums.length <= 10`
* `-10 <= nums[i] <= 10`
-* All the numbers of `nums` are **unique**.
\ No newline at end of file
+* All the numbers of `nums` are **unique**.
+
+To solve the "Subsets" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `subsets` in the `Solution` class that takes an integer array `nums` as input and returns all possible subsets of `nums`.
+2. Initialize an empty list to store the result subsets.
+3. Implement a backtracking algorithm to generate all possible subsets:
+ - Define a recursive helper function `generateSubsets` that takes the current subset, the current index in the array, and the array `nums` as parameters.
+ - Base case: If the current index is equal to the length of `nums`, add the current subset to the result list.
+ - Recursive case:
+ - Include the current element in the subset and recursively call `generateSubsets` with the next index.
+ - Exclude the current element from the subset and recursively call `generateSubsets` with the next index.
+4. Call the `generateSubsets` function with an empty subset and the starting index 0.
+5. Return the list containing all subsets.
+
+Here's the implementation of the `subsets` method in Java:
+
+```java
+import java.util.ArrayList;
+import java.util.List;
+
+class Solution {
+ public List> subsets(int[] nums) {
+ List> result = new ArrayList<>();
+ generateSubsets(new ArrayList<>(), 0, nums, result);
+ return result;
+ }
+
+ private void generateSubsets(List subset, int index, int[] nums, List> result) {
+ // Base case: add the current subset to the result list
+ result.add(new ArrayList<>(subset));
+
+ // Recursive case
+ for (int i = index; i < nums.length; i++) {
+ // Include the current element in the subset
+ subset.add(nums[i]);
+ // Recursively generate subsets starting from the next index
+ generateSubsets(subset, i + 1, nums, result);
+ // Exclude the current element from the subset
+ subset.remove(subset.size() - 1);
+ }
+ }
+}
+```
+
+This implementation uses backtracking to generate all possible subsets of the input array `nums`. It has a time complexity of O(2^N), where N is the number of elements in the input array.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0079_word_search/Solution.java b/src/main/java/g0001_0100/s0079_word_search/Solution.java
index d055a50b7..d3d20e914 100644
--- a/src/main/java/g0001_0100/s0079_word_search/Solution.java
+++ b/src/main/java/g0001_0100/s0079_word_search/Solution.java
@@ -1,44 +1,53 @@
package g0001_0100.s0079_word_search;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Backtracking
-// #Algorithm_II_Day_11_Recursion_Backtracking #Big_O_Time_O(4^(m*n))_Space_O(m*n)
-// #2023_08_11_Time_157_ms_(78.97%)_Space_40.5_MB_(84.41%)
+// #Algorithm_II_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking
+// #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2024_11_11_Time_64_ms_(98.51%)_Space_41.6_MB_(51.63%)
public class Solution {
- private boolean backtrace(
- char[][] board, boolean[][] visited, String word, int index, int x, int y) {
- if (index == word.length()) {
- return true;
- }
- if (x < 0 || x >= board.length || y < 0 || y >= board[0].length || visited[x][y]) {
- return false;
- }
- visited[x][y] = true;
- if (word.charAt(index) == board[x][y]) {
- boolean res =
- backtrace(board, visited, word, index + 1, x, y + 1)
- || backtrace(board, visited, word, index + 1, x, y - 1)
- || backtrace(board, visited, word, index + 1, x + 1, y)
- || backtrace(board, visited, word, index + 1, x - 1, y);
- if (!res) {
- visited[x][y] = false;
- }
- return res;
- } else {
- visited[x][y] = false;
- return false;
- }
- }
+ private boolean exists = false;
public boolean exist(char[][] board, String word) {
- boolean[][] visited = new boolean[board.length][board[0].length];
- for (int i = 0; i < board.length; ++i) {
- for (int j = 0; j < board[0].length; ++j) {
- if (backtrace(board, visited, word, 0, i, j)) {
- return true;
+ for (int i = 0; i < board.length; i++) {
+ for (int j = 0; j < board[0].length; j++) {
+ if (board[i][j] == word.charAt(0)) {
+ dfs(board, word, 1, i, j);
}
}
}
- return false;
+ return exists;
+ }
+
+ private void dfs(char[][] board, String word, int wordIndex, int i, int j) {
+ if (wordIndex == word.length()) {
+ exists = true;
+ return;
+ }
+ char currentChar = board[i][j];
+ char nextChar = word.charAt(wordIndex);
+ if (i > 0 && board[i - 1][j] == nextChar) {
+ // go up
+ board[i][j] = '-';
+ dfs(board, word, wordIndex + 1, i - 1, j);
+ board[i][j] = currentChar;
+ }
+ if (j > 0 && board[i][j - 1] == nextChar) {
+ // go left
+ board[i][j] = '-';
+ dfs(board, word, wordIndex + 1, i, j - 1);
+ board[i][j] = currentChar;
+ }
+ if (i < board.length - 1 && board[i + 1][j] == nextChar) {
+ // go down
+ board[i][j] = '-';
+ dfs(board, word, wordIndex + 1, i + 1, j);
+ board[i][j] = currentChar;
+ }
+ if (j < board[0].length - 1 && board[i][j + 1] == nextChar) {
+ // go right
+ board[i][j] = '-';
+ dfs(board, word, wordIndex + 1, i, j + 1);
+ board[i][j] = currentChar;
+ }
}
}
diff --git a/src/main/java/g0001_0100/s0079_word_search/readme.md b/src/main/java/g0001_0100/s0079_word_search/readme.md
index 0500297a3..763f004ab 100644
--- a/src/main/java/g0001_0100/s0079_word_search/readme.md
+++ b/src/main/java/g0001_0100/s0079_word_search/readme.md
@@ -38,4 +38,55 @@ The word can be constructed from letters of sequentially adjacent cells, where a
* `1 <= word.length <= 15`
* `board` and `word` consists of only lowercase and uppercase English letters.
-**Follow up:** Could you use search pruning to make your solution faster with a larger `board`?
\ No newline at end of file
+**Follow up:** Could you use search pruning to make your solution faster with a larger `board`?
+
+To solve the "Word Search" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `exist` in the `Solution` class that takes a 2D character array `board` and a string `word` as input and returns `true` if the `word` exists in the `board`.
+2. Implement a backtracking algorithm to search for the `word` in the `board`.
+3. Iterate through each cell in the `board`:
+ - For each cell, call a recursive helper function `search` to check if the `word` can be found starting from that cell.
+ - If `search` returns `true`, return `true` immediately.
+4. Define the `search` method to perform the recursive backtracking:
+ - Check if the current cell is out of bounds or if the current character in the `board` does not match the corresponding character in the `word`.
+ - If any of the conditions are met, return `false`.
+ - Mark the current cell as visited by changing its value to a special character (e.g., `#`) to avoid revisiting it.
+ - Recursively call `search` on neighboring cells (up, down, left, right) with the next character in the `word`.
+ - After exploring all possible paths from the current cell, backtrack by restoring the original value of the current cell.
+5. If the `search` method reaches the end of the `word`, return `true`.
+6. If no match is found after exploring all cells, return `false`.
+
+Here's the implementation of the `exist` method in Java:
+
+```java
+class Solution {
+ public boolean exist(char[][] board, String word) {
+ int m = board.length;
+ int n = board[0].length;
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ if (search(board, word, i, j, 0))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean search(char[][] board, String word, int i, int j, int index) {
+ if (index == word.length())
+ return true;
+ if (i < 0 || i >= board.length || j < 0 || j >= board[0].length || board[i][j] != word.charAt(index))
+ return false;
+ char temp = board[i][j];
+ board[i][j] = '#'; // Mark as visited
+ boolean found = search(board, word, i + 1, j, index + 1) ||
+ search(board, word, i - 1, j, index + 1) ||
+ search(board, word, i, j + 1, index + 1) ||
+ search(board, word, i, j - 1, index + 1);
+ board[i][j] = temp; // Restore original value
+ return found;
+ }
+}
+```
+
+This implementation uses backtracking to search for the word in the board, with a time complexity of O(M * N * 4^L), where M and N are the dimensions of the board and L is the length of the word.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java b/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java
index d5e1f2fbc..76fe468f2 100644
--- a/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0080_remove_duplicates_from_sorted_array_ii;
-// #Medium #Array #Two_Pointers #Udemy_Arrays #2023_08_11_Time_0_ms_(100.00%)_Space_44_MB_(12.69%)
+// #Medium #Array #Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String
+// #2025_03_05_Time_0_ms_(100.00%)_Space_46.59_MB_(39.01%)
public class Solution {
public int removeDuplicates(int[] nums) {
diff --git a/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md b/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md
index fa021a5f9..4ed899fe3 100644
--- a/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md
+++ b/src/main/java/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/readme.md
@@ -18,7 +18,7 @@ The judge will test your solution with the following code:
int[] expectedNums = [...]; // The expected answer with correct length
int k = removeDuplicates(nums); // Calls your implementation
-
+
assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
assert nums[i] == expectedNums[i];
@@ -46,4 +46,4 @@ If all assertions pass, then your solution will be **accepted**.
* 1 <= nums.length <= 3 * 104
* -104 <= nums[i] <= 104
-* `nums` is sorted in **non-decreasing** order.
\ No newline at end of file
+* `nums` is sorted in **non-decreasing** order.
diff --git a/src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java b/src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java
index 27cefca09..3feb7e2f3 100644
--- a/src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution.java
@@ -1,7 +1,8 @@
package g0001_0100.s0082_remove_duplicates_from_sorted_list_ii;
// #Medium #Two_Pointers #Linked_List #Data_Structure_II_Day_11_Linked_List
-// #Algorithm_II_Day_3_Two_Pointers #2022_06_20_Time_0_ms_(100.00%)_Space_41.6_MB_(95.54%)
+// #Algorithm_II_Day_3_Two_Pointers #Top_Interview_150_Linked_List
+// #2025_03_05_Time_0_ms_(100.00%)_Space_43.31_MB_(44.18%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.java b/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.java
index 2b1a2fbfd..94c026deb 100644
--- a/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.java
+++ b/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0084_largest_rectangle_in_histogram;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Stack #Monotonic_Stack
-// #Big_O_Time_O(n_log_n)_Space_O(log_n) #2022_06_20_Time_11_ms_(98.34%)_Space_72.8_MB_(81.14%)
+// #Big_O_Time_O(n_log_n)_Space_O(log_n) #2024_11_13_Time_9_ms_(93.28%)_Space_54.6_MB_(99.95%)
public class Solution {
public int largestRectangleArea(int[] heights) {
diff --git a/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md b/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md
index 96ca2d0fe..cda2a9dcb 100644
--- a/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md
+++ b/src/main/java/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md
@@ -25,4 +25,48 @@ Given an array of integers `heights` representing the histogram's bar height whe
**Constraints:**
* 1 <= heights.length <= 105
-* 0 <= heights[i] <= 104
\ No newline at end of file
+* 0 <= heights[i] <= 104
+
+To solve the "Largest Rectangle in Histogram" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `largestRectangleArea` in the `Solution` class that takes an array of integers `heights` as input and returns the area of the largest rectangle in the histogram.
+2. Implement a stack-based algorithm to find the largest rectangle:
+ - Initialize a stack to store indices of bars in the histogram.
+ - Iterate through each bar in the histogram:
+ - If the stack is empty or the current bar's height is greater than or equal to the height of the bar at the top of the stack, push the current bar's index onto the stack.
+ - If the current bar's height is less than the height of the bar at the top of the stack, keep popping bars from the stack until either the stack is empty or the height of the bar at the top of the stack is less than the height of the current bar.
+ - Calculate the area of the rectangle formed by the popped bar using its height and width (the difference between the current index and the index of the previous bar in the stack or -1 if the stack is empty).
+ - Update the maximum area if the calculated area is greater.
+ - After iterating through all bars, pop the remaining bars from the stack and calculate the area of rectangles formed by them using the same method as above.
+3. Return the maximum area calculated.
+
+Here's the implementation of the `largestRectangleArea` method in Java:
+
+```java
+import java.util.Stack;
+
+class Solution {
+ public int largestRectangleArea(int[] heights) {
+ Stack stack = new Stack<>();
+ int maxArea = 0;
+ int i = 0;
+ while (i < heights.length) {
+ if (stack.isEmpty() || heights[i] >= heights[stack.peek()]) {
+ stack.push(i++);
+ } else {
+ int top = stack.pop();
+ int width = stack.isEmpty() ? i : i - stack.peek() - 1;
+ maxArea = Math.max(maxArea, heights[top] * width);
+ }
+ }
+ while (!stack.isEmpty()) {
+ int top = stack.pop();
+ int width = stack.isEmpty() ? i : i - stack.peek() - 1;
+ maxArea = Math.max(maxArea, heights[top] * width);
+ }
+ return maxArea;
+ }
+}
+```
+
+This implementation uses a stack-based approach to find the largest rectangle in the histogram, with a time complexity of O(N), where N is the number of bars in the histogram.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0086_partition_list/Solution.java b/src/main/java/g0001_0100/s0086_partition_list/Solution.java
index 0a44ec6e0..d7dab2d8a 100644
--- a/src/main/java/g0001_0100/s0086_partition_list/Solution.java
+++ b/src/main/java/g0001_0100/s0086_partition_list/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0086_partition_list;
-// #Medium #Two_Pointers #Linked_List #2022_06_20_Time_1_ms_(62.66%)_Space_43_MB_(25.29%)
+// #Medium #Two_Pointers #Linked_List #Top_Interview_150_Linked_List
+// #2025_03_05_Time_0_ms_(100.00%)_Space_41.88_MB_(91.77%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java b/src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java
index 4e0a82145..b356a2d25 100644
--- a/src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java
+++ b/src/main/java/g0001_0100/s0088_merge_sorted_array/Solution.java
@@ -1,7 +1,7 @@
package g0001_0100.s0088_merge_sorted_array;
// #Easy #Top_Interview_Questions #Array #Sorting #Two_Pointers #Data_Structure_I_Day_2_Array
-// #2022_06_20_Time_0_ms_(100.00%)_Space_42.7_MB_(55.70%)
+// #Top_Interview_150_Array/String #2025_03_05_Time_0_ms_(100.00%)_Space_42.40_MB_(26.50%)
public class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
diff --git a/src/main/java/g0001_0100/s0088_merge_sorted_array/readme.md b/src/main/java/g0001_0100/s0088_merge_sorted_array/readme.md
index c75ddb8c5..5e6d26581 100644
--- a/src/main/java/g0001_0100/s0088_merge_sorted_array/readme.md
+++ b/src/main/java/g0001_0100/s0088_merge_sorted_array/readme.md
@@ -14,7 +14,7 @@ The final sorted array should not be returned by the function, but instead be _s
**Output:** [1,2,2,3,5,6]
-**Explanation:** The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
+**Explanation:** The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
**Example 2:**
diff --git a/src/main/java/g0001_0100/s0092_reverse_linked_list_ii/Solution.java b/src/main/java/g0001_0100/s0092_reverse_linked_list_ii/Solution.java
index e35f049f2..547e80668 100644
--- a/src/main/java/g0001_0100/s0092_reverse_linked_list_ii/Solution.java
+++ b/src/main/java/g0001_0100/s0092_reverse_linked_list_ii/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0092_reverse_linked_list_ii;
-// #Medium #Linked_List #2022_06_21_Time_0_ms_(100.00%)_Space_41.8_MB_(52.21%)
+// #Medium #Linked_List #Top_Interview_150_Linked_List
+// #2025_03_05_Time_0_ms_(100.00%)_Space_41.36_MB_(51.54%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0001_0100/s0093_restore_ip_addresses/Solution.java b/src/main/java/g0001_0100/s0093_restore_ip_addresses/Solution.java
index 11b41ca14..bedc2fe1d 100644
--- a/src/main/java/g0001_0100/s0093_restore_ip_addresses/Solution.java
+++ b/src/main/java/g0001_0100/s0093_restore_ip_addresses/Solution.java
@@ -1,41 +1,53 @@
package g0001_0100.s0093_restore_ip_addresses;
-// #Medium #String #Backtracking #2022_06_21_Time_13_ms_(24.23%)_Space_42.8_MB_(71.26%)
+// #Medium #String #Backtracking #2024_05_13_Time_1_ms_(99.27%)_Space_42_MB_(90.75%)
import java.util.ArrayList;
import java.util.List;
public class Solution {
+ private static final int SEG_COUNT = 4;
+ private List result = new ArrayList<>();
+ private int[] segments = new int[SEG_COUNT];
+
public List restoreIpAddresses(String s) {
- List results = new ArrayList<>();
- step(s, 0, new int[4], 0, results);
- return results;
+ dfs(s, 0, 0);
+ return result;
}
- void step(String s, int pos, int[] octets, int count, List results) {
- if (count == 4 && pos == s.length()) {
- results.add(
- String.valueOf(octets[0])
- + '.'
- + octets[1]
- + '.'
- + octets[2]
- + '.'
- + octets[3]);
- } else if (count < 4 && pos < 12) {
- int octet = 0;
- for (int i = 0; i < 3; i++) {
- if (pos + i < s.length()) {
- int digit = s.charAt(pos + i) - '0';
- octet = octet * 10 + digit;
- if (octet < 256) {
- octets[count] = octet;
- step(s, pos + i + 1, octets, count + 1, results);
- }
- if (i == 0 && digit == 0) {
- break;
+ public void dfs(String s, int segId, int segStart) {
+ // find 4 segments and get to last index
+ if (segId == SEG_COUNT) {
+ if (segStart == s.length()) {
+ StringBuilder addr = new StringBuilder();
+ for (int i = 0; i < SEG_COUNT; i++) {
+ addr.append(segments[i]);
+ if (i != SEG_COUNT - 1) {
+ addr.append('.');
}
}
+ result.add(addr.toString());
+ }
+ return;
+ }
+ // last index and no 4 segments
+ if (segStart == s.length()) {
+ return;
+ }
+ // start with a zero
+ if (s.charAt(segStart) == '0') {
+ segments[segId] = 0;
+ dfs(s, segId + 1, segStart + 1);
+ return;
+ }
+ int addr = 0;
+ for (int index = segStart; index < s.length(); index++) {
+ addr = addr * 10 + s.charAt(index) - '0';
+ if (addr >= 0 && addr <= 255) {
+ segments[segId] = addr;
+ dfs(s, segId + 1, index + 1);
+ } else {
+ break;
}
}
}
diff --git a/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java b/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java
index 8020f22bc..d890bed30 100644
--- a/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java
+++ b/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.java
@@ -2,7 +2,7 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree
// #Stack #Data_Structure_I_Day_10_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
-// #2022_06_21_Time_0_ms_(100.00%)_Space_42.7_MB_(9.33%)
+// #2024_11_13_Time_0_ms_(100.00%)_Space_41.6_MB_(47.93%)
import com_github_leetcode.TreeNode;
import java.util.ArrayList;
diff --git a/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md b/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md
index 5068d014f..87e8d704a 100644
--- a/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md
+++ b/src/main/java/g0001_0100/s0094_binary_tree_inorder_traversal/readme.md
@@ -6,43 +6,81 @@ Given the `root` of a binary tree, return _the inorder traversal of its nodes' v
**Example 1:**
-
-
**Input:** root = [1,null,2,3]
-**Output:** [1,3,2]
-
-**Example 2:**
+**Output:** [1,3,2]
-**Input:** root = []
+**Explanation:**
-**Output:** []
+
-**Example 3:**
+**Example 2:**
-**Input:** root = [1]
+**Input:** root = [1,2,3,4,5,null,8,null,null,6,7,9]
-**Output:** [1]
+**Output:** [4,2,6,5,7,1,3,9,8]
-**Example 4:**
+**Explanation:**
-
+
-**Input:** root = [1,2]
+**Example 3:**
-**Output:** [2,1]
+**Input:** root = []
-**Example 5:**
+**Output:** []
-
+**Example 4:**
-**Input:** root = [1,null,2]
+**Input:** root = [1]
-**Output:** [1,2]
+**Output:** [1]
**Constraints:**
* The number of nodes in the tree is in the range `[0, 100]`.
* `-100 <= Node.val <= 100`
-**Follow up:** Recursive solution is trivial, could you do it iteratively?
\ No newline at end of file
+**Follow up:** Recursive solution is trivial, could you do it iteratively?
+
+To solve the "Binary Tree Inorder Traversal" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `inorderTraversal` in the `Solution` class that takes the root of a binary tree as input and returns the inorder traversal of its nodes' values.
+2. Implement an iterative algorithm to perform inorder traversal:
+ - Initialize an empty list to store the inorder traversal result.
+ - Initialize a stack to track the nodes during traversal.
+ - Start with the root node and push it onto the stack.
+ - While the stack is not empty:
+ - Traverse down the left subtree by pushing all left child nodes onto the stack.
+ - Pop the top node from the stack and add its value to the traversal result list.
+ - Move to the right subtree of the popped node and repeat the process.
+ - Return the traversal result list.
+3. Return the inorder traversal result list.
+
+Here's the implementation of the `inorderTraversal` method in Java:
+
+```java
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+class Solution {
+ public List inorderTraversal(TreeNode root) {
+ List inorder = new ArrayList<>();
+ Stack stack = new Stack<>();
+ TreeNode curr = root;
+ while (curr != null || !stack.isEmpty()) {
+ while (curr != null) {
+ stack.push(curr);
+ curr = curr.left;
+ }
+ curr = stack.pop();
+ inorder.add(curr.val);
+ curr = curr.right;
+ }
+ return inorder;
+ }
+}
+```
+
+This implementation performs an iterative inorder traversal of the binary tree using a stack, with a time complexity of O(N), where N is the number of nodes in the tree.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java b/src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java
index 7ba53c2e0..6d65005d7 100644
--- a/src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java
+++ b/src/main/java/g0001_0100/s0096_unique_binary_search_trees/Solution.java
@@ -1,8 +1,8 @@
package g0001_0100.s0096_unique_binary_search_trees;
-// #Medium #Top_100_Liked_Questions #Dynamic_Programming #Math #Tree #Binary_Tree
-// #Binary_Search_Tree #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1)
-// #2022_06_21_Time_0_ms_(100.00%)_Space_40.4_MB_(72.43%)
+// #Medium #Dynamic_Programming #Math #Tree #Binary_Tree #Binary_Search_Tree
+// #Dynamic_Programming_I_Day_11 #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_13_Time_0_ms_(100.00%)_Space_40.7_MB_(6.57%)
public class Solution {
public int numTrees(int n) {
diff --git a/src/main/java/g0001_0100/s0096_unique_binary_search_trees/readme.md b/src/main/java/g0001_0100/s0096_unique_binary_search_trees/readme.md
index de6a28687..2119633ad 100644
--- a/src/main/java/g0001_0100/s0096_unique_binary_search_trees/readme.md
+++ b/src/main/java/g0001_0100/s0096_unique_binary_search_trees/readme.md
@@ -20,4 +20,34 @@ Given an integer `n`, return _the number of structurally unique **BST'**s (binar
**Constraints:**
-* `1 <= n <= 19`
\ No newline at end of file
+* `1 <= n <= 19`
+
+To solve the "Unique Binary Search Trees" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `numTrees` in the `Solution` class that takes an integer `n` as input and returns the number of structurally unique BSTs (binary search trees) with exactly `n` nodes.
+2. Implement a dynamic programming approach to solve the problem:
+ - Create an array `dp` of size `n + 1` to store the number of unique BSTs for each number of nodes from 0 to `n`.
+ - Initialize `dp[0] = 1` and `dp[1] = 1`, as there is only one unique BST for 0 and 1 node(s).
+ - Use a nested loop to calculate `dp[i]` for each `i` from 2 to `n`.
+ - For each `i`, calculate `dp[i]` by summing up the products of `dp[j]` and `dp[i - j - 1]` for all possible values of `j` from 0 to `i - 1`.
+ - Return `dp[n]`, which represents the number of unique BSTs with `n` nodes.
+
+Here's the implementation of the `numTrees` method in Java:
+
+```java
+class Solution {
+ public int numTrees(int n) {
+ int[] dp = new int[n + 1];
+ dp[0] = 1;
+ dp[1] = 1;
+ for (int i = 2; i <= n; i++) {
+ for (int j = 0; j < i; j++) {
+ dp[i] += dp[j] * dp[i - j - 1];
+ }
+ }
+ return dp[n];
+ }
+}
+```
+
+This implementation uses dynamic programming to compute the number of structurally unique BSTs with `n` nodes in O(n^2) time complexity.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0097_interleaving_string/Solution.java b/src/main/java/g0001_0100/s0097_interleaving_string/Solution.java
index 75c5697f9..8f91248bd 100644
--- a/src/main/java/g0001_0100/s0097_interleaving_string/Solution.java
+++ b/src/main/java/g0001_0100/s0097_interleaving_string/Solution.java
@@ -1,6 +1,7 @@
package g0001_0100.s0097_interleaving_string;
-// #Medium #String #Dynamic_Programming #2022_06_21_Time_2_ms_(88.01%)_Space_42.1_MB_(73.59%)
+// #Medium #String #Dynamic_Programming #Top_Interview_150_Multidimensional_DP
+// #2025_03_05_Time_0_ms_(100.00%)_Space_42.24_MB_(22.76%)
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
diff --git a/src/main/java/g0001_0100/s0097_interleaving_string/readme.md b/src/main/java/g0001_0100/s0097_interleaving_string/readme.md
index 613d1d5ed..66eac61ec 100644
--- a/src/main/java/g0001_0100/s0097_interleaving_string/readme.md
+++ b/src/main/java/g0001_0100/s0097_interleaving_string/readme.md
@@ -4,7 +4,7 @@ Medium
Given strings `s1`, `s2`, and `s3`, find whether `s3` is formed by an **interleaving** of `s1` and `s2`.
-An **interleaving** of two strings `s` and `t` is a configuration where they are divided into **non-empty** substrings such that:
+An **interleaving** of two strings `s` and `t` is a configuration where `s` and `t` are divided into `n` and `m` **substring** respectively, such that:
* s = s1 + s2 + ... + sn
* t = t1 + t2 + ... + tm
@@ -19,13 +19,17 @@ An **interleaving** of two strings `s` and `t` is a configuration where they are
**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
-**Output:** true
+**Output:** true
+
+**Explanation:** One way to obtain s3 is: Split s1 into s1 = "aa" + "bc" + "c", and s2 into s2 = "dbbc" + "a". Interleaving the two splits, we get "aa" + "dbbc" + "bc" + "a" + "c" = "aadbbcbcac". Since s3 can be obtained by interleaving s1 and s2, we return true.
**Example 2:**
**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
-**Output:** false
+**Output:** false
+
+**Explanation:** Notice how it is impossible to interleave s2 with any other string to obtain s3.
**Example 3:**
diff --git a/src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java b/src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java
index ff8d54d1d..bd39431de 100644
--- a/src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java
+++ b/src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java
@@ -2,8 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree
// #Binary_Search_Tree #Data_Structure_I_Day_14_Tree #Level_1_Day_8_Binary_Search_Tree
-// #Udemy_Tree_Stack_Queue #Big_O_Time_O(N)_Space_O(log(N))
-// #2022_06_21_Time_0_ms_(100.00%)_Space_43.4_MB_(72.88%)
+// #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(N)_Space_O(log(N))
+// #2024_11_13_Time_0_ms_(100.00%)_Space_42.9_MB_(95.84%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0001_0100/s0098_validate_binary_search_tree/readme.md b/src/main/java/g0001_0100/s0098_validate_binary_search_tree/readme.md
index a65734a4c..3ca83ba09 100644
--- a/src/main/java/g0001_0100/s0098_validate_binary_search_tree/readme.md
+++ b/src/main/java/g0001_0100/s0098_validate_binary_search_tree/readme.md
@@ -6,8 +6,8 @@ Given the `root` of a binary tree, _determine if it is a valid binary search tre
A **valid BST** is defined as follows:
-* The left subtree of a node contains only nodes with keys **less than** the node's key.
-* The right subtree of a node contains only nodes with keys **greater than** the node's key.
+* The left subtree of a node contains only nodes with keys **strictly less than** the node's key.
+* The right subtree of a node contains only nodes with keys **strictly greater than** the node's key.
* Both the left and right subtrees must also be binary search trees.
**Example 1:**
@@ -31,4 +31,41 @@ A **valid BST** is defined as follows:
**Constraints:**
* The number of nodes in the tree is in the range [1, 104].
-* -231 <= Node.val <= 231 - 1
\ No newline at end of file
+* -231 <= Node.val <= 231 - 1
+
+To solve the "Validate Binary Search Tree" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `isValidBST` in the `Solution` class that takes the root of a binary tree as input and returns true if the tree is a valid binary search tree (BST), and false otherwise.
+2. Implement a recursive approach to validate if the given binary tree is a valid BST:
+ - Define a helper method `isValidBSTHelper` that takes the root node, a lower bound, and an upper bound as input parameters.
+ - In the `isValidBSTHelper` method, recursively traverse the binary tree nodes.
+ - At each node, check if its value is within the specified bounds (lower bound and upper bound) for a valid BST.
+ - If the node's value violates the BST property, return false.
+ - Otherwise, recursively validate the left and right subtrees by updating the bounds accordingly.
+ - If both the left and right subtrees are valid BSTs, return true.
+3. Call the `isValidBSTHelper` method with the root node and appropriate initial bounds to start the validation process.
+
+Here's the implementation of the `isValidBST` method in Java:
+
+```java
+class Solution {
+ public boolean isValidBST(TreeNode root) {
+ return isValidBSTHelper(root, null, null);
+ }
+
+ private boolean isValidBSTHelper(TreeNode node, Integer lower, Integer upper) {
+ if (node == null) {
+ return true;
+ }
+
+ int val = node.val;
+ if ((lower != null && val <= lower) || (upper != null && val >= upper)) {
+ return false;
+ }
+
+ return isValidBSTHelper(node.left, lower, val) && isValidBSTHelper(node.right, val, upper);
+ }
+}
+```
+
+This implementation recursively validates whether the given binary tree is a valid BST in O(n) time complexity, where n is the number of nodes in the tree.
\ No newline at end of file
diff --git a/src/main/java/g0001_0100/s0100_same_tree/Solution.java b/src/main/java/g0001_0100/s0100_same_tree/Solution.java
index 914fe4b54..6e359802e 100644
--- a/src/main/java/g0001_0100/s0100_same_tree/Solution.java
+++ b/src/main/java/g0001_0100/s0100_same_tree/Solution.java
@@ -1,7 +1,8 @@
package g0001_0100.s0100_same_tree;
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Level_2_Day_15_Tree
-// #Udemy_Tree_Stack_Queue #2022_06_21_Time_0_ms_(100.00%)_Space_40.9_MB_(78.42%)
+// #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General
+// #2022_06_21_Time_0_ms_(100.00%)_Space_40.9_MB_(78.42%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java b/src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java
index 023e1fbff..63523bd63 100644
--- a/src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java
+++ b/src/main/java/g0101_0200/s0101_symmetric_tree/Solution.java
@@ -2,7 +2,8 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search
// #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree #Level_2_Day_15_Tree
-// #Big_O_Time_O(N)_Space_O(log(N)) #2022_06_22_Time_0_ms_(100.00%)_Space_42.3_MB_(46.67%)
+// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(log(N))
+// #2024_11_13_Time_0_ms_(100.00%)_Space_41.4_MB_(83.38%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0101_symmetric_tree/readme.md b/src/main/java/g0101_0200/s0101_symmetric_tree/readme.md
index bd978643e..67d1bf168 100644
--- a/src/main/java/g0101_0200/s0101_symmetric_tree/readme.md
+++ b/src/main/java/g0101_0200/s0101_symmetric_tree/readme.md
@@ -25,4 +25,39 @@ Given the `root` of a binary tree, _check whether it is a mirror of itself_ (i.e
* The number of nodes in the tree is in the range `[1, 1000]`.
* `-100 <= Node.val <= 100`
-**Follow up:** Could you solve it both recursively and iteratively?
\ No newline at end of file
+**Follow up:** Could you solve it both recursively and iteratively?
+
+To solve the "Symmetric Tree" problem in Java with the Solution class, follow these steps:
+
+1. Define a method `isSymmetric` in the `Solution` class that takes the root of a binary tree as input and returns true if the tree is symmetric, and false otherwise.
+2. Implement a recursive approach to check if the given binary tree is symmetric:
+ - Define a helper method `isMirror` that takes two tree nodes as input parameters.
+ - In the `isMirror` method, recursively compare the left and right subtrees of the given nodes.
+ - At each step, check if the values of the corresponding nodes are equal and if the left subtree of one node is a mirror image of the right subtree of the other node.
+ - If both conditions are satisfied for all corresponding nodes, return true; otherwise, return false.
+3. Call the `isMirror` method with the root's left and right children to check if the entire tree is symmetric.
+
+Here's the implementation of the `isSymmetric` method in Java:
+
+```java
+class Solution {
+ public boolean isSymmetric(TreeNode root) {
+ if (root == null) {
+ return true;
+ }
+ return isMirror(root.left, root.right);
+ }
+
+ private boolean isMirror(TreeNode left, TreeNode right) {
+ if (left == null && right == null) {
+ return true;
+ }
+ if (left == null || right == null) {
+ return false;
+ }
+ return (left.val == right.val) && isMirror(left.left, right.right) && isMirror(left.right, right.left);
+ }
+}
+```
+
+This implementation recursively checks whether the given binary tree is symmetric around its center in O(n) time complexity, where n is the number of nodes in the tree.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java b/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java
index a91f3795a..ef25e9e90 100644
--- a/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java
+++ b/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java
@@ -2,7 +2,8 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Breadth_First_Search #Tree
// #Binary_Tree #Data_Structure_I_Day_11_Tree #Level_1_Day_6_Tree #Udemy_Tree_Stack_Queue
-// #Big_O_Time_O(N)_Space_O(N) #2022_06_22_Time_1_ms_(91.09%)_Space_43.6_MB_(42.50%)
+// #Top_Interview_150_Binary_Tree_BFS #Big_O_Time_O(N)_Space_O(N)
+// #2024_11_13_Time_1_ms_(91.19%)_Space_45.1_MB_(24.35%)
import com_github_leetcode.TreeNode;
import java.util.ArrayList;
diff --git a/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/readme.md b/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/readme.md
index 92fe4a4e3..509970383 100644
--- a/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/readme.md
+++ b/src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/readme.md
@@ -27,4 +27,76 @@ Given the `root` of a binary tree, return _the level order traversal of its node
**Constraints:**
* The number of nodes in the tree is in the range `[0, 2000]`.
-* `-1000 <= Node.val <= 1000`
\ No newline at end of file
+* `-1000 <= Node.val <= 1000`
+
+To solve the "Binary Tree Level Order Traversal" problem in Java with a `Solution` class, we'll perform a breadth-first search (BFS) traversal of the binary tree. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `levelOrder` method**: This method takes the root node of the binary tree as input and returns the level order traversal of its nodes' values.
+
+3. **Initialize a queue**: Create a queue to store the nodes during BFS traversal.
+
+4. **Check for null root**: Check if the root is null. If it is, return an empty list.
+
+5. **Perform BFS traversal**: Enqueue the root node into the queue. While the queue is not empty:
+ - Dequeue the front node from the queue.
+ - Add the value of the dequeued node to the current level list.
+ - Enqueue the left and right children of the dequeued node if they exist.
+ - Move to the next level when all nodes in the current level are processed.
+
+6. **Return the result**: After the BFS traversal is complete, return the list containing the level order traversal of the binary tree.
+
+Here's the Java implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+class Solution {
+ public List> levelOrder(TreeNode root) {
+ List> result = new ArrayList<>(); // Initialize list to store level order traversal
+ if (root == null) return result; // Check for empty tree
+
+ Queue queue = new LinkedList<>(); // Initialize queue for BFS traversal
+ queue.offer(root); // Enqueue the root node
+
+ while (!queue.isEmpty()) {
+ int levelSize = queue.size(); // Get the number of nodes in the current level
+ List level = new ArrayList<>(); // Initialize list for the current level
+
+ for (int i = 0; i < levelSize; i++) {
+ TreeNode node = queue.poll(); // Dequeue the front node
+ level.add(node.val); // Add node value to the current level list
+
+ // Enqueue the left and right children if they exist
+ if (node.left != null) queue.offer(node.left);
+ if (node.right != null) queue.offer(node.right);
+ }
+
+ result.add(level); // Add the current level list to the result list
+ }
+
+ return result; // Return the level order traversal
+ }
+
+ // Definition for a TreeNode
+ public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode() {}
+ TreeNode(int val) { this.val = val; }
+ TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently computes the level order traversal of the binary tree in Java using BFS.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java b/src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java
index 844dc2e65..4ad49f980 100644
--- a/src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java
+++ b/src/main/java/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0103_binary_tree_zigzag_level_order_traversal;
// #Medium #Top_Interview_Questions #Breadth_First_Search #Tree #Binary_Tree
-// #Data_Structure_II_Day_15_Tree #Udemy_Tree_Stack_Queue
-// #2022_06_22_Time_1_ms_(95.00%)_Space_43.2_MB_(19.22%)
+// #Data_Structure_II_Day_15_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_BFS
+// #2025_03_05_Time_0_ms_(100.00%)_Space_42.68_MB_(7.11%)
import com_github_leetcode.TreeNode;
import java.util.ArrayList;
diff --git a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java
index cab658ff1..7f905b514 100644
--- a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java
+++ b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.java
@@ -1,9 +1,10 @@
package g0101_0200.s0104_maximum_depth_of_binary_tree;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search
-// #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree
+// #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS #Data_Structure_I_Day_11_Tree
// #Programming_Skills_I_Day_10_Linked_List_and_Tree #Udemy_Tree_Stack_Queue
-// #Big_O_Time_O(N)_Space_O(H) #2022_06_22_Time_0_ms_(100.00%)_Space_42.9_MB_(67.03%)
+// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(H)
+// #2024_11_13_Time_0_ms_(100.00%)_Space_42.2_MB_(88.11%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md
index 052ac0151..9d2b479c7 100644
--- a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md
+++ b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md
@@ -20,19 +20,49 @@ A binary tree's **maximum depth** is the number of nodes along the longest path
**Output:** 2
-**Example 3:**
-
-**Input:** root = []
-
-**Output:** 0
-
-**Example 4:**
-
-**Input:** root = [0]
-
-**Output:** 1
-
**Constraints:**
* The number of nodes in the tree is in the range [0, 104].
-* `-100 <= Node.val <= 100`
\ No newline at end of file
+* `-100 <= Node.val <= 100`
+
+To solve the "Maximum Depth of Binary Tree" problem in Java with a `Solution` class, we'll perform a depth-first search (DFS) traversal of the binary tree. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `maxDepth` method**: This method takes the root node of the binary tree as input and returns its maximum depth.
+
+3. **Check for null root**: Check if the root is null. If it is, return 0 as the depth.
+
+4. **Perform DFS traversal**: Recursively compute the depth of the left and right subtrees. The maximum depth of the binary tree is the maximum depth of its left and right subtrees, plus 1 for the current node.
+
+5. **Return the result**: After the DFS traversal is complete, return the maximum depth of the binary tree.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ public int maxDepth(TreeNode root) {
+ if (root == null) return 0; // Check for empty tree
+ int leftDepth = maxDepth(root.left); // Compute depth of left subtree
+ int rightDepth = maxDepth(root.right); // Compute depth of right subtree
+ return Math.max(leftDepth, rightDepth) + 1; // Return maximum depth of left and right subtrees, plus 1 for the current node
+ }
+
+ // Definition for a TreeNode
+ public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode() {}
+ TreeNode(int val) { this.val = val; }
+ TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently computes the maximum depth of the binary tree in Java using DFS traversal.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java b/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java
index 2e0d7da4a..9466a71c9 100644
--- a/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java
+++ b/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0105_construct_binary_tree_from_preorder_and_inorder_traversal;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Tree #Binary_Tree
-// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Big_O_Time_O(N)_Space_O(N)
-// #2022_06_22_Time_3_ms_(86.35%)_Space_45.2_MB_(14.09%)
+// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Top_Interview_150_Binary_Tree_General
+// #Big_O_Time_O(N)_Space_O(N) #2024_11_13_Time_1_ms_(96.33%)_Space_44.5_MB_(36.49%)
import com_github_leetcode.TreeNode;
import java.util.HashMap;
diff --git a/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md b/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
index fa4a8b4dc..ffa185d1f 100644
--- a/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
+++ b/src/main/java/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
@@ -26,4 +26,80 @@ Given two integer arrays `preorder` and `inorder` where `preorder` is the preord
* `preorder` and `inorder` consist of **unique** values.
* Each value of `inorder` also appears in `preorder`.
* `preorder` is **guaranteed** to be the preorder traversal of the tree.
-* `inorder` is **guaranteed** to be the inorder traversal of the tree.
\ No newline at end of file
+* `inorder` is **guaranteed** to be the inorder traversal of the tree.
+
+To solve the "Construct Binary Tree from Preorder and Inorder Traversal" problem in Java with a `Solution` class, we'll use a recursive approach. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `buildTree` method**: This method takes two integer arrays, `preorder` and `inorder`, as input and returns the constructed binary tree.
+
+3. **Check for empty arrays**: Check if either of the arrays `preorder` or `inorder` is empty. If so, return null, as there's no tree to construct.
+
+4. **Define a helper method**: Define a recursive helper method `build` to construct the binary tree.
+ - The method should take the indices representing the current subtree in both `preorder` and `inorder`.
+ - The start and end indices in `preorder` represent the current subtree's preorder traversal.
+ - The start and end indices in `inorder` represent the current subtree's inorder traversal.
+
+5. **Base case**: If the start index of `preorder` is greater than the end index or if the start index of `inorder` is greater than the end index, return null.
+
+6. **Find the root node**: The root node is the first element in the `preorder` array.
+
+7. **Find the root's position in `inorder`**: Iterate through the `inorder` array to find the root's position.
+
+8. **Recursively build left and right subtrees**:
+ - Recursively call the `build` method for the left subtree with updated indices.
+ - Recursively call the `build` method for the right subtree with updated indices.
+
+9. **Return the root node**: After constructing the left and right subtrees, return the root node.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ public TreeNode buildTree(int[] preorder, int[] inorder) {
+ if (preorder.length == 0 || inorder.length == 0) return null; // Check for empty arrays
+ return build(preorder, inorder, 0, preorder.length - 1, 0, inorder.length - 1); // Construct binary tree
+ }
+
+ // Recursive helper method to construct binary tree
+ private TreeNode build(int[] preorder, int[] inorder, int preStart, int preEnd, int inStart, int inEnd) {
+ if (preStart > preEnd || inStart > inEnd) return null; // Base case
+
+ int rootValue = preorder[preStart]; // Root node value
+ TreeNode root = new TreeNode(rootValue); // Create root node
+
+ // Find root node's position in inorder array
+ int rootIndex = 0;
+ for (int i = inStart; i <= inEnd; i++) {
+ if (inorder[i] == rootValue) {
+ rootIndex = i;
+ break;
+ }
+ }
+
+ // Recursively build left and right subtrees
+ root.left = build(preorder, inorder, preStart + 1, preStart + rootIndex - inStart, inStart, rootIndex - 1);
+ root.right = build(preorder, inorder, preStart + rootIndex - inStart + 1, preEnd, rootIndex + 1, inEnd);
+
+ return root; // Return root node
+ }
+
+ // TreeNode definition
+ public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode() {}
+ TreeNode(int val) { this.val = val; }
+ TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently constructs the binary tree from preorder and inorder traversals in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.java b/src/main/java/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.java
index f29d60d79..2ad42311f 100644
--- a/src/main/java/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.java
+++ b/src/main/java/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0106_construct_binary_tree_from_inorder_and_postorder_traversal;
// #Medium #Array #Hash_Table #Tree #Binary_Tree #Divide_and_Conquer
-// #2022_06_22_Time_1_ms_(100.00%)_Space_44.7_MB_(28.54%)
+// #Top_Interview_150_Binary_Tree_General #2025_03_05_Time_0_ms_(100.00%)_Space_45.01_MB_(8.73%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java
index 56268a1cf..772b91185 100644
--- a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java
+++ b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution.java
@@ -1,8 +1,9 @@
package g0101_0200.s0108_convert_sorted_array_to_binary_search_tree;
-// #Easy #Top_Interview_Questions #Array #Tree #Binary_Tree #Binary_Search_Tree #Divide_and_Conquer
-// #Data_Structure_II_Day_15_Tree #Level_2_Day_9_Binary_Search_Tree #Udemy_Tree_Stack_Queue
-// #2022_06_22_Time_0_ms_(100.00%)_Space_43.9_MB_(32.26%)
+// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Tree #Binary_Tree
+// #Binary_Search_Tree #Divide_and_Conquer #Data_Structure_II_Day_15_Tree
+// #Level_2_Day_9_Binary_Search_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Divide_and_Conquer
+// #2025_03_05_Time_0_ms_(100.00%)_Space_43.75_MB_(11.21%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md
index c5c6a1ef7..07e88db26 100644
--- a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md
+++ b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md
@@ -2,9 +2,7 @@
Easy
-Given an integer array `nums` where the elements are sorted in **ascending order**, convert _it to a **height-balanced** binary search tree_.
-
-A **height-balanced** binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.
+Given an integer array `nums` where the elements are sorted in **ascending order**, convert _it to a_ **_height-balanced_** _binary search tree_.
**Example 1:**
@@ -24,7 +22,7 @@ A **height-balanced** binary tree is a binary tree in which the depth of the two
**Output:** [3,1]
-**Explanation:** [1,3] and [3,1] are both a height-balanced BSTs.
+**Explanation:** [1,null,3] and [3,1] are both height-balanced BSTs.
**Constraints:**
diff --git a/src/main/java/g0101_0200/s0112_path_sum/Solution.java b/src/main/java/g0101_0200/s0112_path_sum/Solution.java
index 98cd2ccdc..e5a3b4530 100644
--- a/src/main/java/g0101_0200/s0112_path_sum/Solution.java
+++ b/src/main/java/g0101_0200/s0112_path_sum/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0112_path_sum;
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Data_Structure_I_Day_12_Tree
-// #2022_06_23_Time_0_ms_(100.00%)_Space_43.8_MB_(36.11%)
+// #Top_Interview_150_Binary_Tree_General #2025_03_06_Time_0_ms_(100.00%)_Space_43.07_MB_(76.46%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0112_path_sum/readme.md b/src/main/java/g0101_0200/s0112_path_sum/readme.md
index 9402da46f..45f3df1e8 100644
--- a/src/main/java/g0101_0200/s0112_path_sum/readme.md
+++ b/src/main/java/g0101_0200/s0112_path_sum/readme.md
@@ -12,7 +12,9 @@ A **leaf** is a node with no children.
**Input:** root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
-**Output:** true
+**Output:** true
+
+**Explanation:** The root-to-leaf path with the target sum is shown.
**Example 2:**
@@ -20,13 +22,17 @@ A **leaf** is a node with no children.
**Input:** root = [1,2,3], targetSum = 5
-**Output:** false
+**Output:** false
+
+**Explanation:** There are two root-to-leaf paths in the tree: (1 --> 2): The sum is 3. (1 --> 3): The sum is 4. There is no root-to-leaf path with sum = 5.
**Example 3:**
-**Input:** root = [1,2], targetSum = 0
+**Input:** root = [], targetSum = 0
+
+**Output:** false
-**Output:** false
+**Explanation:** Since the tree is empty, there are no root-to-leaf paths.
**Constraints:**
diff --git a/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java b/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java
index b9059ce7b..8222f92ac 100644
--- a/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java
+++ b/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0114_flatten_binary_tree_to_linked_list;
// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List
-// #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(N)
-// #2022_06_23_Time_1_ms_(75.27%)_Space_42.8_MB_(36.48%)
+// #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N)
+// #2024_11_13_Time_0_ms_(100.00%)_Space_42.5_MB_(6.71%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/readme.md b/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/readme.md
index ea101ac1f..1cc08892d 100644
--- a/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/readme.md
+++ b/src/main/java/g0101_0200/s0114_flatten_binary_tree_to_linked_list/readme.md
@@ -32,4 +32,81 @@ Given the `root` of a binary tree, flatten the tree into a "linked list":
* The number of nodes in the tree is in the range `[0, 2000]`.
* `-100 <= Node.val <= 100`
-**Follow up:** Can you flatten the tree in-place (with `O(1)` extra space)?
\ No newline at end of file
+**Follow up:** Can you flatten the tree in-place (with `O(1)` extra space)?
+
+To solve the "Flatten Binary Tree to Linked List" problem in Java with a `Solution` class, we'll use a recursive approach. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `flatten` method**: This method takes the root node of the binary tree as input and flattens the tree into a linked list using preorder traversal.
+
+3. **Check for null root**: Check if the root is null. If so, there's no tree to flatten, so return.
+
+4. **Recursively flatten the tree**: Define a recursive helper method `flattenTree` to perform the flattening.
+ - The method should take the current node as input.
+ - Perform a preorder traversal of the tree.
+ - For each node, if it has a left child:
+ - Find the rightmost node in the left subtree.
+ - Attach the right subtree of the current node to the right of the rightmost node.
+ - Move the left subtree to the right subtree position.
+ - Set the left child of the current node to null.
+ - Recursively call the method for the right child.
+
+5. **Call the helper method**: Call the `flattenTree` method with the root node.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ public void flatten(TreeNode root) {
+ if (root == null) return; // Check for empty tree
+ flattenTree(root); // Flatten the tree
+ }
+
+ // Recursive helper method to flatten the tree
+ private void flattenTree(TreeNode node) {
+ if (node == null) return;
+
+ // Flatten left subtree
+ flattenTree(node.left);
+
+ // Flatten right subtree
+ flattenTree(node.right);
+
+ // Save right subtree
+ TreeNode rightSubtree = node.right;
+
+ // Attach left subtree to the right of the current node
+ node.right = node.left;
+
+ // Set left child to null
+ node.left = null;
+
+ // Move to the rightmost node of the flattened left subtree
+ TreeNode current = node;
+ while (current.right != null) {
+ current = current.right;
+ }
+
+ // Attach the saved right subtree to the right of the rightmost node
+ current.right = rightSubtree;
+ }
+
+ // TreeNode definition
+ public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode() {}
+ TreeNode(int val) { this.val = val; }
+ TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently flattens the binary tree into a linked list using preorder traversal in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java b/src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java
index 34b2f9888..28f0196b5 100644
--- a/src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java
+++ b/src/main/java/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Linked_List
// #Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search
-// #2022_06_23_Time_0_ms_(100.00%)_Space_44.7_MB_(65.49%)
+// #Top_Interview_150_Binary_Tree_General #2025_03_06_Time_0_ms_(100.00%)_Space_44.12_MB_(80.39%)
import com_github_leetcode.left_right.Node;
diff --git a/src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java b/src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java
index bf524527d..71393fa4a 100644
--- a/src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java
+++ b/src/main/java/g0101_0200/s0118_pascals_triangle/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0118_pascals_triangle;
-// #Easy #Top_Interview_Questions #Array #Dynamic_Programming #Data_Structure_I_Day_4_Array
-// #Dynamic_Programming_I_Day_12 #Udemy_Dynamic_Programming
+// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
+// #Data_Structure_I_Day_4_Array #Dynamic_Programming_I_Day_12 #Udemy_Dynamic_Programming
// #2022_06_23_Time_1_ms_(67.08%)_Space_42.4_MB_(5.58%)
import java.util.ArrayList;
diff --git a/src/main/java/g0101_0200/s0120_triangle/Solution.java b/src/main/java/g0101_0200/s0120_triangle/Solution.java
index 062237b54..504fb0e8b 100644
--- a/src/main/java/g0101_0200/s0120_triangle/Solution.java
+++ b/src/main/java/g0101_0200/s0120_triangle/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0120_triangle;
// #Medium #Array #Dynamic_Programming #Algorithm_I_Day_12_Dynamic_Programming
-// #Dynamic_Programming_I_Day_13 #Udemy_Dynamic_Programming
-// #2022_06_23_Time_2_ms_(94.63%)_Space_44.2_MB_(36.02%)
+// #Dynamic_Programming_I_Day_13 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP
+// #2025_03_06_Time_1_ms_(99.79%)_Space_44.45_MB_(35.64%)
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/g0101_0200/s0120_triangle/readme.md b/src/main/java/g0101_0200/s0120_triangle/readme.md
index 3441abb92..7cdd71a90 100644
--- a/src/main/java/g0101_0200/s0120_triangle/readme.md
+++ b/src/main/java/g0101_0200/s0120_triangle/readme.md
@@ -19,7 +19,7 @@ For each step, you may move to an adjacent number of the row below. More formall
3 4
6 5 7
4 1 8 3
- The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
+ The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
**Example 2:**
@@ -34,4 +34,4 @@ For each step, you may move to an adjacent number of the row below. More formall
* `triangle[i].length == triangle[i - 1].length + 1`
* -104 <= triangle[i][j] <= 104
-**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle?
\ No newline at end of file
+**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle?
diff --git a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java
index 85278aa9f..51c31b846 100644
--- a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java
+++ b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java
@@ -2,7 +2,8 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays
-// #Big_O_Time_O(N)_Space_O(1) #2022_06_23_Time_1_ms_(100.00%)_Space_58.9_MB_(93.57%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1)
+// #2024_11_13_Time_1_ms_(99.78%)_Space_61.8_MB_(27.61%)
public class Solution {
public int maxProfit(int[] prices) {
diff --git a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md
index 6e22ccf57..63c9bcd4a 100644
--- a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md
+++ b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md
@@ -2,7 +2,7 @@
Easy
-You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
+You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day.
You want to maximize your profit by choosing a **single day** to buy one stock and choosing a **different day in the future** to sell that stock.
@@ -27,4 +27,42 @@ Return _the maximum profit you can achieve from this transaction_. If you cannot
**Constraints:**
* 1 <= prices.length <= 105
-* 0 <= prices[i] <= 104
\ No newline at end of file
+* 0 <= prices[i] <= 104
+
+To solve the "Best Time to Buy and Sell Stock" problem in Java with a `Solution` class, we'll use a greedy algorithm. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `maxProfit` method**: This method takes an array `prices` as input and returns the maximum profit that can be achieved by buying and selling the stock.
+
+3. **Initialize variables**: Initialize two variables, `minPrice` to store the minimum price seen so far and `maxProfit` to store the maximum profit seen so far. Initialize `maxProfit` to 0.
+
+4. **Iterate through the prices array**:
+ - For each price in the array:
+ - Update `minPrice` to the minimum of the current price and `minPrice`.
+ - Update `maxProfit` to the maximum of the current profit (price - `minPrice`) and `maxProfit`.
+
+5. **Return the maximum profit**: After iterating through the entire array, return `maxProfit`.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ public int maxProfit(int[] prices) {
+ if (prices == null || prices.length <= 1) return 0; // Check for empty array or single element
+
+ int minPrice = prices[0]; // Initialize minPrice to the first price
+ int maxProfit = 0; // Initialize maxProfit to 0
+
+ // Iterate through the prices array
+ for (int i = 1; i < prices.length; i++) {
+ minPrice = Math.min(minPrice, prices[i]); // Update minPrice
+ maxProfit = Math.max(maxProfit, prices[i] - minPrice); // Update maxProfit
+ }
+
+ return maxProfit; // Return the maximum profit
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently calculates the maximum profit that can be achieved by buying and selling the stock in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java
index 0f8742aa6..eadc495dd 100644
--- a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java
+++ b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/Solution.java
@@ -1,7 +1,8 @@
package g0101_0200.s0122_best_time_to_buy_and_sell_stock_ii;
// #Medium #Top_Interview_Questions #Array #Dynamic_Programming #Greedy #Dynamic_Programming_I_Day_7
-// #Udemy_Arrays #2022_06_23_Time_1_ms_(96.82%)_Space_44.7_MB_(25.11%)
+// #Udemy_Arrays #Top_Interview_150_Array/String
+// #2025_03_06_Time_1_ms_(76.91%)_Space_45.72_MB_(69.34%)
public class Solution {
public int maxProfit(int[] prices) {
diff --git a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md
index 4b9c0d017..c3e347de1 100644
--- a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md
+++ b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md
@@ -2,9 +2,9 @@
Medium
-You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
+You are given an integer array `prices` where `prices[i]` is the price of a given stock on the ith day.
-On each day, you may decide to buy and/or sell the stock. You can only hold **at most one** share of the stock at any time. However, you can buy it then immediately sell it on the **same day**.
+On each day, you may decide to buy and/or sell the stock. You can only hold **at most one** share of the stock at any time. However, you can sell and buy the stock multiple times on the **same day**, ensuring you never hold more than one share of the stock.
Find and return _the **maximum** profit you can achieve_.
diff --git a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/Solution.java b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/Solution.java
index 07d99ccdb..df1849728 100644
--- a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/Solution.java
+++ b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/Solution.java
@@ -1,6 +1,7 @@
package g0101_0200.s0123_best_time_to_buy_and_sell_stock_iii;
-// #Hard #Array #Dynamic_Programming #2022_06_23_Time_4_ms_(87.18%)_Space_78.4_MB_(61.70%)
+// #Hard #Array #Dynamic_Programming #Top_Interview_150_Multidimensional_DP
+// #2025_03_06_Time_4_ms_(74.67%)_Space_61.08_MB_(72.04%)
public class Solution {
public int maxProfit(int[] prices) {
diff --git a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md
index d70274771..ae6eeba33 100644
--- a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md
+++ b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md
@@ -2,7 +2,7 @@
Hard
-You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
+You are given an array `prices` where `prices[i]` is the price of a given stock on the ith day.
Find the maximum profit you can achieve. You may complete **at most two transactions**.
@@ -32,12 +32,6 @@ Find the maximum profit you can achieve. You may complete **at most two transact
**Explanation:** In this case, no transaction is done, i.e. max profit = 0.
-**Example 4:**
-
-**Input:** prices = [1]
-
-**Output:** 0
-
**Constraints:**
* 1 <= prices.length <= 105
diff --git a/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java b/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java
index 733efe1f4..9e5bae4ad 100644
--- a/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java
+++ b/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0124_binary_tree_maximum_path_sum;
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search
-// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(N)_Space_O(N)
-// #2022_06_23_Time_1_ms_(99.46%)_Space_47.2_MB_(77.68%)
+// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General
+// #Big_O_Time_O(N)_Space_O(N) #2024_11_13_Time_0_ms_(100.00%)_Space_44.4_MB_(29.91%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/readme.md b/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/readme.md
index 29f9180b2..15f9fe527 100644
--- a/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/readme.md
+++ b/src/main/java/g0101_0200/s0124_binary_tree_maximum_path_sum/readme.md
@@ -31,4 +31,76 @@ Given the `root` of a binary tree, return _the maximum **path sum** of any **non
**Constraints:**
* The number of nodes in the tree is in the range [1, 3 * 104].
-* `-1000 <= Node.val <= 1000`
\ No newline at end of file
+* `-1000 <= Node.val <= 1000`
+
+To solve the "Binary Tree Maximum Path Sum" problem in Java with a `Solution` class, we'll use a recursive approach. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `maxPathSum` method**: This method takes the root node of the binary tree as input and returns the maximum path sum.
+
+3. **Define a recursive helper method**: Define a recursive helper method `maxSumPath` to compute the maximum path sum rooted at the current node.
+ - The method should return the maximum path sum that can be obtained from the current node to any of its descendants.
+ - We'll use a post-order traversal to traverse the tree.
+ - For each node:
+ - Compute the maximum path sum for the left and right subtrees recursively.
+ - Update the maximum path sum by considering three cases:
+ 1. The current node itself.
+ 2. The current node plus the maximum path sum of the left subtree.
+ 3. The current node plus the maximum path sum of the right subtree.
+ - Update the global maximum path sum if necessary by considering the sum of the current node, left subtree, and right subtree.
+
+4. **Initialize a variable to store the maximum path sum**: Initialize a global variable `maxSum` to store the maximum path sum.
+
+5. **Call the helper method**: Call the `maxSumPath` method with the root node.
+
+6. **Return the maximum path sum**: After traversing the entire tree, return the `maxSum`.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ int maxSum = Integer.MIN_VALUE; // Initialize global variable to store maximum path sum
+
+ public int maxPathSum(TreeNode root) {
+ maxSumPath(root);
+ return maxSum; // Return maximum path sum
+ }
+
+ // Recursive helper method to compute maximum path sum rooted at current node
+ private int maxSumPath(TreeNode node) {
+ if (node == null) return 0; // Base case
+
+ // Compute maximum path sum for left and right subtrees recursively
+ int leftSum = Math.max(maxSumPath(node.left), 0); // Ignore negative sums
+ int rightSum = Math.max(maxSumPath(node.right), 0); // Ignore negative sums
+
+ // Update maximum path sum by considering three cases:
+ // 1. Current node itself
+ // 2. Current node + maximum path sum of left subtree
+ // 3. Current node + maximum path sum of right subtree
+ int currentSum = node.val + leftSum + rightSum;
+ maxSum = Math.max(maxSum, currentSum); // Update global maximum path sum
+
+ // Return the maximum path sum that can be obtained from the current node to any of its descendants
+ return node.val + Math.max(leftSum, rightSum);
+ }
+
+ // Definition for a binary tree node
+ public class TreeNode {
+ int val;
+ TreeNode left;
+ TreeNode right;
+
+ TreeNode() {}
+ TreeNode(int val) { this.val = val; }
+ TreeNode(int val, TreeNode left, TreeNode right) {
+ this.val = val;
+ this.left = left;
+ this.right = right;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently computes the maximum path sum in a binary tree in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java b/src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java
index c293b7a11..2b5fc9154 100644
--- a/src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java
+++ b/src/main/java/g0101_0200/s0125_valid_palindrome/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0125_valid_palindrome;
// #Easy #Top_Interview_Questions #String #Two_Pointers #Udemy_Two_Pointers
-// #2022_06_23_Time_3_ms_(98.64%)_Space_43.2_MB_(81.23%)
+// #Top_Interview_150_Two_Pointers #2025_03_06_Time_2_ms_(99.11%)_Space_43.15_MB_(70.82%)
public class Solution {
public boolean isPalindrome(String s) {
diff --git a/src/main/java/g0101_0200/s0127_word_ladder/Solution.java b/src/main/java/g0101_0200/s0127_word_ladder/Solution.java
index 0d1482ded..379da5420 100644
--- a/src/main/java/g0101_0200/s0127_word_ladder/Solution.java
+++ b/src/main/java/g0101_0200/s0127_word_ladder/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0127_word_ladder;
// #Hard #Top_Interview_Questions #String #Hash_Table #Breadth_First_Search
-// #Graph_Theory_I_Day_12_Breadth_First_Search
-// #2022_06_23_Time_37_ms_(94.58%)_Space_54.1_MB_(66.08%)
+// #Graph_Theory_I_Day_12_Breadth_First_Search #Top_Interview_150_Graph_BFS
+// #2025_03_06_Time_22_ms_(96.00%)_Space_45.97_MB_(83.68%)
import java.util.HashSet;
import java.util.List;
diff --git a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/Solution.java b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/Solution.java
index 86bf4f5b2..8d8d6ba6c 100644
--- a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/Solution.java
+++ b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/Solution.java
@@ -1,7 +1,8 @@
package g0101_0200.s0128_longest_consecutive_sequence;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find
-// #Big_O_Time_O(N_log_N)_Space_O(1) #2022_06_23_Time_18_ms_(91.05%)_Space_64.8_MB_(63.58%)
+// #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1)
+// #2024_11_13_Time_14_ms_(98.89%)_Space_57.1_MB_(77.61%)
import java.util.Arrays;
diff --git a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md
index b5169398a..460a97646 100644
--- a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md
+++ b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md
@@ -20,7 +20,63 @@ You must write an algorithm that runs in `O(n)` time.
**Output:** 9
+**Example 3:**
+
+**Input:** nums = [1,0,1,2]
+
+**Output:** 3
+
**Constraints:**
* 0 <= nums.length <= 105
-* -109 <= nums[i] <= 109
\ No newline at end of file
+* -109 <= nums[i] <= 109
+
+To solve the "Longest Consecutive Sequence" problem in Java with a `Solution` class, we'll use a HashSet and a greedy approach. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `longestConsecutive` method**: This method takes an array `nums` as input and returns the length of the longest consecutive elements sequence.
+
+3. **Initialize a HashSet**: Create a HashSet named `numSet` to store all the numbers in the array `nums`.
+
+4. **Iterate through the array**: Add all the numbers from the array `nums` to the `numSet`.
+
+5. **Find the longest sequence**: Iterate through the array `nums` again. For each number `num` in the array:
+ - Check if `num - 1` exists in the `numSet`. If it does not, `num` could be the start of a new sequence.
+ - If `num - 1` does not exist, start a new sequence from `num`. Increment `currentNum` by 1 and check if `currentNum` exists in the `numSet`. Keep incrementing `currentNum` until it does not exist in the `numSet`. Update the maximum length of the sequence accordingly.
+
+6. **Return the maximum length**: After iterating through the entire array, return the maximum length of the consecutive sequence.
+
+Here's the Java implementation:
+
+```java
+import java.util.HashSet;
+
+class Solution {
+ public int longestConsecutive(int[] nums) {
+ HashSet numSet = new HashSet<>();
+ for (int num : nums) {
+ numSet.add(num); // Add all numbers to HashSet
+ }
+
+ int maxLength = 0;
+ for (int num : nums) {
+ if (!numSet.contains(num - 1)) { // Check if num - 1 exists in numSet
+ int currentNum = num;
+ int currentLength = 1;
+
+ while (numSet.contains(currentNum + 1)) { // Increment currentNum until it does not exist in numSet
+ currentNum++;
+ currentLength++;
+ }
+
+ maxLength = Math.max(maxLength, currentLength); // Update maximum length
+ }
+ }
+
+ return maxLength; // Return the maximum length of the consecutive sequence
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently calculates the length of the longest consecutive elements sequence in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0129_sum_root_to_leaf_numbers/Solution.java b/src/main/java/g0101_0200/s0129_sum_root_to_leaf_numbers/Solution.java
index c86c87efb..05e5d2c65 100644
--- a/src/main/java/g0101_0200/s0129_sum_root_to_leaf_numbers/Solution.java
+++ b/src/main/java/g0101_0200/s0129_sum_root_to_leaf_numbers/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0129_sum_root_to_leaf_numbers;
-// #Medium #Depth_First_Search #Tree #Binary_Tree
-// #2022_06_23_Time_0_ms_(100.00%)_Space_41.8_MB_(46.81%)
+// #Medium #Depth_First_Search #Tree #Binary_Tree #Top_Interview_150_Binary_Tree_General
+// #2025_03_06_Time_0_ms_(100.00%)_Space_41.47_MB_(30.87%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java b/src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java
index e2f2ad7bb..02b8a1a39 100644
--- a/src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java
+++ b/src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_Interview_Questions #Array #Depth_First_Search #Breadth_First_Search #Matrix
// #Union_Find #Algorithm_II_Day_8_Breadth_First_Search_Depth_First_Search
-// #2022_06_23_Time_2_ms_(84.66%)_Space_51.4_MB_(62.38%)
+// #Top_Interview_150_Graph_General #2022_06_23_Time_2_ms_(84.66%)_Space_51.4_MB_(62.38%)
public class Solution {
public void solve(char[][] board) {
diff --git a/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md b/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md
index 6b12aaacd..a0b0353b3 100644
--- a/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md
+++ b/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md
@@ -2,25 +2,31 @@
Medium
-Given an `m x n` matrix `board` containing `'X'` and `'O'`, _capture all regions that are 4-directionally surrounded by_ `'X'`.
+You are given an `m x n` matrix `board` containing **letters** `'X'` and `'O'`, **capture regions** that are **surrounded**:
-A region is **captured** by flipping all `'O'`s into `'X'`s in that surrounded region.
+* **Connect**: A cell is connected to adjacent cells horizontally or vertically.
+* **Region**: To form a region **connect every** `'O'` cell.
+* **Surround**: The region is surrounded with `'X'` cells if you can **connect the region** with `'X'` cells and none of the region cells are on the edge of the `board`.
-**Example 1:**
+To capture a **surrounded region**, replace all `'O'`s with `'X'`s **in-place** within the original board. You do not need to return anything.
-
+**Example 1:**
**Input:** board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
**Output:** [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
-**Explanation:** Surrounded regions should not be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.
+**Explanation:**
+
+
+
+In the above diagram, the bottom region is not captured because it is on the edge of the board and cannot be surrounded.
**Example 2:**
**Input:** board = [["X"]]
-**Output:** [["X"]]
+**Output:** [["X"]]
**Constraints:**
diff --git a/src/main/java/g0101_0200/s0131_palindrome_partitioning/Solution.java b/src/main/java/g0101_0200/s0131_palindrome_partitioning/Solution.java
index 10013003e..11b007c00 100644
--- a/src/main/java/g0101_0200/s0131_palindrome_partitioning/Solution.java
+++ b/src/main/java/g0101_0200/s0131_palindrome_partitioning/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
// #Backtracking #Big_O_Time_O(N*2^N)_Space_O(2^N*N)
-// #2022_06_24_Time_16_ms_(65.63%)_Space_194.3_MB_(37.65%)
+// #2024_11_13_Time_7_ms_(98.55%)_Space_56.9_MB_(57.45%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md b/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md
index 450d8798f..a2c2f7757 100644
--- a/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md
+++ b/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md
@@ -2,9 +2,7 @@
Medium
-Given a string `s`, partition `s` such that every substring of the partition is a **palindrome**. Return all possible palindrome partitioning of `s`.
-
-A **palindrome** string is a string that reads the same backward as forward.
+Given a string `s`, partition `s` such that every **substring** of the partition is a **palindrome**. Return _all possible palindrome partitioning of_ `s`.
**Example 1:**
@@ -21,4 +19,72 @@ A **palindrome** string is a string that reads the same backward as forward.
**Constraints:**
* `1 <= s.length <= 16`
-* `s` contains only lowercase English letters.
\ No newline at end of file
+* `s` contains only lowercase English letters.
+
+To solve the "Palindrome Partitioning" problem in Java with a `Solution` class, we'll use backtracking. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `partition` method**: This method takes a string `s` as input and returns all possible palindrome partitioning of `s`.
+
+3. **Define a recursive helper method**: Define a recursive helper method `backtrack` to find all possible palindrome partitions.
+ - The method should take the current index `start`, the current partition `partition`, and the list to store all partitions `result`.
+ - Base case: If `start` reaches the end of the string `s`, add the current partition to the result list and return.
+ - Iterate from `start` to the end of the string:
+ - Check if the substring from `start` to `i` is a palindrome.
+ - If it is a palindrome, add the substring to the current partition and recursively call the `backtrack` method with the updated index and partition.
+ - After the recursive call, remove the last substring added to the partition to backtrack and explore other partitions.
+
+4. **Initialize a list to store all partitions**: Create an ArrayList named `result` to store all possible palindrome partitions.
+
+5. **Call the helper method**: Call the `backtrack` method with the initial index, an empty partition list, and the result list.
+
+6. **Return the result list**: After exploring all possible partitions, return the list containing all palindrome partitions.
+
+Here's the Java implementation:
+
+```java
+import java.util.ArrayList;
+import java.util.List;
+
+class Solution {
+ public List> partition(String s) {
+ List> result = new ArrayList<>();
+ backtrack(s, 0, new ArrayList<>(), result);
+ return result;
+ }
+
+ // Recursive helper method to find all possible palindrome partitions
+ private void backtrack(String s, int start, List partition, List> result) {
+ if (start == s.length()) {
+ result.add(new ArrayList<>(partition));
+ return;
+ }
+
+ for (int i = start; i < s.length(); i++) {
+ String substring = s.substring(start, i + 1);
+ if (isPalindrome(substring)) {
+ partition.add(substring);
+ backtrack(s, i + 1, partition, result);
+ partition.remove(partition.size() - 1); // Backtrack
+ }
+ }
+ }
+
+ // Helper method to check if a string is a palindrome
+ private boolean isPalindrome(String s) {
+ int left = 0;
+ int right = s.length() - 1;
+ while (left < right) {
+ if (s.charAt(left) != s.charAt(right)) {
+ return false;
+ }
+ left++;
+ right--;
+ }
+ return true;
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently finds all possible palindrome partitions of the given string in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0133_clone_graph/Solution.java b/src/main/java/g0101_0200/s0133_clone_graph/Solution.java
index 987785ee9..65eec4eb6 100644
--- a/src/main/java/g0101_0200/s0133_clone_graph/Solution.java
+++ b/src/main/java/g0101_0200/s0133_clone_graph/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0133_clone_graph;
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Graph #Udemy_Graph
-// #2022_06_24_Time_45_ms_(29.80%)_Space_42.7_MB_(77.96%)
+// #Top_Interview_150_Graph_General #2025_05_03_Time_25_ms_(68.87%)_Space_43.26_MB_(7.02%)
import com_github_leetcode.Node;
import java.util.ArrayList;
diff --git a/src/main/java/g0101_0200/s0133_clone_graph/readme.md b/src/main/java/g0101_0200/s0133_clone_graph/readme.md
index 97ec33204..8e5cdbfd1 100644
--- a/src/main/java/g0101_0200/s0133_clone_graph/readme.md
+++ b/src/main/java/g0101_0200/s0133_clone_graph/readme.md
@@ -52,18 +52,10 @@ The given node will always be the first node with `val = 1`. You must return the
**Explanation:** This an empty graph, it does not have any nodes.
-**Example 4:**
-
-
-
-**Input:** adjList = [[2],[1]]
-
-**Output:** [[2],[1]]
-
**Constraints:**
* The number of nodes in the graph is in the range `[0, 100]`.
* `1 <= Node.val <= 100`
* `Node.val` is unique for each node.
* There are no repeated edges and no self-loops in the graph.
-* The Graph is connected and all nodes can be visited starting from the given node.
\ No newline at end of file
+* The Graph is connected and all nodes can be visited starting from the given node.
diff --git a/src/main/java/g0101_0200/s0134_gas_station/Solution.java b/src/main/java/g0101_0200/s0134_gas_station/Solution.java
index 804843add..b8d14f5c5 100644
--- a/src/main/java/g0101_0200/s0134_gas_station/Solution.java
+++ b/src/main/java/g0101_0200/s0134_gas_station/Solution.java
@@ -1,30 +1,22 @@
package g0101_0200.s0134_gas_station;
-// #Medium #Top_Interview_Questions #Array #Greedy
-// #2022_06_24_Time_2_ms_(94.26%)_Space_62.5_MB_(87.11%)
+// #Medium #Top_Interview_Questions #Array #Greedy #Top_Interview_150_Array/String
+// #2025_03_06_Time_2_ms_(97.52%)_Space_57.00_MB_(5.82%)
public class Solution {
public int canCompleteCircuit(int[] gas, int[] cost) {
- int sumGas = 0;
- int sumCost = 0;
- int curGas = 0;
- int result = -1;
+ int index = 0;
+ int total = 0;
+ int current = 0;
for (int i = 0; i < gas.length; i++) {
- curGas += gas[i] - cost[i];
- // re-calculate the starting point
- if (curGas < 0) {
- result = -1;
- curGas = 0;
- } else if (result == -1) {
- // set initial starting point
- result = i;
+ int balance = gas[i] - cost[i];
+ total += balance;
+ current += balance;
+ if (current < 0) {
+ index = i + 1;
+ current = 0;
}
- sumGas += gas[i];
- sumCost += cost[i];
}
- if (sumGas < sumCost) {
- return -1;
- }
- return result;
+ return total >= 0 ? index : -1;
}
}
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/s0135_candy/Solution.java b/src/main/java/g0101_0200/s0135_candy/Solution.java
index 41d862f9d..8c74f8bc0 100644
--- a/src/main/java/g0101_0200/s0135_candy/Solution.java
+++ b/src/main/java/g0101_0200/s0135_candy/Solution.java
@@ -1,6 +1,7 @@
package g0101_0200.s0135_candy;
-// #Hard #Array #Greedy #2022_06_24_Time_2_ms_(99.95%)_Space_42.8_MB_(94.28%)
+// #Hard #Array #Greedy #Top_Interview_150_Array/String
+// #2025_03_06_Time_3_ms_(83.95%)_Space_45.91_MB_(43.68%)
import java.util.Arrays;
diff --git a/src/main/java/g0101_0200/s0136_single_number/Solution.java b/src/main/java/g0101_0200/s0136_single_number/Solution.java
index fffa20123..e6b2f514e 100644
--- a/src/main/java/g0101_0200/s0136_single_number/Solution.java
+++ b/src/main/java/g0101_0200/s0136_single_number/Solution.java
@@ -1,8 +1,9 @@
package g0101_0200.s0136_single_number;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation
-// #Data_Structure_II_Day_1_Array #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers
-// #Big_O_Time_O(N)_Space_O(1) #2022_06_24_Time_1_ms_(99.97%)_Space_50.9_MB_(35.58%)
+// #LeetCode_75_Bit_Manipulation #Data_Structure_II_Day_1_Array
+// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers #Top_Interview_150_Bit_Manipulation
+// #Big_O_Time_O(N)_Space_O(1) #2024_11_13_Time_1_ms_(99.86%)_Space_46_MB_(49.33%)
public class Solution {
public int singleNumber(int[] nums) {
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 5f9d3dfca..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,22 +10,53 @@ 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:**
* 1 <= nums.length <= 3 * 104
* -3 * 104 <= nums[i] <= 3 * 104
-* Each element in the array appears twice except for one element which appears only once.
\ No newline at end of file
+* Each element in the array appears twice except for one element which appears only once.
+
+To solve the "Single Number" problem in Java with a `Solution` class, we'll use bitwise XOR operation. Below are the steps:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `singleNumber` method**: This method takes an array `nums` as input and returns the single number that appears only once.
+
+3. **Initialize a variable to store the result**: Initialize a variable `singleNumber` to 0.
+
+4. **Iterate through the array and perform bitwise XOR operation**: Iterate through the array `nums`. For each number `num` in the array, perform bitwise XOR operation with the `singleNumber`.
+
+5. **Return the result**: After iterating through the entire array, the `singleNumber` variable will store the single number that appears only once. Return `singleNumber`.
+
+Here's the Java implementation:
+
+```java
+class Solution {
+ public int singleNumber(int[] nums) {
+ int singleNumber = 0; // Initialize variable to store result
+
+ // Perform bitwise XOR operation on all elements in the array
+ for (int num : nums) {
+ singleNumber ^= num;
+ }
+
+ return singleNumber; // Return the single number
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently finds the single number that appears only once in the given array using bitwise XOR operation in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0137_single_number_ii/Solution.java b/src/main/java/g0101_0200/s0137_single_number_ii/Solution.java
index bd6cd3e45..425d90590 100644
--- a/src/main/java/g0101_0200/s0137_single_number_ii/Solution.java
+++ b/src/main/java/g0101_0200/s0137_single_number_ii/Solution.java
@@ -1,6 +1,7 @@
package g0101_0200.s0137_single_number_ii;
-// #Medium #Array #Bit_Manipulation #2022_06_24_Time_0_ms_(100.00%)_Space_42.1_MB_(84.59%)
+// #Medium #Array #Bit_Manipulation #Top_Interview_150_Bit_Manipulation
+// #2025_03_06_Time_0_ms_(100.00%)_Space_45.39_MB_(79.09%)
public class Solution {
public int singleNumber(int[] nums) {
diff --git a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java
index bf4be9fe8..32cb71404 100644
--- a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java
+++ b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/Solution.java
@@ -1,71 +1,42 @@
package g0101_0200.s0138_copy_list_with_random_pointer;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Linked_List
-// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(N)
-// #2022_06_24_Time_0_ms_(100.00%)_Space_45.5_MB_(56.49%)
+// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Top_Interview_150_Linked_List
+// #Big_O_Time_O(N)_Space_O(N) #2025_07_04_Time_0_ms_(100.00%)_Space_43.96_MB_(99.29%)
import com_github_leetcode.random.Node;
+import java.util.HashMap;
+import java.util.Map;
/*
// Definition for a Node.
class Node {
- public int val;
- public Node next;
- public Node random;
+ int val;
+ Node next;
+ Node random;
- public Node() {}
-
- public Node(int _val,Node _next,Node _random) {
- val = _val;
- next = _next;
- random = _random;
+ public Node(int val) {
+ this.val = val;
+ this.next = null;
+ this.random = null;
}
-};
+}
*/
public class Solution {
public Node copyRandomList(Node head) {
- if (head == null) {
- return null;
- }
- // first pass to have a clone node point to the next node. ie A->B becomes A->clonedNode->B
- Node curr = head;
- while (curr != null) {
- Node clonedNode = new Node(curr.val);
- clonedNode.next = curr.next;
- curr.next = clonedNode;
- curr = clonedNode.next;
- }
- curr = head;
- // second pass to make the cloned node's random pointer point to the orginal node's randome
- // pointer.
- // ie. A's random pointer becomes ClonedNode's random pointer
- while (curr != null) {
- if (curr.random != null) {
- curr.next.random = curr.random.next;
- } else {
- curr.next.random = null;
- }
- curr = curr.next.next;
+ Map hashMap = new HashMap<>();
+ Node cur = head;
+ while (cur != null) {
+ hashMap.put(cur, new Node(cur.val));
+ cur = cur.next;
}
- curr = head;
- // third pass to restore the links and return the head of the cloned nodes' list.
- Node newHead = null;
- while (curr != null) {
- Node clonedNode;
- if (newHead == null) {
- clonedNode = curr.next;
- newHead = clonedNode;
- } else {
- clonedNode = curr.next;
- }
- curr.next = clonedNode.next;
- if (curr.next != null) {
- clonedNode.next = curr.next.next;
- } else {
- clonedNode.next = null;
- }
- curr = curr.next;
+ cur = head;
+ while (cur != null) {
+ Node copy = hashMap.get(cur);
+ copy.next = hashMap.get(cur.next);
+ copy.random = hashMap.get(cur.random);
+ cur = cur.next;
}
- return newHead;
+ return hashMap.get(head);
}
}
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 9e2f93921..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,16 +41,72 @@ 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`
-* `Node.random` is `null` or is pointing to some node in the linked list.
\ No newline at end of file
+* -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:
+
+1. **Create a `Solution` class**: Define a class named `Solution` to encapsulate our solution methods.
+
+2. **Create a `copyRandomList` method**: This method takes the head node of the original linked list as input and returns the head node of the copied linked list.
+
+3. **Initialize a HashMap**: Create a HashMap named `nodeMap` to store the mapping between original nodes and their corresponding copied nodes.
+
+4. **Create a deep copy of the list**: Iterate through the original linked list and create a deep copy of each node. For each node `originalNode` in the original linked list:
+ - Create a new node `copyNode` with the same value as `originalNode`.
+ - Put the mapping between `originalNode` and `copyNode` in the `nodeMap`.
+ - Set the `copyNode`'s `next` and `random` pointers accordingly.
+ - Attach the `copyNode` to the copied linked list.
+
+5. **Return the head of the copied linked list**: After creating the deep copy of the entire list, return the head node of the copied linked list.
+
+Here's the Java implementation:
+
+```java
+import java.util.HashMap;
+import java.util.Map;
+
+class Solution {
+ public Node copyRandomList(Node head) {
+ if (head == null) return null; // Check for empty list
+
+ Map nodeMap = new HashMap<>(); // Initialize HashMap to store mapping between original and copied nodes
+
+ // Create a deep copy of each node in the list
+ Node current = head;
+ while (current != null) {
+ Node copyNode = new Node(current.val); // Create a new copy node
+ nodeMap.put(current, copyNode); // Put mapping between original and copied nodes in the map
+ current = current.next; // Move to the next node
+ }
+
+ // Set the next and random pointers of copied nodes
+ current = head;
+ while (current != null) {
+ Node copyNode = nodeMap.get(current); // Get copied node
+ copyNode.next = nodeMap.getOrDefault(current.next, null); // Set next pointer
+ copyNode.random = nodeMap.getOrDefault(current.random, null); // Set random pointer
+ current = current.next; // Move to the next node
+ }
+
+ return nodeMap.get(head); // Return the head of the copied linked list
+ }
+
+ // Definition for a Node
+ class Node {
+ int val;
+ Node next, random;
+
+ Node(int val) {
+ this.val = val;
+ this.next = null;
+ this.random = null;
+ }
+ }
+}
+```
+
+This implementation follows the steps outlined above and efficiently constructs a deep copy of the linked list with random pointers in Java.
\ No newline at end of file
diff --git a/src/main/java/g0101_0200/s0139_word_break/Solution.java b/src/main/java/g0101_0200/s0139_word_break/Solution.java
index 8f62cbf77..87ddce28b 100644
--- a/src/main/java/g0101_0200/s0139_word_break/Solution.java
+++ b/src/main/java/g0101_0200/s0139_word_break/Solution.java
@@ -2,44 +2,37 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
-// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Big_O_Time_O(M+max*N)_Space_O(M+N+max)
-// #2022_06_24_Time_2_ms_(97.08%)_Space_42.1_MB_(90.92%)
+// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
+// #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2024_11_15_Time_1_ms_(99.42%)_Space_42.1_MB_(80.42%)
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
public class Solution {
+ private Boolean[] memo;
+
public boolean wordBreak(String s, List wordDict) {
- Set set = new HashSet<>();
- int max = 0;
- boolean[] flag = new boolean[s.length() + 1];
- for (String st : wordDict) {
- set.add(st);
- if (max < st.length()) {
- max = st.length();
- }
- }
- for (int i = 1; i <= max; i++) {
- if (dfs(s, 0, i, max, set, flag)) {
- return true;
- }
- }
- return false;
+ memo = new Boolean[s.length() + 1];
+ return dp(s, 0, wordDict);
}
- private boolean dfs(String s, int start, int end, int max, Set set, boolean[] flag) {
- if (!flag[end] && set.contains(s.substring(start, end))) {
- flag[end] = true;
- if (end == s.length()) {
- return true;
+ public boolean dp(String s, int i, List wordDict) {
+ if (i == s.length()) {
+ return true;
+ }
+ if (memo[i] != null) {
+ return memo[i];
+ }
+ for (String word : wordDict) {
+ int len = word.length();
+ if (i + len > s.length() || !s.substring(i, i + len).equals(word)) {
+ continue;
}
- for (int i = 1; i <= max; i++) {
- if (end + i <= s.length() && dfs(s, end, end + i, max, set, flag)) {
- return true;
- }
+ if (dp(s, i + len, wordDict)) {
+ memo[i] = true;
+ return true;
}
}
+ memo[i] = false;
return false;
}
}
diff --git a/src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java b/src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java
index 72066f45f..3f12e2c4c 100644
--- a/src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java
+++ b/src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0141_linked_list_cycle;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
-// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
-// #2022_06_24_Time_0_ms_(100.00%)_Space_45.5_MB_(68.52%)
+// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
+// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_44.3_MB_(52.46%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java b/src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java
index 559cb953d..8bcdf03a9 100644
--- a/src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java
+++ b/src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List
// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List
-// #Big_O_Time_O(N)_Space_O(1) #2022_06_24_Time_0_ms_(100.00%)_Space_42.3_MB_(98.70%)
+// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_44.7_MB_(20.31%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java b/src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java
index 791b20209..c49c23aff 100644
--- a/src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java
+++ b/src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java
@@ -1,8 +1,8 @@
package g0101_0200.s0146_lru_cache;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List
-// #Doubly_Linked_List #Udemy_Linked_List #Big_O_Time_O(1)_Space_O(capacity)
-// #2022_06_24_Time_87_ms_(50.80%)_Space_125.2_MB_(58.73%)
+// #Doubly_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
+// #Big_O_Time_O(1)_Space_O(capacity) #2024_11_15_Time_40_ms_(98.20%)_Space_111.4_MB_(88.70%)
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/java/g0101_0200/s0148_sort_list/Solution.java b/src/main/java/g0101_0200/s0148_sort_list/Solution.java
index 2f6953f93..e9502d601 100644
--- a/src/main/java/g0101_0200/s0148_sort_list/Solution.java
+++ b/src/main/java/g0101_0200/s0148_sort_list/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0148_sort_list;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List
-// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Big_O_Time_O(log(N))_Space_O(log(N))
-// #2022_06_24_Time_12_ms_(85.82%)_Space_76_MB_(43.84%)
+// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Top_Interview_150_Divide_and_Conquer
+// #Big_O_Time_O(log(N))_Space_O(log(N)) #2024_11_15_Time_9_ms_(93.90%)_Space_56.9_MB_(37.47%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java b/src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java
index 108064340..2f9fb1b10 100644
--- a/src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java
+++ b/src/main/java/g0101_0200/s0149_max_points_on_a_line/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0149_max_points_on_a_line;
// #Hard #Top_Interview_Questions #Array #Hash_Table #Math #Geometry #Algorithm_II_Day_21_Others
-// #2022_06_24_Time_11_ms_(99.21%)_Space_41.5_MB_(95.53%)
+// #Top_Interview_150_Math #2025_03_06_Time_7_ms_(99.18%)_Space_41.70_MB_(81.57%)
public class Solution {
public int maxPoints(int[][] points) {
diff --git a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java
index 6da6dd087..dbfb67d90 100644
--- a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java
+++ b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0150_evaluate_reverse_polish_notation;
// #Medium #Top_Interview_Questions #Array #Math #Stack #Programming_Skills_II_Day_3
-// #2022_06_24_Time_9_ms_(51.23%)_Space_44.1_MB_(56.86%)
+// #Top_Interview_150_Stack #2025_03_06_Time_6_ms_(76.50%)_Space_44.94_MB_(31.04%)
import java.util.Stack;
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/Solution.java b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/Solution.java
index 54a6f3f11..f0824af7a 100644
--- a/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/Solution.java
+++ b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0151_reverse_words_in_a_string;
-// #Medium #String #Two_Pointers #Udemy_Strings
-// #2022_06_25_Time_2_ms_(99.94%)_Space_42.4_MB_(88.57%)
+// #Medium #String #Two_Pointers #LeetCode_75_Array/String #Udemy_Strings
+// #Top_Interview_150_Array/String #2025_03_06_Time_2_ms_(99.69%)_Space_42.48_MB_(97.99%)
public class Solution {
public String reverseWords(String s) {
@@ -17,7 +17,7 @@ public String reverseWords(String s) {
sb.append(s, start + 1, i + 1);
i = start - 1;
}
- if (sb.length() > 0) {
+ if (!sb.isEmpty()) {
sb.deleteCharAt(0);
}
return sb.toString();
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/Solution.java b/src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java
index f683ba42e..1e8f8c0c2 100644
--- a/src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java
+++ b/src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java
@@ -2,27 +2,25 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming
-// #Big_O_Time_O(N)_Space_O(1) #2022_06_25_Time_0_ms_(100.00%)_Space_42.7_MB_(82.46%)
+// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_1_ms_(92.74%)_Space_45_MB_(23.41%)
public class Solution {
- public int maxProduct(int[] arr) {
- int ans = Integer.MIN_VALUE;
- int cprod = 1;
- for (int j : arr) {
- cprod = cprod * j;
- ans = Math.max(ans, cprod);
- if (cprod == 0) {
- cprod = 1;
+ public int maxProduct(int[] nums) {
+ int overAllMaxProd = Integer.MIN_VALUE;
+ int n = nums.length;
+ int start = 1;
+ int end = 1;
+ for (int i = 0; i < n; i++) {
+ if (start == 0) {
+ start = 1;
}
- }
- cprod = 1;
- for (int i = arr.length - 1; i >= 0; i--) {
- cprod = cprod * arr[i];
- ans = Math.max(ans, cprod);
- if (cprod == 0) {
- cprod = 1;
+ if (end == 0) {
+ end = 1;
}
+ start = start * nums[i];
+ end = end * nums[n - i - 1];
+ overAllMaxProd = Math.max(overAllMaxProd, Math.max(start, end));
}
- return ans;
+ return overAllMaxProd;
}
}
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/Solution.java b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java
index 5f23c4d03..fd5144823 100644
--- a/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java
+++ b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0153_find_minimum_in_rotated_sorted_array;
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search
-// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Big_O_Time_O(log_N)_Space_O(log_N)
-// #2022_06_25_Time_0_ms_(100.00%)_Space_43.3_MB_(6.36%)
+// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Top_Interview_150_Binary_Search
+// #Big_O_Time_O(log_N)_Space_O(log_N) #2024_11_15_Time_0_ms_(100.00%)_Space_42.1_MB_(33.31%)
public class Solution {
private int findMinUtil(int[] nums, int l, int r) {
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/MinStack.java b/src/main/java/g0101_0200/s0155_min_stack/MinStack.java
index ebc36465e..8fb7bd0f3 100644
--- a/src/main/java/g0101_0200/s0155_min_stack/MinStack.java
+++ b/src/main/java/g0101_0200/s0155_min_stack/MinStack.java
@@ -1,8 +1,9 @@
package g0101_0200.s0155_min_stack;
-// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design
+// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design
// #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design
-// #Udemy_Design #Big_O_Time_O(1)_Space_O(N) #2022_06_25_Time_3_ms_(100.00%)_Space_44.3_MB_(85.39%)
+// #Udemy_Design #Top_Interview_150_Stack #Big_O_Time_O(1)_Space_O(N)
+// #2024_11_15_Time_4_ms_(96.54%)_Space_44.5_MB_(84.54%)
public class MinStack {
private static class Node {
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/Solution.java b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java
index 64ca25c2a..201d453e5 100644
--- a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java
+++ b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java
@@ -2,7 +2,7 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
// #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1)
-// #2022_06_25_Time_1_ms_(99.68%)_Space_55.1_MB_(63.42%)
+// #2024_11_15_Time_1_ms_(99.92%)_Space_48.4_MB_(68.45%)
import com_github_leetcode.ListNode;
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/Solution.java b/src/main/java/g0101_0200/s0162_find_peak_element/Solution.java
index b9aee1cc2..21ed18f7b 100644
--- a/src/main/java/g0101_0200/s0162_find_peak_element/Solution.java
+++ b/src/main/java/g0101_0200/s0162_find_peak_element/Solution.java
@@ -1,7 +1,8 @@
package g0101_0200.s0162_find_peak_element;
-// #Medium #Top_Interview_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search
-// #Binary_Search_II_Day_12 #2022_06_25_Time_0_ms_(100.00%)_Space_43.5_MB_(12.83%)
+// #Medium #Top_Interview_Questions #Array #Binary_Search #LeetCode_75_Binary_Search
+// #Algorithm_II_Day_2_Binary_Search #Binary_Search_II_Day_12 #Top_Interview_150_Binary_Search
+// #2025_03_06_Time_0_ms_(100.00%)_Space_42.78_MB_(21.39%)
public class Solution {
public int findPeakElement(int[] nums) {
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/s0164_maximum_gap/Solution.java b/src/main/java/g0101_0200/s0164_maximum_gap/Solution.java
index 40015e6ac..621534f90 100644
--- a/src/main/java/g0101_0200/s0164_maximum_gap/Solution.java
+++ b/src/main/java/g0101_0200/s0164_maximum_gap/Solution.java
@@ -1,6 +1,6 @@
package g0101_0200.s0164_maximum_gap;
-// #Hard #Array #Sorting #Bucket_Sort #Radix_Sort
+// #Medium #Array #Sorting #Bucket_Sort #Radix_Sort
// #2022_06_25_Time_48_ms_(53.59%)_Space_84.1_MB_(20.66%)
import java.util.Arrays;
diff --git a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java
index 44dcbedcb..6b95bd7a6 100644
--- a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java
+++ b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/Solution.java
@@ -1,7 +1,8 @@
package g0101_0200.s0167_two_sum_ii_input_array_is_sorted;
// #Medium #Array #Binary_Search #Two_Pointers #Algorithm_I_Day_3_Two_Pointers
-// #Binary_Search_I_Day_7 #2022_06_25_Time_1_ms_(99.21%)_Space_50.3_MB_(31.33%)
+// #Binary_Search_I_Day_7 #Top_Interview_150_Two_Pointers
+// #2025_03_09_Time_2_ms_(92.62%)_Space_47.15_MB_(64.95%)
public class Solution {
public int[] twoSum(int[] numbers, int target) {
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/Solution.java b/src/main/java/g0101_0200/s0169_majority_element/Solution.java
index 285f70e62..cbd2d081d 100644
--- a/src/main/java/g0101_0200/s0169_majority_element/Solution.java
+++ b/src/main/java/g0101_0200/s0169_majority_element/Solution.java
@@ -2,7 +2,8 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting #Counting
// #Divide_and_Conquer #Data_Structure_II_Day_1_Array #Udemy_Famous_Algorithm
-// #Big_O_Time_O(n)_Space_O(1) #2022_06_25_Time_1_ms_(100.00%)_Space_45.5_MB_(97.51%)
+// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_15_Time_1_ms_(99.89%)_Space_52.8_MB_(64.33%)
public class Solution {
public int majorityElement(int[] arr) {
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
diff --git a/src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java b/src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java
index 073613433..7a2435c10 100644
--- a/src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java
+++ b/src/main/java/g0101_0200/s0172_factorial_trailing_zeroes/Solution.java
@@ -1,7 +1,7 @@
package g0101_0200.s0172_factorial_trailing_zeroes;
-// #Medium #Top_Interview_Questions #Math #Udemy_Integers
-// #2022_06_26_Time_1_ms_(85.61%)_Space_42.1_MB_(7.61%)
+// #Medium #Top_Interview_Questions #Math #Udemy_Integers #Top_Interview_150_Math
+// #2025_03_09_Time_0_ms_(100.00%)_Space_40.78_MB_(46.99%)
public class Solution {
public int trailingZeroes(int n) {
diff --git a/src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java b/src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java
index ab2bdd414..b154568d2 100644
--- a/src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java
+++ b/src/main/java/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.java
@@ -2,7 +2,7 @@
// #Medium #Tree #Binary_Tree #Stack #Design #Binary_Search_Tree #Iterator
// #Data_Structure_II_Day_17_Tree #Programming_Skills_II_Day_16 #Level_2_Day_9_Binary_Search_Tree
-// #2022_06_26_Time_18_ms_(84.18%)_Space_52.2_MB_(23.01%)
+// #Top_Interview_150_Binary_Tree_General #2025_03_09_Time_15_ms_(100.00%)_Space_48.60_MB_(18.83%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql b/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql
index a5c43ee4a..ab0dd6a27 100644
--- a/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql
+++ b/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql
@@ -1,4 +1,12 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_5_Union #2022_06_26_Time_491_ms_(32.30%)_Space_0B_(100.00%)
-SELECT FirstName, LastName, City, State
-FROM Person LEFT JOIN Address USING (PersonId)
+SELECT
+ FirstName,
+ LastName,
+ City,
+ State
+FROM
+ Person
+LEFT JOIN
+ Address
+USING (PersonId);
diff --git a/src/main/java/g0101_0200/s0176_second_highest_salary/script.sql b/src/main/java/g0101_0200/s0176_second_highest_salary/script.sql
index edd9001b5..a6758a294 100644
--- a/src/main/java/g0101_0200/s0176_second_highest_salary/script.sql
+++ b/src/main/java/g0101_0200/s0176_second_highest_salary/script.sql
@@ -1,9 +1,13 @@
# Write your MySQL query statement below
# #Medium #Database #SQL_I_Day_4_Union_and_Select
# #2022_07_10_Time_225_ms_(73.10%)_Space_0B_(100.00%)
-SELECT ifnull(
- (SELECT distinct(Salary)
- FROM Employee
- ORDER BY Salary DESC
- LIMIT 1
- OFFSET 1), NULL) SecondHighestSalary;
+SELECT
+ IFNULL(
+ (
+ SELECT DISTINCT Salary
+ FROM Employee
+ ORDER BY Salary DESC
+ LIMIT 1 OFFSET 1
+ ),
+ NULL
+ ) AS SecondHighestSalary;
diff --git a/src/main/java/g0101_0200/s0178_rank_scores/script.sql b/src/main/java/g0101_0200/s0178_rank_scores/script.sql
index 67e867312..2773cd557 100644
--- a/src/main/java/g0101_0200/s0178_rank_scores/script.sql
+++ b/src/main/java/g0101_0200/s0178_rank_scores/script.sql
@@ -1,3 +1,9 @@
# Write your MySQL query statement below
# #Medium #Database #2022_06_26_Time_290_ms_(66.73%)_Space_0B_(100.00%)
-select Score, DENSE_RANK() OVER(order by Score Desc) as "Rank" from Scores order by "Rank" Asc;
+SELECT
+ Score,
+ DENSE_RANK() OVER (ORDER BY Score DESC) AS Rank
+FROM
+ Scores
+ORDER BY
+ Rank ASC;
diff --git a/src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql b/src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql
index 116633fbb..949b570bd 100644
--- a/src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql
+++ b/src/main/java/g0101_0200/s0180_consecutive_numbers/script.sql
@@ -1,6 +1,11 @@
# Write your MySQL query statement below
-# #Medium #Database #2022_06_26_Time_550_ms_(48.44%)_Space_0B_(100.00%)
-select distinct num as ConsecutiveNums from
-(select num, lag(num,1) over(order by id) as l1, lag(num,2) over(order by id) as l2
-from Logs) con_thr
-where num = l1 and num = l2
+# #Medium #Database #2024_07_15_Time_469_ms_(89.19%)_Space_0B_(100.00%)
+SELECT DISTINCT
+ l1.num AS ConsecutiveNums
+FROM
+ Logs l1
+ JOIN Logs l2 ON l1.id = l2.id - 1
+ JOIN Logs l3 ON l1.id = l3.id - 2
+WHERE
+ l1.num = l2.num
+ AND l2.num = l3.num;
diff --git a/src/main/java/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql b/src/main/java/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql
index 9cbf8e5ea..75f807b84 100644
--- a/src/main/java/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql
+++ b/src/main/java/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql
@@ -1,4 +1,10 @@
# Write your MySQL query statement below
# #Easy #Database #2022_06_27_Time_315_ms_(94.44%)_Space_0B_(100.00%)
-select a.Name as Employee from Employee a left join Employee b on a.ManagerId=b.Id
-where a.Salary > b.Salary and a.ManagerId is not null
+SELECT
+ a.Name AS Employee
+FROM
+ Employee a
+ LEFT JOIN Employee b ON a.ManagerId = b.Id
+WHERE
+ a.Salary > b.Salary
+ AND a.ManagerId IS NOT NULL;
diff --git a/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql b/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql
index 1f6ad665d..0cbebed39 100644
--- a/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql
+++ b/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql
@@ -1,3 +1,10 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_10_Where #2022_06_27_Time_303_ms_(92.08%)_Space_0B_(100.00%)
-SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1;
+SELECT
+ Email
+FROM
+ Person
+GROUP BY
+ Email
+HAVING
+ COUNT(Email) > 1;
diff --git a/src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql b/src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql
index 9711329dc..198c6e3c1 100644
--- a/src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql
+++ b/src/main/java/g0101_0200/s0183_customers_who_never_order/script.sql
@@ -1,7 +1,9 @@
# Write your MySQL query statement below
# #Easy #Database #SQL_I_Day_1_Select #2022_06_27_Time_376_ms_(98.73%)_Space_0B_(100.00%)
-SELECT c.Name as Customers
-FROM Customers as c
-LEFT JOIN Orders as o
-ON c.Id = o.CustomerId
-WHERE o.CustomerId is null
+SELECT
+ c.Name AS Customers
+FROM
+ Customers AS c
+ LEFT JOIN Orders AS o ON c.Id = o.CustomerId
+WHERE
+ o.CustomerId IS NULL;
diff --git a/src/main/java/g0101_0200/s0184_department_highest_salary/script.sql b/src/main/java/g0101_0200/s0184_department_highest_salary/script.sql
index 41fcd8d42..eb54457e4 100644
--- a/src/main/java/g0101_0200/s0184_department_highest_salary/script.sql
+++ b/src/main/java/g0101_0200/s0184_department_highest_salary/script.sql
@@ -5,13 +5,18 @@ SELECT
Sel.Name AS Employee,
Sel.Salary AS Salary
FROM
-(
- SELECT
- Name,
- Salary,
- DepartmentId,
- DENSE_RANK() OVER (PARTITION BY DepartmentId ORDER BY Salary DESC) AS dr
- FROM Employee
-) AS Sel
-INNER JOIN Department d ON d.Id = Sel.DepartmentId
-WHERE Sel.dr = 1
+ (
+ SELECT
+ Name,
+ Salary,
+ DepartmentId,
+ DENSE_RANK() OVER (
+ PARTITION BY DepartmentId
+ ORDER BY Salary DESC
+ ) AS dr
+ FROM
+ Employee
+ ) AS Sel
+ INNER JOIN Department d ON d.Id = Sel.DepartmentId
+WHERE
+ Sel.dr = 1;
diff --git a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.java b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.java
index 38d37ae0f..dc851951e 100644
--- a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.java
+++ b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/Solution.java
@@ -1,6 +1,7 @@
package g0101_0200.s0188_best_time_to_buy_and_sell_stock_iv;
-// #Hard #Array #Dynamic_Programming #2022_06_27_Time_1_ms_(100.00%)_Space_42.7_MB_(47.38%)
+// #Hard #Array #Dynamic_Programming #Top_Interview_150_Multidimensional_DP
+// #2025_03_09_Time_1_ms_(99.73%)_Space_41.76_MB_(82.48%)
public class Solution {
public int maxProfit(int k, int[] prices) {
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/Solution.java b/src/main/java/g0101_0200/s0189_rotate_array/Solution.java
index 5c221ad7f..ab7a087fe 100644
--- a/src/main/java/g0101_0200/s0189_rotate_array/Solution.java
+++ b/src/main/java/g0101_0200/s0189_rotate_array/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0189_rotate_array;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Two_Pointers
-// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
-// #2022_06_27_Time_0_ms_(100.00%)_Space_58_MB_(96.22%)
+// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String
+// #Big_O_Time_O(n)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_57.7_MB_(14.36%)
public class Solution {
private void reverse(int[] nums, int l, int r) {
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/Solution.java b/src/main/java/g0101_0200/s0190_reverse_bits/Solution.java
index 768fca7b5..6d314bdd6 100644
--- a/src/main/java/g0101_0200/s0190_reverse_bits/Solution.java
+++ b/src/main/java/g0101_0200/s0190_reverse_bits/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0190_reverse_bits;
// #Easy #Top_Interview_Questions #Bit_Manipulation #Divide_and_Conquer
-// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Bit_Manipulation
-// #2022_06_27_Time_1_ms_(98.66%)_Space_41.9_MB_(81.78%)
+// #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Bit_Manipulation #Top_Interview_150_Bit_Manipulation
+// #2025_03_09_Time_0_ms_(100.00%)_Space_41.94_MB_(43.56%)
public class Solution {
// you need treat n as an unsigned value
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/Solution.java b/src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java
index baa9d9054..0a1b5b8db 100644
--- a/src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java
+++ b/src/main/java/g0101_0200/s0191_number_of_1_bits/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0191_number_of_1_bits;
// #Easy #Top_Interview_Questions #Bit_Manipulation #Algorithm_I_Day_13_Bit_Manipulation
-// #Programming_Skills_I_Day_2_Operator #Udemy_Bit_Manipulation
-// #2022_06_28_Time_1_ms_(84.87%)_Space_41.8_MB_(10.40%)
+// #Programming_Skills_I_Day_2_Operator #Udemy_Bit_Manipulation #Top_Interview_150_Bit_Manipulation
+// #2025_03_09_Time_0_ms_(100.00%)_Space_41.10_MB_(13.52%)
public class Solution {
public int hammingWeight(int n) {
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/s0194_transpose_file/script.sh b/src/main/java/g0101_0200/s0194_transpose_file/script.sh
index 2e90bd48e..2b5f71645 100644
--- a/src/main/java/g0101_0200/s0194_transpose_file/script.sh
+++ b/src/main/java/g0101_0200/s0194_transpose_file/script.sh
@@ -1,8 +1,17 @@
# Read from the file file.txt and print its transposed content to stdout.
-# #Medium #Shell #2022_06_28_Time_630_ms_(28.43%)_Space_3.9_MB_(71.08%)
-wordcount=$(head -1 file.txt | wc -w)
-col_n=1
-while [[ $col_n -le $wordcount ]]; do
- awk "{ print \$$col_n }" file.txt | paste -sd " "
- col_n=$((col_n + 1))
-done
+# #Medium #Shell #2025_05_03_Time_61_ms_(88.19%)_Space_4.14_MB_(38.67%)
+awk '
+{
+ for (i = 1; i <= NF; i++) {
+ if (NR == 1) {
+ a[i] = $i
+ } else {
+ a[i] = a[i] " " $i
+ }
+ }
+}
+END {
+ for (i = 1; i <= NF; i++) {
+ print a[i]
+ }
+}' file.txt
diff --git a/src/main/java/g0101_0200/s0198_house_robber/Solution.java b/src/main/java/g0101_0200/s0198_house_robber/Solution.java
index 1aeaeb74a..7946f758f 100644
--- a/src/main/java/g0101_0200/s0198_house_robber/Solution.java
+++ b/src/main/java/g0101_0200/s0198_house_robber/Solution.java
@@ -1,9 +1,9 @@
package g0101_0200.s0198_house_robber;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
-// #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3
-// #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Big_O_Time_O(n)_Space_O(n)
-// #2022_06_28_Time_0_ms_(100.00%)_Space_39.9_MB_(85.30%)
+// #LeetCode_75_DP/1D #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3
+// #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_15_Time_0_ms_(100.00%)_Space_40.7_MB_(77.55%)
public class Solution {
public int rob(int[] nums) {
diff --git a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java
index d1c7c14af..a028b50cd 100644
--- a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java
+++ b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/Solution.java
@@ -1,8 +1,8 @@
package g0101_0200.s0199_binary_tree_right_side_view;
-// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
-// #Data_Structure_II_Day_16_Tree #Level_2_Day_15_Tree
-// #2022_06_28_Time_1_ms_(94.57%)_Space_42.9_MB_(41.09%)
+// #Medium #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
+// #LeetCode_75_Binary_Tree/BFS #Data_Structure_II_Day_16_Tree #Level_2_Day_15_Tree
+// #Top_Interview_150_Binary_Tree_BFS #2025_03_09_Time_0_ms_(100.00%)_Space_42.21_MB_(42.76%)
import com_github_leetcode.TreeNode;
import java.util.ArrayList;
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:**
-
-
**Input:** root = [1,2,3,null,5,null,4]
-**Output:** [1,3,4]
+**Output:** [1,3,4]
+
+**Explanation:**
+
+
**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:**
+
+
**Example 3:**
+**Input:** root = [1,null,3]
+
+**Output:** [1,3]
+
+**Example 4:**
+
**Input:** root = []
-**Output:** []
+**Output:** []
**Constraints:**
diff --git a/src/main/java/g0101_0200/s0200_number_of_islands/Solution.java b/src/main/java/g0101_0200/s0200_number_of_islands/Solution.java
index 741435a9b..23698eff9 100644
--- a/src/main/java/g0101_0200/s0200_number_of_islands/Solution.java
+++ b/src/main/java/g0101_0200/s0200_number_of_islands/Solution.java
@@ -4,7 +4,8 @@
// #Breadth_First_Search #Matrix #Union_Find
// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #Udemy_Graph
-// #Big_O_Time_O(M*N)_Space_O(M*N) #2022_06_28_Time_3_ms_(97.76%)_Space_57.5_MB_(41.23%)
+// #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N)
+// #2024_11_15_Time_3_ms_(87.24%)_Space_49.6_MB_(39.89%)
public class Solution {
public int numIslands(char[][] grid) {
diff --git a/src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java b/src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java
index 7f1814cbf..23f934d8b 100644
--- a/src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java
+++ b/src/main/java/g0201_0300/s0201_bitwise_and_of_numbers_range/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0201_bitwise_and_of_numbers_range;
// #Medium #Bit_Manipulation #Algorithm_II_Day_19_Bit_Manipulation
-// #2022_06_28_Time_8_ms_(74.15%)_Space_44.4_MB_(39.54%)
+// #Top_Interview_150_Bit_Manipulation #2025_03_09_Time_3_ms_(100.00%)_Space_43.70_MB_(94.56%)
public class Solution {
private static final int[] MASKS =
diff --git a/src/main/java/g0201_0300/s0202_happy_number/Solution.java b/src/main/java/g0201_0300/s0202_happy_number/Solution.java
index e3dffa3a4..6187252b9 100644
--- a/src/main/java/g0201_0300/s0202_happy_number/Solution.java
+++ b/src/main/java/g0201_0300/s0202_happy_number/Solution.java
@@ -2,7 +2,7 @@
// #Easy #Top_Interview_Questions #Hash_Table #Math #Two_Pointers #Algorithm_II_Day_21_Others
// #Programming_Skills_I_Day_4_Loop #Level_2_Day_1_Implementation/Simulation
-// #2022_06_28_Time_1_ms_(98.59%)_Space_41_MB_(64.25%)
+// #Top_Interview_150_Hashmap #2025_03_09_Time_0_ms_(100.00%)_Space_40.92_MB_(38.98%)
public class Solution {
public boolean isHappy(int n) {
diff --git a/src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java b/src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java
index 5164a615e..8a8d5458f 100644
--- a/src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java
+++ b/src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0205_isomorphic_strings;
-// #Easy #String #Hash_Table #Level_1_Day_2_String
-// #2022_06_28_Time_2_ms_(99.97%)_Space_43.3_MB_(32.68%)
+// #Easy #String #Hash_Table #Level_1_Day_2_String #Top_Interview_150_Hashmap
+// #2025_03_09_Time_2_ms_(99.18%)_Space_42.83_MB_(16.73%)
public class Solution {
public boolean isIsomorphic(String s, String t) {
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/s0206_reverse_linked_list/Solution.java b/src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java
index 575856453..9e24c044f 100644
--- a/src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java
+++ b/src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java
@@ -1,9 +1,9 @@
package g0201_0300.s0206_reverse_linked_list;
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
-// #Data_Structure_I_Day_8_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
-// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
-// #2022_06_28_Time_0_ms_(100.00%)_Space_43.9_MB_(7.98%)
+// #LeetCode_75_LinkedList #Data_Structure_I_Day_8_Linked_List
+// #Algorithm_I_Day_10_Recursion_Backtracking #Level_1_Day_3_Linked_List #Udemy_Linked_List
+// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_42.5_MB_(41.63%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0201_0300/s0207_course_schedule/Solution.java b/src/main/java/g0201_0300/s0207_course_schedule/Solution.java
index cee89e4f2..292ca0387 100644
--- a/src/main/java/g0201_0300/s0207_course_schedule/Solution.java
+++ b/src/main/java/g0201_0300/s0207_course_schedule/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0207_course_schedule;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search
-// #Breadth_First_Search #Graph #Topological_Sort #Big_O_Time_O(N)_Space_O(N)
-// #2022_06_28_Time_3_ms_(97.58%)_Space_48.2_MB_(49.51%)
+// #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General
+// #Big_O_Time_O(N)_Space_O(N) #2024_11_15_Time_3_ms_(99.99%)_Space_44.8_MB_(88.52%)
import java.util.ArrayList;
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/s0208_implement_trie_prefix_tree/Trie.java b/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java
index fd0432c1c..574fa6c1d 100644
--- a/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java
+++ b/src/main/java/g0201_0300/s0208_implement_trie_prefix_tree/Trie.java
@@ -1,13 +1,13 @@
package g0201_0300.s0208_implement_trie_prefix_tree;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie
-// #Level_2_Day_16_Design #Udemy_Trie_and_Heap
+// #LeetCode_75_Trie #Level_2_Day_16_Design #Udemy_Trie_and_Heap #Top_Interview_150_Trie
// #Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N)
-// #2022_06_28_Time_34_ms_(99.90%)_Space_51_MB_(94.92%)
+// #2024_11_15_Time_32_ms_(95.05%)_Space_54.9_MB_(91.16%)
@SuppressWarnings("java:S1104")
public class Trie {
- private TrieNode root;
+ private final TrieNode root;
private boolean startWith;
private static class TrieNode {
@@ -46,7 +46,7 @@ public boolean search(String word) {
return search(word, root, 0);
}
- public boolean search(String word, TrieNode root, int idx) {
+ private boolean search(String word, TrieNode root, int idx) {
if (idx == word.length()) {
startWith = true;
return root.isWord;
@@ -66,3 +66,11 @@ public boolean startsWith(String prefix) {
return startWith;
}
}
+
+/*
+ * Your Trie object will be instantiated and called as such:
+ * Trie obj = new Trie();
+ * obj.insert(word);
+ * boolean param_2 = obj.search(word);
+ * boolean param_3 = obj.startsWith(prefix);
+ */
diff --git a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java
index 5b523e24f..fa8e86ae8 100644
--- a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java
+++ b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/Solution.java
@@ -1,7 +1,8 @@
package g0201_0300.s0209_minimum_size_subarray_sum;
// #Medium #Array #Binary_Search #Prefix_Sum #Sliding_Window #Algorithm_II_Day_5_Sliding_Window
-// #Binary_Search_II_Day_1 #2022_06_28_Time_1_ms_(100.00%)_Space_50.1_MB_(11.60%)
+// #Binary_Search_II_Day_1 #Top_Interview_150_Sliding_Window
+// #2025_03_09_Time_1_ms_(99.76%)_Space_58.08_MB_(66.32%)
public class Solution {
public int minSubArrayLen(int target, int[] nums) {
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/Solution.java b/src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java
index a040c13d7..3d11da7b7 100644
--- a/src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java
+++ b/src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0210_course_schedule_ii;
// #Medium #Top_Interview_Questions #Depth_First_Search #Breadth_First_Search #Graph
-// #Topological_Sort #Level_2_Day_11_Graph/BFS/DFS
-// #2022_06_28_Time_13_ms_(35.17%)_Space_50.7_MB_(22.84%)
+// #Topological_Sort #Level_2_Day_11_Graph/BFS/DFS #Top_Interview_150_Graph_General
+// #2025_03_09_Time_4_ms_(91.07%)_Space_45.55_MB_(91.17%)
import java.util.ArrayList;
import java.util.HashMap;
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/WordDictionary.java b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/WordDictionary.java
index 2626aa5e9..16fc8a6f1 100644
--- a/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/WordDictionary.java
+++ b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/WordDictionary.java
@@ -1,7 +1,7 @@
package g0201_0300.s0211_design_add_and_search_words_data_structure;
-// #Medium #String #Depth_First_Search #Design #Trie
-// #2023_01_06_Time_308_ms_(99.46%)_Space_284.7_MB_(13.25%)
+// #Medium #String #Depth_First_Search #Design #Trie #Top_Interview_150_Trie
+// #2025_03_09_Time_156_ms_(99.85%)_Space_100.34_MB_(44.69%)
public class WordDictionary {
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/s0212_word_search_ii/Solution.java b/src/main/java/g0201_0300/s0212_word_search_ii/Solution.java
index 9548105d4..8ec2358a2 100644
--- a/src/main/java/g0201_0300/s0212_word_search_ii/Solution.java
+++ b/src/main/java/g0201_0300/s0212_word_search_ii/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0212_word_search_ii;
-// #Hard #Top_Interview_Questions #Array #String #Matrix #Backtracking #Trie
-// #2022_07_02_Time_21_ms_(99.42%)_Space_44.1_MB_(67.33%)
+// #Hard #Top_Interview_Questions #Array #String #Matrix #Backtracking #Trie #Top_Interview_150_Trie
+// #2025_03_09_Time_17_ms_(99.16%)_Space_45.08_MB_(67.05%)
import java.util.ArrayList;
import java.util.Collections;
diff --git a/src/main/java/g0201_0300/s0212_word_search_ii/Tree.java b/src/main/java/g0201_0300/s0212_word_search_ii/Tree.java
index 7ca9046ad..11865d884 100644
--- a/src/main/java/g0201_0300/s0212_word_search_ii/Tree.java
+++ b/src/main/java/g0201_0300/s0212_word_search_ii/Tree.java
@@ -1,8 +1,5 @@
package g0201_0300.s0212_word_search_ii;
-// #Hard #Top_Interview_Questions #Array #String #Matrix #Backtracking #Trie
-// #2022_07_02_Time_21_ms_(99.42%)_Space_44.1_MB_(67.33%)
-
@SuppressWarnings("java:S1104")
public class Tree {
private Tree[] children;
diff --git a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java
index 7c0c92758..22df02908 100644
--- a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java
+++ b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.java
@@ -1,7 +1,8 @@
package g0201_0300.s0215_kth_largest_element_in_an_array;
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Heap_Priority_Queue
-// #Divide_and_Conquer #Quickselect #Data_Structure_II_Day_20_Heap_Priority_Queue
+// #Divide_and_Conquer #Quickselect #LeetCode_75_Heap/Priority_Queue
+// #Data_Structure_II_Day_20_Heap_Priority_Queue #Top_Interview_150_Heap
// #Big_O_Time_O(n*log(n))_Space_O(log(n)) #2022_07_02_Time_5_ms_(70.82%)_Space_45.1_MB_(24.69%)
import java.util.Arrays;
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
diff --git a/src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java b/src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java
index dd877b0a0..41f701cd1 100644
--- a/src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java
+++ b/src/main/java/g0201_0300/s0216_combination_sum_iii/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0216_combination_sum_iii;
-// #Medium #Array #Backtracking #Udemy_Backtracking/Recursion
+// #Medium #Array #Backtracking #LeetCode_75_Backtracking #Udemy_Backtracking/Recursion
// #2022_07_02_Time_1_ms_(81.35%)_Space_41.8_MB_(46.36%)
import java.util.ArrayList;
diff --git a/src/main/java/g0201_0300/s0218_the_skyline_problem/Solution.java b/src/main/java/g0201_0300/s0218_the_skyline_problem/Solution.java
index cea91b992..f265f5ef6 100644
--- a/src/main/java/g0201_0300/s0218_the_skyline_problem/Solution.java
+++ b/src/main/java/g0201_0300/s0218_the_skyline_problem/Solution.java
@@ -1,8 +1,7 @@
package g0201_0300.s0218_the_skyline_problem;
-// #Hard #Top_Interview_Questions #Array #Heap_Priority_Queue #Ordered_Set #Divide_and_Conquer
-// #Segment_Tree #Binary_Indexed_Tree #Line_Sweep
-// #2022_07_02_Time_22_ms_(76.93%)_Space_52.3_MB_(45.14%)
+// #Hard #Array #Heap_Priority_Queue #Ordered_Set #Divide_and_Conquer #Segment_Tree
+// #Binary_Indexed_Tree #Line_Sweep #2022_07_02_Time_22_ms_(76.93%)_Space_52.3_MB_(45.14%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/Solution.java b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/Solution.java
index 188e07b94..48a8d434f 100644
--- a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/Solution.java
+++ b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/Solution.java
@@ -1,6 +1,7 @@
package g0201_0300.s0219_contains_duplicate_ii;
-// #Easy #Array #Hash_Table #Sliding_Window #2022_07_02_Time_15_ms_(99.09%)_Space_56_MB_(82.82%)
+// #Easy #Array #Hash_Table #Sliding_Window #Top_Interview_150_Hashmap
+// #2025_03_09_Time_15_ms_(98.00%)_Space_57.98_MB_(48.14%)
import java.util.HashMap;
import java.util.Map;
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/s0220_contains_duplicate_iii/Solution.java b/src/main/java/g0201_0300/s0220_contains_duplicate_iii/Solution.java
index e7f4e44c8..e80d250b7 100644
--- a/src/main/java/g0201_0300/s0220_contains_duplicate_iii/Solution.java
+++ b/src/main/java/g0201_0300/s0220_contains_duplicate_iii/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0220_contains_duplicate_iii;
-// #Medium #Array #Sorting #Sliding_Window #Ordered_Set #Bucket_Sort
+// #Hard #Array #Sorting #Sliding_Window #Ordered_Set #Bucket_Sort
// #2022_07_02_Time_38_ms_(80.90%)_Space_54.1_MB_(52.01%)
import java.util.HashMap;
diff --git a/src/main/java/g0201_0300/s0221_maximal_square/Solution.java b/src/main/java/g0201_0300/s0221_maximal_square/Solution.java
index 813897f24..4ed42d49f 100644
--- a/src/main/java/g0201_0300/s0221_maximal_square/Solution.java
+++ b/src/main/java/g0201_0300/s0221_maximal_square/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0221_maximal_square;
-// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix
-// #Dynamic_Programming_I_Day_16 #Big_O_Time_O(m*n)_Space_O(m*n)
-// #2022_07_04_Time_7_ms_(72.35%)_Space_59.5_MB_(10.55%)
+// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_16
+// #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(m*n)_Space_O(m*n)
+// #2024_11_16_Time_6_ms_(97.07%)_Space_60.3_MB_(39.55%)
public class Solution {
public int maximalSquare(char[][] matrix) {
diff --git a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java
index 5df754f2c..edf5a327c 100644
--- a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java
+++ b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0222_count_complete_tree_nodes;
-// #Medium #Depth_First_Search #Tree #Binary_Search #Binary_Tree #Binary_Search_II_Day_10
-// #2022_07_04_Time_0_ms_(100.00%)_Space_50_MB_(37.43%)
+// #Easy #Depth_First_Search #Tree #Binary_Search #Binary_Tree #Binary_Search_II_Day_10
+// #Top_Interview_150_Binary_Tree_General #2025_03_09_Time_0_ms_(100.00%)_Space_47.81_MB_(37.25%)
import com_github_leetcode.TreeNode;
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/s0224_basic_calculator/Solution.java b/src/main/java/g0201_0300/s0224_basic_calculator/Solution.java
index 684fe6fdd..61a626bae 100644
--- a/src/main/java/g0201_0300/s0224_basic_calculator/Solution.java
+++ b/src/main/java/g0201_0300/s0224_basic_calculator/Solution.java
@@ -1,6 +1,7 @@
package g0201_0300.s0224_basic_calculator;
-// #Hard #String #Math #Stack #Recursion #2022_07_04_Time_3_ms_(98.92%)_Space_44.6_MB_(43.19%)
+// #Hard #String #Math #Stack #Recursion #Top_Interview_150_Stack
+// #2025_03_09_Time_2_ms_(96.52%)_Space_45.07_MB_(23.63%)
public class Solution {
private int i = 0;
diff --git a/src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java b/src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java
index a5fe94bab..693fa0786 100644
--- a/src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java
+++ b/src/main/java/g0201_0300/s0226_invert_binary_tree/Solution.java
@@ -2,7 +2,8 @@
// #Easy #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #Data_Structure_I_Day_12_Tree #Level_2_Day_6_Tree #Udemy_Tree_Stack_Queue
-// #Big_O_Time_O(n)_Space_O(n) #2022_07_04_Time_0_ms_(100.00%)_Space_42_MB_(20.73%)
+// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_16_Time_0_ms_(100.00%)_Space_40.6_MB_(95.51%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java b/src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java
index f344e68e2..db4b9e133 100644
--- a/src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java
+++ b/src/main/java/g0201_0300/s0227_basic_calculator_ii/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0227_basic_calculator_ii;
-// #Medium #Top_Interview_Questions #String #Math #Stack #Level_2_Day_18_Stack
+// #Medium #String #Math #Stack #Level_2_Day_18_Stack
// #2022_07_04_Time_8_ms_(95.32%)_Space_43.6_MB_(79.36%)
public class Solution {
diff --git a/src/main/java/g0201_0300/s0228_summary_ranges/Solution.java b/src/main/java/g0201_0300/s0228_summary_ranges/Solution.java
index 14bcb54af..3486a95e8 100644
--- a/src/main/java/g0201_0300/s0228_summary_ranges/Solution.java
+++ b/src/main/java/g0201_0300/s0228_summary_ranges/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0228_summary_ranges;
-// #Easy #Array #2022_07_04_Time_0_ms_(100.00%)_Space_42.7_MB_(15.43%)
+// #Easy #Array #Top_Interview_150_Intervals #2025_03_09_Time_0_ms_(100.00%)_Space_41.53_MB_(90.54%)
import java.util.ArrayList;
import java.util.List;
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/s0230_kth_smallest_element_in_a_bst/Solution.java b/src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java
index 546fb9ad0..609c495b0 100644
--- a/src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java
+++ b/src/main/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution.java
@@ -1,8 +1,9 @@
package g0201_0300.s0230_kth_smallest_element_in_a_bst;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree
-// #Binary_Search_Tree #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree
-// #Big_O_Time_O(n)_Space_O(n) #2022_07_04_Time_1_ms_(78.91%)_Space_45.3_MB_(58.87%)
+// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree
+// #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree
+// #Top_Interview_150_Binary_Search_Tree #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_16_Time_0_ms_(100.00%)_Space_44.3_MB_(63.70%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java b/src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java
index e42c2a3ff..301c4fced 100644
--- a/src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java
+++ b/src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java
@@ -10,6 +10,7 @@
public class MyQueue {
private Deque left;
private Deque right;
+
// Initialize your data structure here.
public MyQueue() {
left = new ArrayDeque<>();
diff --git a/src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java b/src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java
index fcdf6edb1..b212b6d3a 100644
--- a/src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java
+++ b/src/main/java/g0201_0300/s0234_palindrome_linked_list/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0234_palindrome_linked_list;
-// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Stack #Linked_List
-// #Recursion #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1)
-// #2022_07_04_Time_6_ms_(76.07%)_Space_97.6_MB_(56.14%)
+// #Easy #Top_100_Liked_Questions #Two_Pointers #Stack #Linked_List #Recursion
+// #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1)
+// #2024_11_16_Time_4_ms_(84.46%)_Space_69_MB_(17.17%)
import com_github_leetcode.ListNode;
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/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java b/src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java
index 8f7ed12d7..873d12c51 100644
--- a/src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java
+++ b/src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0235_lowest_common_ancestor_of_a_binary_search_tree;
-// #Easy #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree #Data_Structure_I_Day_14_Tree
+// #Medium #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree #Data_Structure_I_Day_14_Tree
// #Level_1_Day_8_Binary_Search_Tree #2022_07_04_Time_4_ms_(100.00%)_Space_43.2_MB_(90.56%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java b/src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java
index 9ad99ad90..32dd6075b 100644
--- a/src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java
+++ b/src/main/java/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.java
@@ -1,8 +1,9 @@
package g0201_0300.s0236_lowest_common_ancestor_of_a_binary_tree;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree
-// #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
-// #2022_07_04_Time_10_ms_(56.51%)_Space_47.4_MB_(45.84%)
+// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree
+// #LeetCode_75_Binary_Tree/DFS #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue
+// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_16_Time_6_ms_(100.00%)_Space_44_MB_(98.99%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0201_0300/s0237_delete_node_in_a_linked_list/Solution.java b/src/main/java/g0201_0300/s0237_delete_node_in_a_linked_list/Solution.java
index b83f9fa5d..bc07032ce 100644
--- a/src/main/java/g0201_0300/s0237_delete_node_in_a_linked_list/Solution.java
+++ b/src/main/java/g0201_0300/s0237_delete_node_in_a_linked_list/Solution.java
@@ -1,7 +1,6 @@
package g0201_0300.s0237_delete_node_in_a_linked_list;
-// #Easy #Top_Interview_Questions #Linked_List
-// #2022_07_04_Time_0_ms_(100.00%)_Space_43.8_MB_(62.83%)
+// #Medium #Linked_List #2022_07_04_Time_0_ms_(100.00%)_Space_43.8_MB_(62.83%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java b/src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java
index d30a46a80..0ae177b08 100644
--- a/src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java
+++ b/src/main/java/g0201_0300/s0238_product_of_array_except_self/Solution.java
@@ -1,29 +1,22 @@
package g0201_0300.s0238_product_of_array_except_self;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Prefix_Sum
-// #Data_Structure_II_Day_5_Array #Udemy_Arrays #Big_O_Time_O(n^2)_Space_O(n)
-// #2022_07_04_Time_1_ms_(100.00%)_Space_50.8_MB_(85.60%)
+// #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #LeetCode_75_Array/String
+// #Data_Structure_II_Day_5_Array #Udemy_Arrays #Top_Interview_150_Array/String
+// #Big_O_Time_O(n^2)_Space_O(n) #2024_11_16_Time_1_ms_(99.66%)_Space_55.1_MB_(79.02%)
public class Solution {
public int[] productExceptSelf(int[] nums) {
- int product = 1;
- int[] ans = new int[nums.length];
- for (int num : nums) {
- product = product * num;
- }
+ int[] res = new int[nums.length];
+ int prefixProduct = 1;
for (int i = 0; i < nums.length; i++) {
- if (nums[i] != 0) {
- ans[i] = product / nums[i];
- } else {
- int p = 1;
- for (int j = 0; j < nums.length; j++) {
- if (j != i) {
- p = p * nums[j];
- }
- }
- ans[i] = p;
- }
+ res[i] = prefixProduct;
+ prefixProduct *= nums[i];
+ }
+ int suffixProduct = 1;
+ for (int i = nums.length - 1; i >= 0; i--) {
+ res[i] *= suffixProduct;
+ suffixProduct *= nums[i];
}
- return ans;
+ return res;
}
}
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/Solution.java b/src/main/java/g0201_0300/s0239_sliding_window_maximum/Solution.java
index f3a6de1b7..0be6c1834 100644
--- a/src/main/java/g0201_0300/s0239_sliding_window_maximum/Solution.java
+++ b/src/main/java/g0201_0300/s0239_sliding_window_maximum/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0239_sliding_window_maximum;
-// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Heap_Priority_Queue
-// #Sliding_Window #Queue #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
-// #2022_07_04_Time_58_ms_(52.28%)_Space_145_MB_(50.60%)
+// #Hard #Top_100_Liked_Questions #Array #Heap_Priority_Queue #Sliding_Window #Queue
+// #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
+// #2024_11_16_Time_26_ms_(95.89%)_Space_59.6_MB_(38.70%)
import java.util.LinkedList;
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/Solution.java b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java
index 316af701d..24f96fa09 100644
--- a/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java
+++ b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0240_search_a_2d_matrix_ii;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Matrix
-// #Divide_and_Conquer #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8
-// #Big_O_Time_O(n+m)_Space_O(1) #2022_07_04_Time_7_ms_(86.73%)_Space_58.4_MB_(9.95%)
+// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Divide_and_Conquer
+// #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
+// #2024_11_16_Time_5_ms_(99.92%)_Space_45.8_MB_(60.21%)
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
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/Solution.java b/src/main/java/g0201_0300/s0242_valid_anagram/Solution.java
index ae4665bbb..d4148d338 100644
--- a/src/main/java/g0201_0300/s0242_valid_anagram/Solution.java
+++ b/src/main/java/g0201_0300/s0242_valid_anagram/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0242_valid_anagram;
-// #Easy #Top_Interview_Questions #String #Hash_Table #Sorting #Data_Structure_I_Day_6_String
-// #Programming_Skills_I_Day_11_Containers_and_Libraries #Udemy_Strings
-// #2022_07_05_Time_2_ms_(99.01%)_Space_42.4_MB_(91.86%)
+// #Easy #String #Hash_Table #Sorting #Data_Structure_I_Day_6_String
+// #Programming_Skills_I_Day_11_Containers_and_Libraries #Udemy_Strings #Top_Interview_150_Hashmap
+// #2025_03_09_Time_2_ms_(97.76%)_Space_43.41_MB_(66.14%)
public class Solution {
public boolean isAnagram(String s, String t) {
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/s0268_missing_number/Solution.java b/src/main/java/g0201_0300/s0268_missing_number/Solution.java
index 3d14b8c13..e6ab59918 100644
--- a/src/main/java/g0201_0300/s0268_missing_number/Solution.java
+++ b/src/main/java/g0201_0300/s0268_missing_number/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0268_missing_number;
-// #Easy #Top_Interview_Questions #Array #Hash_Table #Math #Sorting #Binary_Search #Bit_Manipulation
+// #Easy #Array #Hash_Table #Math #Sorting #Binary_Search #Bit_Manipulation
// #2022_07_05_Time_1_ms_(72.07%)_Space_50.6_MB_(76.88%)
public class Solution {
diff --git a/src/main/java/g0201_0300/s0274_h_index/Solution.java b/src/main/java/g0201_0300/s0274_h_index/Solution.java
index 6280d4e5c..647dbc1ad 100644
--- a/src/main/java/g0201_0300/s0274_h_index/Solution.java
+++ b/src/main/java/g0201_0300/s0274_h_index/Solution.java
@@ -1,6 +1,7 @@
package g0201_0300.s0274_h_index;
-// #Medium #Array #Sorting #Counting_Sort #2022_11_05_Time_0_ms_(100.00%)_Space_40.3_MB_(86.98%)
+// #Medium #Array #Sorting #Counting_Sort #Top_Interview_150_Array/String
+// #2022_11_05_Time_0_ms_(100.00%)_Space_40.3_MB_(86.98%)
public class Solution {
public int hIndex(int[] citations) {
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/s0279_perfect_squares/Solution.java b/src/main/java/g0201_0300/s0279_perfect_squares/Solution.java
index a7eb35257..e5ca5ca22 100644
--- a/src/main/java/g0201_0300/s0279_perfect_squares/Solution.java
+++ b/src/main/java/g0201_0300/s0279_perfect_squares/Solution.java
@@ -1,6 +1,6 @@
package g0201_0300.s0279_perfect_squares;
-// #Medium #Top_Interview_Questions #Dynamic_Programming #Math #Breadth_First_Search
+// #Medium #Top_100_Liked_Questions #Dynamic_Programming #Math #Breadth_First_Search
// #Dynamic_Programming_I_Day_21 #2022_07_06_Time_1_ms_(100.00%)_Space_40.2_MB_(99.44%)
public class Solution {
diff --git a/src/main/java/g0201_0300/s0282_expression_add_operators/Solution.java b/src/main/java/g0201_0300/s0282_expression_add_operators/Solution.java
index 048633149..ea58104f1 100644
--- a/src/main/java/g0201_0300/s0282_expression_add_operators/Solution.java
+++ b/src/main/java/g0201_0300/s0282_expression_add_operators/Solution.java
@@ -9,7 +9,7 @@
public class Solution {
public List addOperators(String num, int target) {
List res = new ArrayList<>();
- if (num.length() == 0 || Long.valueOf(num) > Integer.MAX_VALUE) {
+ if (num.isEmpty() || Long.parseLong(num) > Integer.MAX_VALUE) {
return res;
}
char[] list = num.toCharArray();
diff --git a/src/main/java/g0201_0300/s0283_move_zeroes/Solution.java b/src/main/java/g0201_0300/s0283_move_zeroes/Solution.java
index 7b23fae53..fc89319fb 100644
--- a/src/main/java/g0201_0300/s0283_move_zeroes/Solution.java
+++ b/src/main/java/g0201_0300/s0283_move_zeroes/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0283_move_zeroes;
-// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Two_Pointers
+// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #LeetCode_75_Two_Pointers
// #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays
-// #Big_O_Time_O(n)_Space_O(1) #2022_07_06_Time_2_ms_(79.54%)_Space_55.7_MB_(5.98%)
+// #Big_O_Time_O(n)_Space_O(1) #2024_11_16_Time_2_ms_(83.99%)_Space_45.9_MB_(50.99%)
public class Solution {
public void moveZeroes(int[] nums) {
diff --git a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java
index 90274a8de..494072cb5 100644
--- a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java
+++ b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/Solution.java
@@ -1,8 +1,8 @@
package g0201_0300.s0287_find_the_duplicate_number;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Two_Pointers
-// #Bit_Manipulation #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n)
-// #2022_07_06_Time_2_ms_(99.82%)_Space_61.1_MB_(83.92%)
+// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Two_Pointers #Bit_Manipulation
+// #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_16_Time_2_ms_(97.52%)_Space_59.9_MB_(5.22%)
public class Solution {
public int findDuplicate(int[] nums) {
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/Solution.java b/src/main/java/g0201_0300/s0289_game_of_life/Solution.java
index 16725178d..411b75c6f 100644
--- a/src/main/java/g0201_0300/s0289_game_of_life/Solution.java
+++ b/src/main/java/g0201_0300/s0289_game_of_life/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0289_game_of_life;
-// #Medium #Top_Interview_Questions #Array #Matrix #Simulation
-// #2022_07_06_Time_0_ms_(100.00%)_Space_42.9_MB_(10.73%)
+// #Medium #Array #Matrix #Simulation #Top_Interview_150_Matrix
+// #2025_03_09_Time_0_ms_(100.00%)_Space_41.90_MB_(24.53%)
public class Solution {
public void gameOfLife(int[][] board) {
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/Solution.java b/src/main/java/g0201_0300/s0290_word_pattern/Solution.java
index c68769295..db0687d14 100644
--- a/src/main/java/g0201_0300/s0290_word_pattern/Solution.java
+++ b/src/main/java/g0201_0300/s0290_word_pattern/Solution.java
@@ -1,7 +1,7 @@
package g0201_0300.s0290_word_pattern;
-// #Easy #String #Hash_Table #Data_Structure_II_Day_7_String
-// #2022_07_06_Time_1_ms_(97.26%)_Space_40.4_MB_(85.78%)
+// #Easy #String #Hash_Table #Data_Structure_II_Day_7_String #Top_Interview_150_Hashmap
+// #2025_03_09_Time_0_ms_(100.00%)_Space_41.27_MB_(92.07%)
import java.util.HashMap;
import java.util.Map;
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/MedianFinder.java b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinder.java
index 9bb2850b6..0f0ebfaa6 100644
--- a/src/main/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinder.java
+++ b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/MedianFinder.java
@@ -1,8 +1,8 @@
package g0201_0300.s0295_find_median_from_data_stream;
-// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Design
-// #Heap_Priority_Queue #Data_Stream #Big_O_Time_O(n*log_n)_Space_O(n)
-// #2022_07_06_Time_151_ms_(80.24%)_Space_125.2_MB_(44.11%)
+// #Hard #Top_100_Liked_Questions #Sorting #Two_Pointers #Design #Heap_Priority_Queue #Data_Stream
+// #Top_Interview_150_Heap #Big_O_Time_O(n*log_n)_Space_O(n)
+// #2024_11_16_Time_83_ms_(99.56%)_Space_63.4_MB_(77.85%)
import java.util.PriorityQueue;
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/s0297_serialize_and_deserialize_binary_tree/Codec.java b/src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java
index ba15a46c1..18ad4e704 100644
--- a/src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java
+++ b/src/main/java/g0201_0300/s0297_serialize_and_deserialize_binary_tree/Codec.java
@@ -1,7 +1,7 @@
package g0201_0300.s0297_serialize_and_deserialize_binary_tree;
-// #Hard #Top_Interview_Questions #String #Depth_First_Search #Breadth_First_Search #Tree
-// #Binary_Tree #Design #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue
+// #Hard #String #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Design
+// #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue
// #2022_07_06_Time_7_ms_(98.13%)_Space_51.1_MB_(74.13%)
import com_github_leetcode.TreeNode;
@@ -36,11 +36,7 @@ public void serialize(TreeNode root, StringBuilder sb) {
return;
}
String s = Integer.toHexString(root.val + BASE_OFFSET);
- StringBuilder sb2 = new StringBuilder();
- for (int i = 0; i < 3 - s.length(); i++) {
- sb2.append('0');
- }
- sb2.append(s);
+ String sb2 = "0".repeat(Math.max(0, 3 - s.length())) + s;
sb.append(sb2);
serialize(root.left, sb);
serialize(root.right, sb);
diff --git a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java
index 318c619fd..7ba248b8c 100644
--- a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java
+++ b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/Solution.java
@@ -1,9 +1,9 @@
package g0201_0300.s0300_longest_increasing_subsequence;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
-// #Binary_Search #Algorithm_II_Day_16_Dynamic_Programming #Binary_Search_II_Day_3
-// #Dynamic_Programming_I_Day_18 #Udemy_Dynamic_Programming #Big_O_Time_O(n*log_n)_Space_O(n)
-// #2022_07_06_Time_3_ms_(98.63%)_Space_44.3_MB_(60.27%)
+// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Binary_Search
+// #Algorithm_II_Day_16_Dynamic_Programming #Binary_Search_II_Day_3 #Dynamic_Programming_I_Day_18
+// #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(n*log_n)_Space_O(n)
+// #2024_11_16_Time_3_ms_(95.75%)_Space_43.7_MB_(93.58%)
public class Solution {
public int lengthOfLIS(int[] nums) {
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:**
diff --git a/src/main/java/g0301_0400/s0315_count_of_smaller_numbers_after_self/Solution.java b/src/main/java/g0301_0400/s0315_count_of_smaller_numbers_after_self/Solution.java
index 7e0767de0..44c4a5c2a 100644
--- a/src/main/java/g0301_0400/s0315_count_of_smaller_numbers_after_self/Solution.java
+++ b/src/main/java/g0301_0400/s0315_count_of_smaller_numbers_after_self/Solution.java
@@ -1,8 +1,7 @@
package g0301_0400.s0315_count_of_smaller_numbers_after_self;
-// #Hard #Top_Interview_Questions #Array #Binary_Search #Ordered_Set #Divide_and_Conquer
-// #Segment_Tree #Binary_Indexed_Tree #Merge_Sort
-// #2022_07_08_Time_36_ms_(98.63%)_Space_119_MB_(77.48%)
+// #Hard #Array #Binary_Search #Ordered_Set #Divide_and_Conquer #Segment_Tree #Binary_Indexed_Tree
+// #Merge_Sort #2022_07_08_Time_36_ms_(98.63%)_Space_119_MB_(77.48%)
import java.util.LinkedList;
import java.util.List;
@@ -41,6 +40,7 @@ public void update(int i, int v) {
bit[i] += v;
}
}
+
// prefix sum query
private int ps(int j) {
int ps = 0;
diff --git a/src/main/java/g0301_0400/s0322_coin_change/Solution.java b/src/main/java/g0301_0400/s0322_coin_change/Solution.java
index 87cac6baf..423fca945 100644
--- a/src/main/java/g0301_0400/s0322_coin_change/Solution.java
+++ b/src/main/java/g0301_0400/s0322_coin_change/Solution.java
@@ -1,9 +1,9 @@
package g0301_0400.s0322_coin_change;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
-// #Breadth_First_Search #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20
-// #Level_2_Day_12_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(amount)
-// #2022_07_09_Time_17_ms_(91.77%)_Space_41.8_MB_(95.50%)
+// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Breadth_First_Search
+// #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_20
+// #Level_2_Day_12_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(m*n)_Space_O(amount)
+// #2024_11_16_Time_12_ms_(92.59%)_Space_44.3_MB_(64.02%)
public class Solution {
public int coinChange(int[] coins, int amount) {
diff --git a/src/main/java/g0301_0400/s0324_wiggle_sort_ii/Solution.java b/src/main/java/g0301_0400/s0324_wiggle_sort_ii/Solution.java
index e1b4046ad..5edf0b343 100644
--- a/src/main/java/g0301_0400/s0324_wiggle_sort_ii/Solution.java
+++ b/src/main/java/g0301_0400/s0324_wiggle_sort_ii/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0324_wiggle_sort_ii;
-// #Medium #Top_Interview_Questions #Array #Sorting #Divide_and_Conquer #Quickselect
+// #Medium #Array #Sorting #Divide_and_Conquer #Quickselect
// #2022_07_09_Time_4_ms_(93.22%)_Space_46.4_MB_(85.87%)
import java.util.Arrays;
diff --git a/src/main/java/g0301_0400/s0326_power_of_three/Solution.java b/src/main/java/g0301_0400/s0326_power_of_three/Solution.java
index 9b83f3ba3..bce7ba09a 100644
--- a/src/main/java/g0301_0400/s0326_power_of_three/Solution.java
+++ b/src/main/java/g0301_0400/s0326_power_of_three/Solution.java
@@ -1,7 +1,6 @@
package g0301_0400.s0326_power_of_three;
-// #Easy #Top_Interview_Questions #Math #Recursion
-// #2022_07_09_Time_18_ms_(85.35%)_Space_47.9_MB_(14.68%)
+// #Easy #Math #Recursion #2022_07_09_Time_18_ms_(85.35%)_Space_47.9_MB_(14.68%)
public class Solution {
// regular method that has a loop
diff --git a/src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java b/src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java
index 51fe31810..ea997f1ca 100644
--- a/src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java
+++ b/src/main/java/g0301_0400/s0328_odd_even_linked_list/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0328_odd_even_linked_list;
-// #Medium #Top_Interview_Questions #Linked_List #Level_2_Day_4_Linked_List #Udemy_Linked_List
+// #Medium #Linked_List #LeetCode_75_LinkedList #Level_2_Day_4_Linked_List #Udemy_Linked_List
// #2022_07_09_Time_0_ms_(100.00%)_Space_44.8_MB_(44.32%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g0301_0400/s0329_longest_increasing_path_in_a_matrix/Solution.java b/src/main/java/g0301_0400/s0329_longest_increasing_path_in_a_matrix/Solution.java
index dbd7c06ac..1a2e5431b 100644
--- a/src/main/java/g0301_0400/s0329_longest_increasing_path_in_a_matrix/Solution.java
+++ b/src/main/java/g0301_0400/s0329_longest_increasing_path_in_a_matrix/Solution.java
@@ -1,7 +1,7 @@
package g0301_0400.s0329_longest_increasing_path_in_a_matrix;
-// #Hard #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search #Breadth_First_Search
-// #Graph #Memoization #Topological_Sort #2022_07_09_Time_8_ms_(97.60%)_Space_54.7_MB_(19.13%)
+// #Hard #Dynamic_Programming #Depth_First_Search #Breadth_First_Search #Graph #Memoization
+// #Topological_Sort #2022_07_09_Time_8_ms_(97.60%)_Space_54.7_MB_(19.13%)
public class Solution {
public int longestIncreasingPath(int[][] matrix) {
diff --git a/src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java b/src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java
index a418738a9..aba10e725 100644
--- a/src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java
+++ b/src/main/java/g0301_0400/s0334_increasing_triplet_subsequence/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0334_increasing_triplet_subsequence;
-// #Medium #Top_Interview_Questions #Array #Greedy #Data_Structure_II_Day_5_Array
+// #Medium #Array #Greedy #LeetCode_75_Array/String #Data_Structure_II_Day_5_Array
// #2022_07_10_Time_2_ms_(99.33%)_Space_93.5_MB_(47.20%)
public class Solution {
diff --git a/src/main/java/g0301_0400/s0338_counting_bits/Solution.java b/src/main/java/g0301_0400/s0338_counting_bits/Solution.java
index 026396d95..1fcc7035d 100644
--- a/src/main/java/g0301_0400/s0338_counting_bits/Solution.java
+++ b/src/main/java/g0301_0400/s0338_counting_bits/Solution.java
@@ -1,7 +1,8 @@
package g0301_0400.s0338_counting_bits;
-// #Easy #Top_100_Liked_Questions #Dynamic_Programming #Bit_Manipulation #Udemy_Bit_Manipulation
-// #Big_O_Time_O(num)_Space_O(num) #2022_07_10_Time_2_ms_(86.73%)_Space_48.3_MB_(31.59%)
+// #Easy #Dynamic_Programming #Bit_Manipulation #LeetCode_75_Bit_Manipulation
+// #Udemy_Bit_Manipulation #Big_O_Time_O(num)_Space_O(num)
+// #2024_11_16_Time_2_ms_(96.37%)_Space_46.4_MB_(70.53%)
public class Solution {
public int[] countBits(int num) {
diff --git a/src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java b/src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java
index bfadc4626..0ccf48315 100644
--- a/src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java
+++ b/src/main/java/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.java
@@ -1,7 +1,7 @@
package g0301_0400.s0341_flatten_nested_list_iterator;
-// #Medium #Top_Interview_Questions #Depth_First_Search #Tree #Stack #Design #Queue #Iterator
-// #Programming_Skills_II_Day_18 #2022_07_10_Time_2_ms_(99.95%)_Space_43.2_MB_(94.14%)
+// #Medium #Depth_First_Search #Tree #Stack #Design #Queue #Iterator #Programming_Skills_II_Day_18
+// #2022_07_10_Time_2_ms_(99.95%)_Space_43.2_MB_(94.14%)
import com_github_leetcode.NestedInteger;
import java.util.ArrayDeque;
diff --git a/src/main/java/g0301_0400/s0344_reverse_string/Solution.java b/src/main/java/g0301_0400/s0344_reverse_string/Solution.java
index 2fdd48866..1934ec654 100644
--- a/src/main/java/g0301_0400/s0344_reverse_string/Solution.java
+++ b/src/main/java/g0301_0400/s0344_reverse_string/Solution.java
@@ -1,7 +1,7 @@
package g0301_0400.s0344_reverse_string;
-// #Easy #Top_Interview_Questions #String #Two_Pointers #Recursion #Algorithm_I_Day_4_Two_Pointers
-// #Udemy_Strings #2022_07_11_Time_1_ms_(99.91%)_Space_54.4_MB_(64.26%)
+// #Easy #String #Two_Pointers #Recursion #Algorithm_I_Day_4_Two_Pointers #Udemy_Strings
+// #2022_07_11_Time_1_ms_(99.91%)_Space_54.4_MB_(64.26%)
public class Solution {
public void reverseString(char[] s) {
diff --git a/src/main/java/g0301_0400/s0345_reverse_vowels_of_a_string/Solution.java b/src/main/java/g0301_0400/s0345_reverse_vowels_of_a_string/Solution.java
index 70cb6a274..1baf216c9 100644
--- a/src/main/java/g0301_0400/s0345_reverse_vowels_of_a_string/Solution.java
+++ b/src/main/java/g0301_0400/s0345_reverse_vowels_of_a_string/Solution.java
@@ -1,6 +1,7 @@
package g0301_0400.s0345_reverse_vowels_of_a_string;
-// #Easy #String #Two_Pointers #2022_07_11_Time_3_ms_(98.02%)_Space_42.2_MB_(98.08%)
+// #Easy #String #Two_Pointers #LeetCode_75_Array/String
+// #2022_07_11_Time_3_ms_(98.02%)_Space_42.2_MB_(98.08%)
public class Solution {
private boolean isVowel(char c) {
diff --git a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java
index a95143c4d..f6d69f07d 100644
--- a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java
+++ b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/Solution.java
@@ -1,9 +1,8 @@
package g0301_0400.s0347_top_k_frequent_elements;
-// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting
-// #Heap_Priority_Queue #Counting #Divide_and_Conquer #Quickselect #Bucket_Sort
-// #Data_Structure_II_Day_20_Heap_Priority_Queue #Big_O_Time_O(n*log(n))_Space_O(k)
-// #2022_07_11_Time_9_ms_(97.93%)_Space_48.5_MB_(83.34%)
+// #Medium #Top_100_Liked_Questions #Array #Hash_Table #Sorting #Heap_Priority_Queue #Counting
+// #Divide_and_Conquer #Quickselect #Bucket_Sort #Data_Structure_II_Day_20_Heap_Priority_Queue
+// #Big_O_Time_O(n*log(n))_Space_O(k) #2024_11_17_Time_9_ms_(97.30%)_Space_45.4_MB_(92.52%)
import java.util.Arrays;
import java.util.PriorityQueue;
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/s0350_intersection_of_two_arrays_ii/Solution.java b/src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java
index e54dc961a..7bdc350f7 100644
--- a/src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java
+++ b/src/main/java/g0301_0400/s0350_intersection_of_two_arrays_ii/Solution.java
@@ -1,8 +1,7 @@
package g0301_0400.s0350_intersection_of_two_arrays_ii;
-// #Easy #Top_Interview_Questions #Array #Hash_Table #Sorting #Binary_Search #Two_Pointers
-// #Data_Structure_I_Day_3_Array #Binary_Search_I_Day_10
-// #2022_07_11_Time_4_ms_(69.62%)_Space_42.3_MB_(92.20%)
+// #Easy #Array #Hash_Table #Sorting #Binary_Search #Two_Pointers #Data_Structure_I_Day_3_Array
+// #Binary_Search_I_Day_10 #2022_07_11_Time_4_ms_(69.62%)_Space_42.3_MB_(92.20%)
import java.util.Arrays;
diff --git a/src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java b/src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java
index 174044cd1..0152d1afe 100644
--- a/src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java
+++ b/src/main/java/g0301_0400/s0371_sum_of_two_integers/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0371_sum_of_two_integers;
-// #Medium #Top_Interview_Questions #Math #Bit_Manipulation #Udemy_Bit_Manipulation
+// #Medium #Math #Bit_Manipulation #Udemy_Bit_Manipulation
// #2022_07_12_Time_0_ms_(100.00%)_Space_40.3_MB_(77.27%)
public class Solution {
diff --git a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.java b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.java
index 571bd700e..9ce0018fa 100644
--- a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.java
+++ b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.java
@@ -1,6 +1,7 @@
package g0301_0400.s0373_find_k_pairs_with_smallest_sums;
-// #Medium #Array #Heap_Priority_Queue #2022_07_12_Time_59_ms_(46.79%)_Space_120.7_MB_(83.25%)
+// #Medium #Array #Heap_Priority_Queue #Top_Interview_150_Heap
+// #2025_03_09_Time_27_ms_(90.23%)_Space_58.22_MB_(77.32%)
import java.util.ArrayList;
import java.util.List;
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/s0374_guess_number_higher_or_lower/Solution.java b/src/main/java/g0301_0400/s0374_guess_number_higher_or_lower/Solution.java
index fa6542fb8..f91e1e6ed 100644
--- a/src/main/java/g0301_0400/s0374_guess_number_higher_or_lower/Solution.java
+++ b/src/main/java/g0301_0400/s0374_guess_number_higher_or_lower/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0374_guess_number_higher_or_lower;
-// #Easy #Binary_Search #Interactive #Binary_Search_I_Day_1
+// #Easy #Binary_Search #Interactive #LeetCode_75_Binary_Search #Binary_Search_I_Day_1
// #2022_07_12_Time_0_ms_(100.00%)_Space_40.4_MB_(74.20%)
/*
diff --git a/src/main/java/g0301_0400/s0378_kth_smallest_element_in_a_sorted_matrix/Solution.java b/src/main/java/g0301_0400/s0378_kth_smallest_element_in_a_sorted_matrix/Solution.java
index ebe3d632a..545c5780d 100644
--- a/src/main/java/g0301_0400/s0378_kth_smallest_element_in_a_sorted_matrix/Solution.java
+++ b/src/main/java/g0301_0400/s0378_kth_smallest_element_in_a_sorted_matrix/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0378_kth_smallest_element_in_a_sorted_matrix;
-// #Medium #Top_Interview_Questions #Array #Sorting #Binary_Search #Matrix #Heap_Priority_Queue
+// #Medium #Array #Sorting #Binary_Search #Matrix #Heap_Priority_Queue
// #2022_07_13_Time_1_ms_(92.14%)_Space_58_MB_(9.74%)
public class Solution {
diff --git a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java
index a739d24ec..fd746e001 100644
--- a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java
+++ b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.java
@@ -1,7 +1,7 @@
package g0301_0400.s0380_insert_delete_getrandom_o1;
-// #Medium #Top_Interview_Questions #Array #Hash_Table #Math #Design #Randomized
-// #Programming_Skills_II_Day_20 #2022_07_13_Time_27_ms_(93.44%)_Space_92.2_MB_(91.11%)
+// #Medium #Array #Hash_Table #Math #Design #Randomized #Programming_Skills_II_Day_20
+// #Top_Interview_150_Array/String #2022_07_13_Time_27_ms_(93.44%)_Space_92.2_MB_(91.11%)
import java.util.ArrayList;
import java.util.HashMap;
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/Solution.java b/src/main/java/g0301_0400/s0383_ransom_note/Solution.java
index a127b9c51..429e5b1e5 100644
--- a/src/main/java/g0301_0400/s0383_ransom_note/Solution.java
+++ b/src/main/java/g0301_0400/s0383_ransom_note/Solution.java
@@ -1,7 +1,7 @@
package g0301_0400.s0383_ransom_note;
-// #Easy #String #Hash_Table #Counting #Data_Structure_I_Day_6_String
-// #2022_07_13_Time_1_ms_(99.97%)_Space_46_MB_(62.86%)
+// #Easy #String #Hash_Table #Counting #Data_Structure_I_Day_6_String #Top_Interview_150_Hashmap
+// #2025_03_09_Time_1_ms_(99.10%)_Space_44.62_MB_(86.13%)
public class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
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/s0384_shuffle_an_array/Solution.java b/src/main/java/g0301_0400/s0384_shuffle_an_array/Solution.java
index 70aee2586..156fb276d 100644
--- a/src/main/java/g0301_0400/s0384_shuffle_an_array/Solution.java
+++ b/src/main/java/g0301_0400/s0384_shuffle_an_array/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0384_shuffle_an_array;
-// #Medium #Top_Interview_Questions #Array #Math #Randomized #Algorithm_II_Day_20_Others
+// #Medium #Array #Math #Randomized #Algorithm_II_Day_20_Others
// #2022_07_13_Time_52_ms_(91.77%)_Space_48.2_MB_(92.20%)
import java.util.Random;
diff --git a/src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java b/src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java
index 498a5e0ad..e7eb8d0f8 100644
--- a/src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java
+++ b/src/main/java/g0301_0400/s0387_first_unique_character_in_a_string/Solution.java
@@ -1,7 +1,7 @@
package g0301_0400.s0387_first_unique_character_in_a_string;
-// #Easy #Top_Interview_Questions #String #Hash_Table #Counting #Queue
-// #Data_Structure_I_Day_6_String #2022_07_13_Time_1_ms_(100.00%)_Space_42.9_MB_(86.44%)
+// #Easy #String #Hash_Table #Counting #Queue #Data_Structure_I_Day_6_String
+// #2022_07_13_Time_1_ms_(100.00%)_Space_42.9_MB_(86.44%)
public class Solution {
public int firstUniqChar(String s) {
diff --git a/src/main/java/g0301_0400/s0392_is_subsequence/Solution.java b/src/main/java/g0301_0400/s0392_is_subsequence/Solution.java
index 4a926201e..7b7a92306 100644
--- a/src/main/java/g0301_0400/s0392_is_subsequence/Solution.java
+++ b/src/main/java/g0301_0400/s0392_is_subsequence/Solution.java
@@ -1,7 +1,8 @@
package g0301_0400.s0392_is_subsequence;
-// #Easy #String #Dynamic_Programming #Two_Pointers #Dynamic_Programming_I_Day_19
-// #Level_1_Day_2_String #Udemy_Two_Pointers #2022_07_13_Time_1_ms_(93.01%)_Space_42.2_MB_(32.57%)
+// #Easy #String #Dynamic_Programming #Two_Pointers #LeetCode_75_Two_Pointers
+// #Dynamic_Programming_I_Day_19 #Level_1_Day_2_String #Udemy_Two_Pointers
+// #Top_Interview_150_Two_Pointers #2025_03_09_Time_1_ms_(93.13%)_Space_41.65_MB_(37.86%)
public class Solution {
public boolean isSubsequence(String s, String t) {
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/Solution.java b/src/main/java/g0301_0400/s0394_decode_string/Solution.java
index b92aa469d..4a3790208 100644
--- a/src/main/java/g0301_0400/s0394_decode_string/Solution.java
+++ b/src/main/java/g0301_0400/s0394_decode_string/Solution.java
@@ -1,7 +1,8 @@
package g0301_0400.s0394_decode_string;
-// #Medium #Top_100_Liked_Questions #String #Stack #Recursion #Level_1_Day_14_Stack #Udemy_Strings
-// #Big_O_Time_O(n)_Space_O(n) #2022_07_15_Time_1_ms_(87.68%)_Space_41.2_MB_(83.30%)
+// #Medium #Top_100_Liked_Questions #String #Stack #Recursion #LeetCode_75_Stack
+// #Level_1_Day_14_Stack #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_17_Time_0_ms_(100.00%)_Space_41.5_MB_(58.38%)
public class Solution {
private int i = 0;
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/s0395_longest_substring_with_at_least_k_repeating_characters/Solution.java b/src/main/java/g0301_0400/s0395_longest_substring_with_at_least_k_repeating_characters/Solution.java
index 70620244d..27c23db77 100644
--- a/src/main/java/g0301_0400/s0395_longest_substring_with_at_least_k_repeating_characters/Solution.java
+++ b/src/main/java/g0301_0400/s0395_longest_substring_with_at_least_k_repeating_characters/Solution.java
@@ -1,6 +1,6 @@
package g0301_0400.s0395_longest_substring_with_at_least_k_repeating_characters;
-// #Medium #Top_Interview_Questions #String #Hash_Table #Sliding_Window #Divide_and_Conquer
+// #Medium #String #Hash_Table #Sliding_Window #Divide_and_Conquer
// #2022_07_15_Time_0_ms_(100.00%)_Space_42.4_MB_(47.47%)
public class Solution {
diff --git a/src/main/java/g0301_0400/s0399_evaluate_division/Solution.java b/src/main/java/g0301_0400/s0399_evaluate_division/Solution.java
index 52dad90db..a7a47db38 100644
--- a/src/main/java/g0301_0400/s0399_evaluate_division/Solution.java
+++ b/src/main/java/g0301_0400/s0399_evaluate_division/Solution.java
@@ -1,6 +1,7 @@
package g0301_0400.s0399_evaluate_division;
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Graph #Union_Find #Shortest_Path
+// #LeetCode_75_Graphs/DFS #Top_Interview_150_Graph_General
// #2022_07_15_Time_1_ms_(99.52%)_Space_43_MB_(20.05%)
import java.util.HashMap;
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/g0301_0400/s0400_nth_digit/Solution.java b/src/main/java/g0301_0400/s0400_nth_digit/Solution.java
index f6d663caa..b206f4cf2 100644
--- a/src/main/java/g0301_0400/s0400_nth_digit/Solution.java
+++ b/src/main/java/g0301_0400/s0400_nth_digit/Solution.java
@@ -13,7 +13,7 @@ public int findNthDigit(int n) {
long count = 9;
int start = 1;
while (n > len * count) {
- n -= len * count;
+ n -= (int) (len * count);
len += 1;
count *= 10;
start *= 10;
diff --git a/src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java b/src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java
index ffea009a7..718bf550e 100644
--- a/src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java
+++ b/src/main/java/g0401_0500/s0412_fizz_buzz/Solution.java
@@ -1,6 +1,6 @@
package g0401_0500.s0412_fizz_buzz;
-// #Easy #Top_Interview_Questions #String #Math #Simulation #Udemy_Integers
+// #Easy #String #Math #Simulation #Udemy_Integers
// #2022_07_16_Time_1_ms_(100.00%)_Space_48.4_MB_(48.76%)
import java.util.ArrayList;
diff --git a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java
index 80df83ff6..4bed2751c 100644
--- a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java
+++ b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/Solution.java
@@ -1,25 +1,33 @@
package g0401_0500.s0416_partition_equal_subset_sum;
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Level_2_Day_13_Dynamic_Programming
-// #Big_O_Time_O(n*sums)_Space_O(n*sums) #2022_12_29_Time_27_ms_(94.53%)_Space_41.8_MB_(95.29%)
+// #Big_O_Time_O(n*sums)_Space_O(n*sums) #2024_11_17_Time_5_ms_(99.88%)_Space_42.2_MB_(85.79%)
public class Solution {
public boolean canPartition(int[] nums) {
- int sums = 0;
- for (int num : nums) {
- sums += num;
+ int sum = 0;
+ for (int val : nums) {
+ sum += val;
}
- if (sums % 2 == 1) {
+ if (sum % 2 != 0) {
return false;
}
- sums /= 2;
- boolean[] dp = new boolean[sums + 1];
- dp[0] = true;
- for (int num : nums) {
- for (int sum = sums; sum >= num; sum--) {
- dp[sum] = dp[sum] || dp[sum - num];
+ sum /= 2;
+ boolean[] set = new boolean[sum + 1];
+ int[] arr = new int[sum + 2];
+ int top = 0;
+ for (int val : nums) {
+ for (int i = top; i > -1; i--) {
+ int tempSum = val + arr[i];
+ if (tempSum <= sum && !set[tempSum]) {
+ if (tempSum == sum) {
+ return true;
+ }
+ set[tempSum] = true;
+ arr[++top] = tempSum;
+ }
}
}
- return dp[sums];
+ return false;
}
}
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/s0419_battleships_in_a_board/Solution.java b/src/main/java/g0401_0500/s0419_battleships_in_a_board/Solution.java
index 24fde3beb..18c246976 100644
--- a/src/main/java/g0401_0500/s0419_battleships_in_a_board/Solution.java
+++ b/src/main/java/g0401_0500/s0419_battleships_in_a_board/Solution.java
@@ -13,7 +13,7 @@ public int countBattleships(char[][] board) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (board[i][j] != '.'
- && (j <= 0 || board[i][j - 1] != 'X')
+ && (j == 0 || board[i][j - 1] != 'X')
&& (i <= 0 || board[i - 1][j] != 'X')) {
count++;
}
diff --git a/src/main/java/g0401_0500/s0427_construct_quad_tree/Solution.java b/src/main/java/g0401_0500/s0427_construct_quad_tree/Solution.java
index 25004932f..53d85ddde 100644
--- a/src/main/java/g0401_0500/s0427_construct_quad_tree/Solution.java
+++ b/src/main/java/g0401_0500/s0427_construct_quad_tree/Solution.java
@@ -1,7 +1,7 @@
package g0401_0500.s0427_construct_quad_tree;
-// #Medium #Array #Tree #Matrix #Divide_and_Conquer
-// #2022_07_16_Time_0_ms_(100.00%)_Space_42.6_MB_(89.45%)
+// #Medium #Array #Tree #Matrix #Divide_and_Conquer #Top_Interview_150_Divide_and_Conquer
+// #2025_03_09_Time_0_ms_(100.00%)_Space_44.55_MB_(62.63%)
/*
// Definition for a QuadTree node.
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/s0430_flatten_a_multilevel_doubly_linked_list/readme.md b/src/main/java/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/readme.md
index 25794212f..5f3e4790a 100644
--- a/src/main/java/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/readme.md
+++ b/src/main/java/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/readme.md
@@ -10,17 +10,17 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
**Example 1:**
-
+
**Input:** head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
**Output:** [1,2,3,7,8,11,12,9,10,4,5,6]
-**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: 
+**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: 
**Example 2:**
-
+
**Input:** head = [1,2,null,3]
@@ -31,7 +31,7 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
The multilevel linked list in the input is shown.
After flattening the multilevel linked list it becomes:
-
+
**Example 3:**
diff --git a/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java b/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java
index 873600905..aa7487154 100644
--- a/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java
+++ b/src/main/java/g0401_0500/s0432_all_oone_data_structure/AllOne.java
@@ -69,12 +69,12 @@ public void dec(String key) {
/* Returns one of the keys with maximal value. */
public String getMaxKey() {
- return tail.pre == head ? "" : (String) tail.pre.keySet.iterator().next();
+ return tail.pre == head ? "" : tail.pre.keySet.iterator().next();
}
/* Returns one of the keys with Minimal value. */
public String getMinKey() {
- return head.next == tail ? "" : (String) head.next.keySet.iterator().next();
+ return head.next == tail ? "" : head.next.keySet.iterator().next();
}
// helper function to make change on given key according to offset
diff --git a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java
index 66aae95ec..63979fcae 100644
--- a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java
+++ b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/Solution.java
@@ -1,7 +1,7 @@
package g0401_0500.s0433_minimum_genetic_mutation;
// #Medium #String #Hash_Table #Breadth_First_Search #Graph_Theory_I_Day_12_Breadth_First_Search
-// #2022_07_16_Time_1_ms_(90.95%)_Space_41.9_MB_(56.72%)
+// #Top_Interview_150_Graph_BFS #2025_03_09_Time_0_ms_(100.00%)_Space_41.65_MB_(47.68%)
import java.util.ArrayList;
import java.util.HashSet;
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/s0434_number_of_segments_in_a_string/Solution.java b/src/main/java/g0401_0500/s0434_number_of_segments_in_a_string/Solution.java
index 884835970..0faf33262 100644
--- a/src/main/java/g0401_0500/s0434_number_of_segments_in_a_string/Solution.java
+++ b/src/main/java/g0401_0500/s0434_number_of_segments_in_a_string/Solution.java
@@ -5,13 +5,13 @@
public class Solution {
public int countSegments(String s) {
s = s.trim();
- if (s.length() == 0) {
+ if (s.isEmpty()) {
return 0;
}
String[] splitted = s.split(" ");
int result = 0;
for (String value : splitted) {
- if (value.length() > 0) {
+ if (!value.isEmpty()) {
result++;
}
}
diff --git a/src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java b/src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java
index 0d1fd5e03..b87a689b7 100644
--- a/src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java
+++ b/src/main/java/g0401_0500/s0435_non_overlapping_intervals/Solution.java
@@ -1,7 +1,7 @@
package g0401_0500.s0435_non_overlapping_intervals;
-// #Medium #Array #Dynamic_Programming #Sorting #Greedy #Data_Structure_II_Day_4_Array
-// #2022_07_16_Time_96_ms_(47.37%)_Space_106.6_MB_(6.15%)
+// #Medium #Array #Dynamic_Programming #Sorting #Greedy #LeetCode_75_Intervals
+// #Data_Structure_II_Day_4_Array #2022_07_16_Time_96_ms_(47.37%)_Space_106.6_MB_(6.15%)
import java.util.Arrays;
diff --git a/src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java b/src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java
index bd3e72354..e8704b665 100644
--- a/src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java
+++ b/src/main/java/g0401_0500/s0437_path_sum_iii/Solution.java
@@ -1,9 +1,11 @@
package g0401_0500.s0437_path_sum_iii;
-// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Level_2_Day_7_Tree
-// #Big_O_Time_O(n)_Space_O(n) #2022_07_16_Time_18_ms_(45.66%)_Space_42_MB_(88.96%)
+// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree
+// #LeetCode_75_Binary_Tree/DFS #Level_2_Day_7_Tree #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_17_Time_2_ms_(100.00%)_Space_44.7_MB_(11.66%)
import com_github_leetcode.TreeNode;
+import java.util.HashMap;
/*
* Definition for a binary tree node.
@@ -21,28 +23,27 @@
* }
*/
public class Solution {
- private int count = 0;
-
public int pathSum(TreeNode root, int targetSum) {
- if (root == null) {
- return 0;
- }
- helper(root, targetSum, 0);
- pathSum(root.left, targetSum);
- pathSum(root.right, targetSum);
- return count;
+ HashMap h = new HashMap<>();
+ return dfs(root, targetSum, h, 0L);
}
- public void helper(TreeNode node, int targetSum, long currSum) {
- currSum += node.val;
- if (targetSum == currSum) {
- count++;
+ int dfs(TreeNode root, int t, HashMap h, Long cs) {
+ int s = 0;
+ if (root == null) {
+ return 0;
}
- if (node.left != null) {
- helper(node.left, targetSum, currSum);
+ Long k = cs + root.val;
+ if (k == t) {
+ s += 1;
}
- if (node.right != null) {
- helper(node.right, targetSum, currSum);
+ if (h.getOrDefault(k - t, 0) > 0) {
+ s += h.get(k - t);
}
+ h.put(k, h.getOrDefault(k, 0) + 1);
+ s += dfs(root.left, t, h, k);
+ s += dfs(root.right, t, h, k);
+ h.put(k, h.getOrDefault(k, 0) - 1);
+ return s;
}
}
diff --git a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java
index 0d5cdf362..f212b542e 100644
--- a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java
+++ b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java
@@ -3,7 +3,7 @@
// #Medium #Top_100_Liked_Questions #String #Hash_Table #Sliding_Window
// #Algorithm_II_Day_5_Sliding_Window #Programming_Skills_II_Day_12
// #Level_1_Day_12_Sliding_Window/Two_Pointer #Big_O_Time_O(n+m)_Space_O(1)
-// #2022_07_16_Time_6_ms_(99.03%)_Space_47.9_MB_(50.50%)
+// #2024_11_17_Time_3_ms_(99.83%)_Space_44.7_MB_(74.83%)
import java.util.ArrayList;
import java.util.List;
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/g0401_0500/s0443_string_compression/Solution.java b/src/main/java/g0401_0500/s0443_string_compression/Solution.java
index 696137bb6..fdd5ef7d7 100644
--- a/src/main/java/g0401_0500/s0443_string_compression/Solution.java
+++ b/src/main/java/g0401_0500/s0443_string_compression/Solution.java
@@ -1,6 +1,7 @@
package g0401_0500.s0443_string_compression;
-// #Medium #String #Two_Pointers #2022_07_16_Time_2_ms_(65.35%)_Space_44.8_MB_(14.78%)
+// #Medium #String #Two_Pointers #LeetCode_75_Array/String
+// #2022_07_16_Time_2_ms_(65.35%)_Space_44.8_MB_(14.78%)
public class Solution {
/* This is breaking the rules, it's not in-place. */
diff --git a/src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java b/src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java
index 3f728c723..a611a2fe4 100644
--- a/src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java
+++ b/src/main/java/g0401_0500/s0450_delete_node_in_a_bst/Solution.java
@@ -1,7 +1,7 @@
package g0401_0500.s0450_delete_node_in_a_bst;
-// #Medium #Tree #Binary_Tree #Binary_Search_Tree #Data_Structure_II_Day_16_Tree
-// #2022_07_18_Time_0_ms_(100.00%)_Space_50.2_MB_(16.59%)
+// #Medium #Tree #Binary_Tree #Binary_Search_Tree #LeetCode_75_Binary_Search_Tree
+// #Data_Structure_II_Day_16_Tree #2022_07_18_Time_0_ms_(100.00%)_Space_50.2_MB_(16.59%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java b/src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java
index a36a38a5b..85e598d31 100644
--- a/src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java
+++ b/src/main/java/g0401_0500/s0451_sort_characters_by_frequency/Solution.java
@@ -27,9 +27,7 @@ public String frequencySort(String s) {
for (Map.Entry> freq : reverseMap.entrySet()) {
List list = reverseMap.get(freq.getKey());
for (char c : list) {
- for (int i = 0; i < freq.getKey(); i++) {
- sb.append(c);
- }
+ sb.append(String.valueOf(c).repeat(Math.max(0, freq.getKey())));
}
}
return sb.toString();
diff --git a/src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/Solution.java b/src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/Solution.java
index 5175100df..27c4cb274 100644
--- a/src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/Solution.java
+++ b/src/main/java/g0401_0500/s0452_minimum_number_of_arrows_to_burst_balloons/Solution.java
@@ -1,6 +1,7 @@
package g0401_0500.s0452_minimum_number_of_arrows_to_burst_balloons;
-// #Medium #Array #Sorting #Greedy #2022_07_18_Time_84_ms_(71.26%)_Space_100.7_MB_(21.68%)
+// #Medium #Array #Sorting #Greedy #LeetCode_75_Intervals #Top_Interview_150_Intervals
+// #2025_03_09_Time_52_ms_(89.91%)_Space_68.86_MB_(77.92%)
import java.util.Arrays;
diff --git a/src/main/java/g0401_0500/s0454_4sum_ii/Solution.java b/src/main/java/g0401_0500/s0454_4sum_ii/Solution.java
index cb6488011..c76fcfacf 100644
--- a/src/main/java/g0401_0500/s0454_4sum_ii/Solution.java
+++ b/src/main/java/g0401_0500/s0454_4sum_ii/Solution.java
@@ -1,7 +1,6 @@
package g0401_0500.s0454_4sum_ii;
-// #Medium #Top_Interview_Questions #Array #Hash_Table
-// #2022_07_18_Time_133_ms_(95.19%)_Space_42.4_MB_(88.53%)
+// #Medium #Array #Hash_Table #2022_07_18_Time_133_ms_(95.19%)_Space_42.4_MB_(88.53%)
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/java/g0401_0500/s0468_validate_ip_address/Solution.java b/src/main/java/g0401_0500/s0468_validate_ip_address/Solution.java
index 24bca9480..0ad76f4c3 100644
--- a/src/main/java/g0401_0500/s0468_validate_ip_address/Solution.java
+++ b/src/main/java/g0401_0500/s0468_validate_ip_address/Solution.java
@@ -6,7 +6,7 @@ public class Solution {
private static final String NEITHER = "Neither";
public String validIPAddress(String ip) {
- if (ip.length() == 0) {
+ if (ip.isEmpty()) {
return NEITHER;
}
String[] arr = ip.split("\\.", -1);
@@ -24,7 +24,7 @@ public String validIPAddress(String ip) {
return "IPv4";
} else if (arr1.length == 8) {
for (String num : arr1) {
- if (num.length() < 1 || num.length() > 4) {
+ if (num.isEmpty() || num.length() > 4) {
return NEITHER;
}
for (int j = 0; j < num.length(); j++) {
diff --git a/src/main/java/g0401_0500/s0488_zuma_game/Solution.java b/src/main/java/g0401_0500/s0488_zuma_game/Solution.java
index 4322e2e5b..d2947de07 100644
--- a/src/main/java/g0401_0500/s0488_zuma_game/Solution.java
+++ b/src/main/java/g0401_0500/s0488_zuma_game/Solution.java
@@ -16,10 +16,10 @@ private int dfs(String board, String hand) {
}
private int findMinStepDp(String board, String hand, Map> dp) {
- if (board.length() == 0) {
+ if (board.isEmpty()) {
return 0;
}
- if (hand.length() == 0) {
+ if (hand.isEmpty()) {
return -1;
}
if (dp.get(board) != null && dp.get(board).get(hand) != null) {
diff --git a/src/main/java/g0401_0500/s0494_target_sum/Solution.java b/src/main/java/g0401_0500/s0494_target_sum/Solution.java
index bcda7efcb..71f6176b8 100644
--- a/src/main/java/g0401_0500/s0494_target_sum/Solution.java
+++ b/src/main/java/g0401_0500/s0494_target_sum/Solution.java
@@ -1,38 +1,44 @@
package g0401_0500.s0494_target_sum;
-// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Backtracking
-// #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s))
-// #2022_07_21_Time_9_ms_(79.99%)_Space_45.2_MB_(32.79%)
+// #Medium #Array #Dynamic_Programming #Backtracking #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s))
+// #2024_11_17_Time_4_ms_(92.28%)_Space_42.7_MB_(57.04%)
public class Solution {
- public int findTargetSumWays(int[] nums, int s) {
- int sum = 0;
- s = Math.abs(s);
+ public int findTargetSumWays(int[] nums, int target) {
+ int totalSum = 0;
for (int num : nums) {
- sum += num;
+ totalSum += num;
}
- // Invalid s, just return 0
- if (s > sum || (sum + s) % 2 != 0) {
+ int sum = totalSum - target;
+ if (sum < 0 || sum % 2 == 1) {
return 0;
}
- int[][] dp = new int[(sum + s) / 2 + 1][nums.length + 1];
- dp[0][0] = 1;
- // empty knapsack must be processed specially
- for (int i = 0; i < nums.length; i++) {
- if (nums[i] == 0) {
- dp[0][i + 1] = dp[0][i] * 2;
- } else {
- dp[0][i + 1] = dp[0][i];
- }
+ return solve(nums, sum / 2);
+ }
+
+ private int solve(int[] nums, int target) {
+ int[] prev = new int[target + 1];
+ if (nums[0] == 0) {
+ prev[0] = 2;
+ } else {
+ prev[0] = 1;
+ }
+ if (nums[0] != 0 && nums[0] <= target) {
+ prev[nums[0]] = 1;
}
- for (int i = 1; i < dp.length; i++) {
- for (int j = 0; j < nums.length; j++) {
- dp[i][j + 1] += dp[i][j];
- if (nums[j] <= i) {
- dp[i][j + 1] += dp[i - nums[j]][j];
+ int n = nums.length;
+ for (int i = 1; i < n; i++) {
+ int[] curr = new int[target + 1];
+ for (int j = 0; j <= target; j++) {
+ int taken = 0;
+ if (j >= nums[i]) {
+ taken = prev[j - nums[i]];
}
+ int nonTaken = prev[j];
+ curr[j] = taken + nonTaken;
}
+ prev = curr;
}
- return dp[(sum + s) / 2][nums.length];
+ return prev[target];
}
}
diff --git a/src/main/java/g0501_0600/s0502_ipo/Solution.java b/src/main/java/g0501_0600/s0502_ipo/Solution.java
index e7762a235..8c901247c 100644
--- a/src/main/java/g0501_0600/s0502_ipo/Solution.java
+++ b/src/main/java/g0501_0600/s0502_ipo/Solution.java
@@ -1,7 +1,7 @@
package g0501_0600.s0502_ipo;
-// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue
-// #2022_07_24_Time_51_ms_(89.62%)_Space_101.7_MB_(47.03%)
+// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue #Top_Interview_150_Heap
+// #2025_03_09_Time_64_ms_(97.22%)_Space_59.96_MB_(87.77%)
import java.util.Comparator;
import java.util.PriorityQueue;
diff --git a/src/main/java/g0501_0600/s0520_detect_capital/Solution.java b/src/main/java/g0501_0600/s0520_detect_capital/Solution.java
index 39fc4ff7a..1883c5de9 100644
--- a/src/main/java/g0501_0600/s0520_detect_capital/Solution.java
+++ b/src/main/java/g0501_0600/s0520_detect_capital/Solution.java
@@ -4,7 +4,7 @@
public class Solution {
public boolean detectCapitalUse(String word) {
- if (word == null || word.length() == 0) {
+ if (word == null || word.isEmpty()) {
return false;
}
int upper = 0;
diff --git a/src/main/java/g0501_0600/s0530_minimum_absolute_difference_in_bst/Solution.java b/src/main/java/g0501_0600/s0530_minimum_absolute_difference_in_bst/Solution.java
index b09f8ec4e..efed52b0d 100644
--- a/src/main/java/g0501_0600/s0530_minimum_absolute_difference_in_bst/Solution.java
+++ b/src/main/java/g0501_0600/s0530_minimum_absolute_difference_in_bst/Solution.java
@@ -1,7 +1,7 @@
package g0501_0600.s0530_minimum_absolute_difference_in_bst;
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Binary_Search_Tree
-// #2022_07_28_Time_1_ms_(92.05%)_Space_45_MB_(70.03%)
+// #Top_Interview_150_Binary_Search_Tree #2025_03_09_Time_0_ms_(100.00%)_Space_44.75_MB_(31.94%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java b/src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java
index 670040dac..e2c4f66e7 100644
--- a/src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java
+++ b/src/main/java/g0501_0600/s0543_diameter_of_binary_tree/Solution.java
@@ -2,7 +2,7 @@
// #Easy #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Level_2_Day_7_Tree
// #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
-// #2022_08_02_Time_1_ms_(65.86%)_Space_43.5_MB_(33.52%)
+// #2024_11_17_Time_0_ms_(100.00%)_Space_44.5_MB_(74.23%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java b/src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java
index adfaca778..19e55c8b1 100644
--- a/src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java
+++ b/src/main/java/g0501_0600/s0547_number_of_provinces/Solution.java
@@ -1,6 +1,6 @@
package g0501_0600.s0547_number_of_provinces;
-// #Medium #Depth_First_Search #Breadth_First_Search #Graph #Union_Find
+// #Medium #Depth_First_Search #Breadth_First_Search #Graph #Union_Find #LeetCode_75_Graphs/DFS
// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_8_Standard_Traversal #Level_2_Day_19_Union_Find
// #2022_08_02_Time_2_ms_(69.51%)_Space_54.2_MB_(42.16%)
diff --git a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java
index 050e6901e..dfd79635b 100644
--- a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java
+++ b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/Solution.java
@@ -1,7 +1,7 @@
package g0501_0600.s0560_subarray_sum_equals_k;
// #Medium #Top_100_Liked_Questions #Array #Hash_Table #Prefix_Sum #Data_Structure_II_Day_5_Array
-// #Big_O_Time_O(n)_Space_O(n) #2022_08_03_Time_21_ms_(98.97%)_Space_46.8_MB_(88.27%)
+// #Big_O_Time_O(n)_Space_O(n) #2024_11_17_Time_22_ms_(95.17%)_Space_47.2_MB_(6.13%)
import java.util.HashMap;
import java.util.Map;
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/g0501_0600/s0572_subtree_of_another_tree/Solution.java b/src/main/java/g0501_0600/s0572_subtree_of_another_tree/Solution.java
index 87f0edac7..5493c77c1 100644
--- a/src/main/java/g0501_0600/s0572_subtree_of_another_tree/Solution.java
+++ b/src/main/java/g0501_0600/s0572_subtree_of_another_tree/Solution.java
@@ -2,7 +2,7 @@
// #Easy #Depth_First_Search #Tree #Binary_Tree #Hash_Function #String_Matching
// #Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search
-// #2022_08_10_Time_1_ms_(100.00%)_Space_47.2_MB_(13.44%)
+// #2024_10_11_Time_2_ms_(97.06%)_Space_44.2_MB_(68.85%)
import com_github_leetcode.TreeNode;
@@ -22,29 +22,29 @@
* }
*/
public class Solution {
- private boolean isSubtreeFound(TreeNode root, TreeNode subRoot) {
- if (root == null && subRoot == null) {
+ public boolean isSubtree(TreeNode root, TreeNode subRoot) {
+ if (root == null) {
+ return false;
+ }
+ if (traverse(root, subRoot)) {
return true;
}
- if (root == null || subRoot == null) {
+ return isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot);
+ }
+
+ private boolean traverse(TreeNode root, TreeNode subRoot) {
+ if (root == null && subRoot != null) {
return false;
}
- if (root.val == subRoot.val) {
- return isSubtreeFound(root.left, subRoot.left) && isSubtree(root.right, subRoot.right);
- } else {
+ if (root != null && subRoot == null) {
return false;
}
- }
-
- public boolean isSubtree(TreeNode root, TreeNode subRoot) {
- if (root == null && subRoot == null) {
+ if (root == null) {
return true;
}
- if (root == null || subRoot == null) {
+ if (root.val != subRoot.val) {
return false;
}
- return isSubtreeFound(root, subRoot)
- || isSubtree(root.left, subRoot)
- || isSubtree(root.right, subRoot);
+ return traverse(root.left, subRoot.left) && traverse(root.right, subRoot.right);
}
}
diff --git a/src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java b/src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java
index 9e5c28991..124fbcf7d 100644
--- a/src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java
+++ b/src/main/java/g0601_0700/s0605_can_place_flowers/Solution.java
@@ -1,6 +1,7 @@
package g0601_0700.s0605_can_place_flowers;
-// #Easy #Array #Greedy #Udemy_Arrays #2022_03_21_Time_1_ms_(96.77%)_Space_51.2_MB_(61.33%)
+// #Easy #Array #Greedy #LeetCode_75_Array/String #Udemy_Arrays
+// #2022_03_21_Time_1_ms_(96.77%)_Space_51.2_MB_(61.33%)
public class Solution {
public boolean canPlaceFlowers(int[] flowerbed, int n) {
diff --git a/src/main/java/g0601_0700/s0606_construct_string_from_binary_tree/Solution.java b/src/main/java/g0601_0700/s0606_construct_string_from_binary_tree/Solution.java
index f0562491e..fb5a5a268 100644
--- a/src/main/java/g0601_0700/s0606_construct_string_from_binary_tree/Solution.java
+++ b/src/main/java/g0601_0700/s0606_construct_string_from_binary_tree/Solution.java
@@ -1,6 +1,6 @@
package g0601_0700.s0606_construct_string_from_binary_tree;
-// #Easy #String #Depth_First_Search #Tree #Binary_Tree
+// #Medium #String #Depth_First_Search #Tree #Binary_Tree
// #2022_03_21_Time_1_ms_(100.00%)_Space_42.3_MB_(91.51%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0601_0700/s0620_not_boring_movies/script.sql b/src/main/java/g0601_0700/s0620_not_boring_movies/script.sql
index 07498b6ce..3d77c150c 100644
--- a/src/main/java/g0601_0700/s0620_not_boring_movies/script.sql
+++ b/src/main/java/g0601_0700/s0620_not_boring_movies/script.sql
@@ -1,7 +1,6 @@
# Write your MySQL query statement below
-# #Easy #Database #2022_03_21_Time_258_ms_(28.33%)_Space_0B_(100.00%)
-SELECT *
-FROM cinema
-WHERE description != 'boring'
-AND ID % 2 = 1
-ORDER BY rating desc;
+# #Easy #Database #2025_04_23_Time_259_ms_(64.69%)_Space_0.0_MB_(100.00%)
+SELECT id, movie, description, rating
+FROM Cinema
+WHERE description != 'boring' AND id % 2 != 0
+ORDER BY rating DESC;
diff --git a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/Solution.java b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/Solution.java
index 5b641428b..c29433dec 100644
--- a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/Solution.java
+++ b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/Solution.java
@@ -1,7 +1,7 @@
package g0601_0700.s0637_average_of_levels_in_binary_tree;
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
-// #2022_03_21_Time_2_ms_(89.32%)_Space_44.7_MB_(77.73%)
+// #Top_Interview_150_Binary_Tree_BFS #2025_03_09_Time_2_ms_(94.34%)_Space_45.93_MB_(25.94%)
import com_github_leetcode.TreeNode;
import java.util.ArrayList;
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/g0601_0700/s0643_maximum_average_subarray_i/Solution.java b/src/main/java/g0601_0700/s0643_maximum_average_subarray_i/Solution.java
index 057eff8a6..b460dbe53 100644
--- a/src/main/java/g0601_0700/s0643_maximum_average_subarray_i/Solution.java
+++ b/src/main/java/g0601_0700/s0643_maximum_average_subarray_i/Solution.java
@@ -1,6 +1,7 @@
package g0601_0700.s0643_maximum_average_subarray_i;
-// #Easy #Array #Sliding_Window #2022_03_21_Time_5_ms_(74.81%)_Space_58.3_MB_(84.86%)
+// #Easy #Array #Sliding_Window #LeetCode_75_Sliding_Window
+// #2022_03_21_Time_5_ms_(74.81%)_Space_58.3_MB_(84.86%)
public class Solution {
public double findMaxAverage(int[] nums, int k) {
diff --git a/src/main/java/g0601_0700/s0647_palindromic_substrings/Solution.java b/src/main/java/g0601_0700/s0647_palindromic_substrings/Solution.java
index cd00af5a6..aaf35c22f 100644
--- a/src/main/java/g0601_0700/s0647_palindromic_substrings/Solution.java
+++ b/src/main/java/g0601_0700/s0647_palindromic_substrings/Solution.java
@@ -1,7 +1,7 @@
package g0601_0700.s0647_palindromic_substrings;
-// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n)
-// #2022_03_21_Time_2_ms_(98.77%)_Space_41.7_MB_(75.10%)
+// #Medium #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n)
+// #2024_11_17_Time_2_ms_(99.31%)_Space_41.4_MB_(77.04%)
public class Solution {
private void expand(char[] a, int l, int r, int[] res) {
diff --git a/src/main/java/g0601_0700/s0649_dota2_senate/Solution.java b/src/main/java/g0601_0700/s0649_dota2_senate/Solution.java
index a39fc93a3..5fbdbf08d 100644
--- a/src/main/java/g0601_0700/s0649_dota2_senate/Solution.java
+++ b/src/main/java/g0601_0700/s0649_dota2_senate/Solution.java
@@ -1,6 +1,7 @@
package g0601_0700.s0649_dota2_senate;
-// #Medium #String #Greedy #Queue #2022_03_21_Time_4_ms_(95.00%)_Space_41.8_MB_(93.75%)
+// #Medium #String #Greedy #Queue #LeetCode_75_Queue
+// #2022_03_21_Time_4_ms_(95.00%)_Space_41.8_MB_(93.75%)
public class Solution {
public String predictPartyVictory(String senate) {
diff --git a/src/main/java/g0601_0700/s0664_strange_printer/Solution.java b/src/main/java/g0601_0700/s0664_strange_printer/Solution.java
index 659fb0c2d..06ed9385f 100644
--- a/src/main/java/g0601_0700/s0664_strange_printer/Solution.java
+++ b/src/main/java/g0601_0700/s0664_strange_printer/Solution.java
@@ -4,7 +4,7 @@
public class Solution {
public int strangePrinter(String s) {
- if (s.length() == 0) {
+ if (s.isEmpty()) {
return 0;
}
int[][] dp = new int[s.length()][s.length()];
diff --git a/src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java b/src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java
index ad3572923..9ced313cb 100644
--- a/src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java
+++ b/src/main/java/g0601_0700/s0700_search_in_a_binary_search_tree/Solution.java
@@ -1,7 +1,7 @@
package g0601_0700.s0700_search_in_a_binary_search_tree;
-// #Easy #Tree #Binary_Tree #Binary_Search_Tree #Data_Structure_I_Day_13_Tree
-// #2022_03_22_Time_0_ms_(100.00%)_Space_52.3_MB_(6.38%)
+// #Easy #Tree #Binary_Tree #Binary_Search_Tree #LeetCode_75_Binary_Search_Tree
+// #Data_Structure_I_Day_13_Tree #2022_03_22_Time_0_ms_(100.00%)_Space_52.3_MB_(6.38%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java b/src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java
index 19213f2a3..a2ddf2b8d 100644
--- a/src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java
+++ b/src/main/java/g0701_0800/s0706_design_hashmap/MyHashMap.java
@@ -7,7 +7,7 @@
@SuppressWarnings("unchecked")
public class MyHashMap {
- private ArrayList[] arr = null;
+ private final ArrayList[] arr;
public MyHashMap() {
arr = new ArrayList[1000];
diff --git a/src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java b/src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java
index 24005f1e5..1d5cf006c 100644
--- a/src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java
+++ b/src/main/java/g0701_0800/s0714_best_time_to_buy_and_sell_stock_with_transaction_fee/Solution.java
@@ -1,7 +1,7 @@
package g0701_0800.s0714_best_time_to_buy_and_sell_stock_with_transaction_fee;
-// #Medium #Array #Dynamic_Programming #Greedy #Dynamic_Programming_I_Day_8
-// #2022_03_24_Time_4_ms_(78.57%)_Space_75.9_MB_(33.27%)
+// #Medium #Array #Dynamic_Programming #Greedy #LeetCode_75_DP/Multidimensional
+// #Dynamic_Programming_I_Day_8 #2022_03_24_Time_4_ms_(78.57%)_Space_75.9_MB_(33.27%)
public class Solution {
public int maxProfit(int[] prices, int fee) {
diff --git a/src/main/java/g0701_0800/s0722_remove_comments/Solution.java b/src/main/java/g0701_0800/s0722_remove_comments/Solution.java
index db3d6ff9a..db09ac352 100644
--- a/src/main/java/g0701_0800/s0722_remove_comments/Solution.java
+++ b/src/main/java/g0701_0800/s0722_remove_comments/Solution.java
@@ -44,7 +44,7 @@ public List removeComments(String[] source) {
}
index++;
}
- if (sb.length() > 0 && !multiComment) {
+ if (!sb.isEmpty() && !multiComment) {
result.add(sb.toString());
sb.setLength(0);
}
diff --git a/src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java b/src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java
index 0c62116d8..8dd02e9de 100644
--- a/src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java
+++ b/src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java
@@ -1,6 +1,6 @@
package g0701_0800.s0724_find_pivot_index;
-// #Easy #Array #Prefix_Sum #Level_1_Day_1_Prefix_Sum
+// #Easy #Array #Prefix_Sum #LeetCode_75_Prefix_Sum #Level_1_Day_1_Prefix_Sum
// #2022_03_24_Time_2_ms_(69.67%)_Space_52.1_MB_(59.19%)
public class Solution {
diff --git a/src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java b/src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java
index d600bbdaa..c2a9ed6cf 100644
--- a/src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java
+++ b/src/main/java/g0701_0800/s0735_asteroid_collision/Solution.java
@@ -1,6 +1,7 @@
package g0701_0800.s0735_asteroid_collision;
-// #Medium #Array #Stack #Level_2_Day_18_Stack #2022_03_25_Time_2_ms_(99.59%)_Space_43.1_MB_(91.77%)
+// #Medium #Array #Stack #LeetCode_75_Stack #Level_2_Day_18_Stack
+// #2022_03_25_Time_2_ms_(99.59%)_Space_43.1_MB_(91.77%)
import java.util.Deque;
import java.util.LinkedList;
diff --git a/src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java b/src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java
index e272286b6..7660afb50 100644
--- a/src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java
+++ b/src/main/java/g0701_0800/s0739_daily_temperatures/Solution.java
@@ -1,7 +1,8 @@
package g0701_0800.s0739_daily_temperatures;
-// #Medium #Top_100_Liked_Questions #Array #Stack #Monotonic_Stack #Programming_Skills_II_Day_6
-// #Big_O_Time_O(n)_Space_O(n) #2022_03_25_Time_10_ms_(94.99%)_Space_118.3_MB_(70.21%)
+// #Medium #Top_100_Liked_Questions #Array #Stack #Monotonic_Stack #LeetCode_75_Monotonic_Stack
+// #Programming_Skills_II_Day_6 #Big_O_Time_O(n)_Space_O(n)
+// #2024_11_17_Time_8_ms_(96.83%)_Space_60.6_MB_(55.93%)
@SuppressWarnings("java:S135")
public class Solution {
diff --git a/src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java b/src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java
index 130c898d9..7104d2892 100644
--- a/src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java
+++ b/src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java
@@ -1,6 +1,6 @@
package g0701_0800.s0746_min_cost_climbing_stairs;
-// #Easy #Array #Dynamic_Programming #Dynamic_Programming_I_Day_2
+// #Easy #Array #Dynamic_Programming #LeetCode_75_DP/1D #Dynamic_Programming_I_Day_2
// #Level_1_Day_11_Dynamic_Programming #2022_03_25_Time_1_ms_(86.38%)_Space_43.6_MB_(54.14%)
public class Solution {
diff --git a/src/main/java/g0701_0800/s0753_cracking_the_safe/Solution.java b/src/main/java/g0701_0800/s0753_cracking_the_safe/Solution.java
index b1614575c..64eab3ed1 100644
--- a/src/main/java/g0701_0800/s0753_cracking_the_safe/Solution.java
+++ b/src/main/java/g0701_0800/s0753_cracking_the_safe/Solution.java
@@ -12,9 +12,7 @@ public String crackSafe(int n, int k) {
visited[0] = true;
int visitedCnt = 1;
StringBuilder crackStr = new StringBuilder();
- for (int i = 0; i < n; i++) {
- crackStr.append('0');
- }
+ crackStr.append("0".repeat(Math.max(0, n)));
dfsAddPwd(n, k, crackStr, 0, visited, visitedCnt, targetCnt);
return foundStr;
}
diff --git a/src/main/java/g0701_0800/s0761_special_binary_string/Solution.java b/src/main/java/g0701_0800/s0761_special_binary_string/Solution.java
index fa546d3c5..7ec9c8232 100644
--- a/src/main/java/g0701_0800/s0761_special_binary_string/Solution.java
+++ b/src/main/java/g0701_0800/s0761_special_binary_string/Solution.java
@@ -6,7 +6,7 @@
public class Solution {
public String makeLargestSpecial(String s) {
- if (s == null || s.length() == 0 || s.length() == 2) {
+ if (s == null || s.isEmpty() || s.length() == 2) {
return s;
}
PriorityQueue pq = new PriorityQueue<>((a, b) -> b.compareTo(a));
@@ -32,7 +32,7 @@ public String makeLargestSpecial(String s) {
while (!pq.isEmpty()) {
ans.append(pq.poll());
}
- if (ans.length() == 0) {
+ if (ans.isEmpty()) {
ans.append('1');
ans.append(makeLargestSpecial(s.substring(1, s.length() - 1)));
ans.append('0');
diff --git a/src/main/java/g0701_0800/s0763_partition_labels/Solution.java b/src/main/java/g0701_0800/s0763_partition_labels/Solution.java
index 26442e97d..c5594c5c9 100644
--- a/src/main/java/g0701_0800/s0763_partition_labels/Solution.java
+++ b/src/main/java/g0701_0800/s0763_partition_labels/Solution.java
@@ -2,7 +2,7 @@
// #Medium #Top_100_Liked_Questions #String #Hash_Table #Greedy #Two_Pointers
// #Data_Structure_II_Day_7_String #Big_O_Time_O(n)_Space_O(1)
-// #2022_03_26_Time_1_ms_(100.00%)_Space_40.3_MB_(98.19%)
+// #2024_11_17_Time_2_ms_(100.00%)_Space_41.9_MB_(73.06%)
import java.util.ArrayList;
import java.util.List;
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/g0701_0800/s0770_basic_calculator_iv/Solution.java b/src/main/java/g0701_0800/s0770_basic_calculator_iv/Solution.java
index 15e2fb65c..6faa2f1ea 100644
--- a/src/main/java/g0701_0800/s0770_basic_calculator_iv/Solution.java
+++ b/src/main/java/g0701_0800/s0770_basic_calculator_iv/Solution.java
@@ -1,7 +1,7 @@
package g0701_0800.s0770_basic_calculator_iv;
// #Hard #String #Hash_Table #Math #Stack #Recursion
-// #2022_04_30_Time_8_ms_(96.92%)_Space_42.9_MB_(93.85%)
+// #2025_04_18_Time_8_ms_(95.70%)_Space_44.97_MB_(82.80%)
import java.util.ArrayList;
import java.util.Collections;
diff --git a/src/main/java/g0701_0800/s0790_domino_and_tromino_tiling/Solution.java b/src/main/java/g0701_0800/s0790_domino_and_tromino_tiling/Solution.java
index 14e78598a..d23e1287f 100644
--- a/src/main/java/g0701_0800/s0790_domino_and_tromino_tiling/Solution.java
+++ b/src/main/java/g0701_0800/s0790_domino_and_tromino_tiling/Solution.java
@@ -1,6 +1,7 @@
package g0701_0800.s0790_domino_and_tromino_tiling;
-// #Medium #Dynamic_Programming #2022_03_26_Time_0_ms_(100.00%)_Space_42_MB_(14.39%)
+// #Medium #Dynamic_Programming #LeetCode_75_DP/1D
+// #2022_03_26_Time_0_ms_(100.00%)_Space_42_MB_(14.39%)
public class Solution {
public int numTilings(int n) {
diff --git a/src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java b/src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java
index 506e34ae8..b6ab889eb 100644
--- a/src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java
+++ b/src/main/java/g0801_0900/s0841_keys_and_rooms/Solution.java
@@ -1,7 +1,8 @@
package g0801_0900.s0841_keys_and_rooms;
-// #Medium #Depth_First_Search #Breadth_First_Search #Graph #Data_Structure_II_Day_19_Graph
-// #Graph_Theory_I_Day_7_Standard_Traversal #2022_03_24_Time_3_ms_(51.54%)_Space_42.3_MB_(75.53%)
+// #Medium #Depth_First_Search #Breadth_First_Search #Graph #LeetCode_75_Graphs/DFS
+// #Data_Structure_II_Day_19_Graph #Graph_Theory_I_Day_7_Standard_Traversal
+// #2022_03_24_Time_3_ms_(51.54%)_Space_42.3_MB_(75.53%)
import java.util.HashSet;
import java.util.List;
diff --git a/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java b/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java
index b7c31b09d..87faebfa2 100644
--- a/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java
+++ b/src/main/java/g0801_0900/s0843_guess_the_word/Solution.java
@@ -15,7 +15,7 @@
* }
*/
public class Solution {
- interface Master {
+ public interface Master {
int guess(String word);
}
diff --git a/src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java b/src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java
index 7ed7c6e92..83fc831f4 100644
--- a/src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java
+++ b/src/main/java/g0801_0900/s0852_peak_index_in_a_mountain_array/Solution.java
@@ -1,6 +1,6 @@
package g0801_0900.s0852_peak_index_in_a_mountain_array;
-// #Easy #Array #Binary_Search #Binary_Search_I_Day_2
+// #Medium #Array #Binary_Search #Binary_Search_I_Day_2
// #2022_03_28_Time_0_ms_(100.00%)_Space_46.1_MB_(68.36%)
public class Solution {
diff --git a/src/main/java/g0801_0900/s0869_reordered_power_of_2/Solution.java b/src/main/java/g0801_0900/s0869_reordered_power_of_2/Solution.java
index 75b21a949..72de67a77 100644
--- a/src/main/java/g0801_0900/s0869_reordered_power_of_2/Solution.java
+++ b/src/main/java/g0801_0900/s0869_reordered_power_of_2/Solution.java
@@ -1,38 +1,29 @@
package g0801_0900.s0869_reordered_power_of_2;
// #Medium #Math #Sorting #Counting #Enumeration
-// #2022_03_28_Time_9_ms_(25.97%)_Space_42.8_MB_(11.69%)
+// #2024_12_19_Time_1_ms_(89.02%)_Space_40.9_MB_(44.51%)
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.Arrays;
public class Solution {
public boolean reorderedPowerOf2(int n) {
- int i = 0;
- while (Math.pow(2, i) < (long) n * 10) {
- if (isValid(String.valueOf((int) (Math.pow(2, i++))), String.valueOf(n))) {
+ int[] originalDigits = countDigits(n);
+ int num = 1;
+ for (int i = 0; i < 31; i++) {
+ if (Arrays.equals(originalDigits, countDigits(num))) {
return true;
}
+ num <<= 1;
}
return false;
}
- private boolean isValid(String a, String b) {
- Map m = new HashMap<>();
- Map mTwo = new HashMap<>();
- for (char c : a.toCharArray()) {
- m.put(c, m.containsKey(c) ? m.get(c) + 1 : 1);
+ private int[] countDigits(int num) {
+ int[] digitCount = new int[10];
+ while (num > 0) {
+ digitCount[num % 10]++;
+ num /= 10;
}
- for (char c : b.toCharArray()) {
- mTwo.put(c, mTwo.containsKey(c) ? mTwo.get(c) + 1 : 1);
- }
- for (Map.Entry entry : mTwo.entrySet()) {
- if (!m.containsKey(entry.getKey())
- || !Objects.equals(entry.getValue(), m.get(entry.getKey()))) {
- return false;
- }
- }
- return a.charAt(0) != '0' && m.size() == mTwo.size();
+ return digitCount;
}
}
diff --git a/src/main/java/g0801_0900/s0870_advantage_shuffle/Solution.java b/src/main/java/g0801_0900/s0870_advantage_shuffle/Solution.java
index a49dca644..b22e29edd 100644
--- a/src/main/java/g0801_0900/s0870_advantage_shuffle/Solution.java
+++ b/src/main/java/g0801_0900/s0870_advantage_shuffle/Solution.java
@@ -1,59 +1,60 @@
package g0801_0900.s0870_advantage_shuffle;
-// #Medium #Array #Sorting #Greedy #2022_03_28_Time_188_ms_(28.01%)_Space_116.9_MB_(5.12%)
+// #Medium #Array #Sorting #Greedy #2024_12_19_Time_42_ms_(99.16%)_Space_56.1_MB_(94.94%)
-import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Deque;
-import java.util.HashMap;
import java.util.List;
-import java.util.PriorityQueue;
-@SuppressWarnings("java:S5413")
public class Solution {
public int[] advantageCount(int[] nums1, int[] nums2) {
- PriorityQueue pque = new PriorityQueue<>();
- for (int e : nums1) {
- pque.add(e);
- }
- int l = nums1.length;
- HashMap> map = new HashMap<>();
- int[] n = new int[l];
- System.arraycopy(nums2, 0, n, 0, l);
- Arrays.sort(n);
- Deque sta = new ArrayDeque<>();
- for (int i = 0; i < l && !pque.isEmpty(); i++) {
- List p = map.getOrDefault(n[i], new ArrayList<>());
- int x = pque.poll();
- if (x > n[i]) {
- p.add(x);
- map.put(n[i], p);
+ Arrays.sort(nums1);
+ int[] result = new int[nums1.length];
+ int low = 0;
+ boolean[] chosen = new boolean[nums1.length];
+ for (int i = 0; i < nums2.length; i++) {
+ int pos = binSearch(nums1, nums2[i], low, chosen);
+ if (pos != -1 && pos < nums1.length) {
+ result[i] = nums1[pos];
+ chosen[pos] = true;
} else {
- while (x <= n[i] && !pque.isEmpty()) {
- sta.push(x);
- x = pque.poll();
- }
- if (x > n[i]) {
- p.add(x);
- map.put(n[i], p);
- } else {
- sta.push(x);
- }
+ result[i] = -1;
}
}
- for (int i = 0; i < nums2.length; i++) {
- List p = map.getOrDefault(nums2[i], new ArrayList<>());
- int t;
- if (!p.isEmpty()) {
- t = p.get(0);
- p.remove(0);
- map.put(nums2[i], p);
+ List pos = new ArrayList<>();
+ int i = 0;
+ for (boolean ch : chosen) {
+ if (!ch) {
+ pos.add(i);
+ }
+ i++;
+ }
+ int index = 0;
+ for (i = 0; i < result.length; i++) {
+ if (result[i] == -1) {
+ result[i] = nums1[pos.get(index)];
+ index++;
+ }
+ }
+ return result;
+ }
+
+ private int binSearch(int[] nums, int target, int low, boolean[] chosen) {
+ int high = nums.length - 1;
+ while (high >= low) {
+ int mid = high - (high - low) / 2;
+ if (nums[mid] > target && (mid == 0 || nums[mid - 1] <= target)) {
+ while (mid < nums.length && chosen[mid]) {
+ mid++;
+ }
+ return mid;
+ }
+ if (nums[mid] > target) {
+ high = mid - 1;
} else {
- t = sta.pop();
+ low = mid + 1;
}
- nums1[i] = t;
}
- return nums1;
+ return -1;
}
}
diff --git a/src/main/java/g0801_0900/s0872_leaf_similar_trees/Solution.java b/src/main/java/g0801_0900/s0872_leaf_similar_trees/Solution.java
index 7f80bd695..c53a5fa8a 100644
--- a/src/main/java/g0801_0900/s0872_leaf_similar_trees/Solution.java
+++ b/src/main/java/g0801_0900/s0872_leaf_similar_trees/Solution.java
@@ -1,6 +1,6 @@
package g0801_0900.s0872_leaf_similar_trees;
-// #Easy #Depth_First_Search #Tree #Binary_Tree
+// #Easy #Depth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS
// #2022_03_28_Time_0_ms_(100.00%)_Space_41.8_MB_(64.12%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java b/src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java
index 251e862a3..60c0570aa 100644
--- a/src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java
+++ b/src/main/java/g0801_0900/s0875_koko_eating_bananas/Solution.java
@@ -1,6 +1,6 @@
package g0801_0900.s0875_koko_eating_bananas;
-// #Medium #Array #Binary_Search #Binary_Search_II_Day_4
+// #Medium #Array #Binary_Search #LeetCode_75_Binary_Search #Binary_Search_II_Day_4
// #2022_03_28_Time_15_ms_(91.32%)_Space_55_MB_(6.01%)
public class Solution {
diff --git a/src/main/java/g0801_0900/s0880_decoded_string_at_index/Solution.java b/src/main/java/g0801_0900/s0880_decoded_string_at_index/Solution.java
index fe7be9f8a..c30834aaa 100644
--- a/src/main/java/g0801_0900/s0880_decoded_string_at_index/Solution.java
+++ b/src/main/java/g0801_0900/s0880_decoded_string_at_index/Solution.java
@@ -15,7 +15,7 @@ public String decodeAtIndex(String s, int k) {
}
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
- k %= length;
+ k %= (int) length;
if (c >= 48 && c <= 57) {
length /= c - '0';
} else if (k == 0) {
diff --git a/src/main/java/g0901_1000/s0901_online_stock_span/StockSpanner.java b/src/main/java/g0901_1000/s0901_online_stock_span/StockSpanner.java
index c94be5e6a..3ebacc4c4 100644
--- a/src/main/java/g0901_1000/s0901_online_stock_span/StockSpanner.java
+++ b/src/main/java/g0901_1000/s0901_online_stock_span/StockSpanner.java
@@ -1,6 +1,6 @@
package g0901_1000.s0901_online_stock_span;
-// #Medium #Stack #Design #Monotonic_Stack #Data_Stream
+// #Medium #Stack #Design #Monotonic_Stack #Data_Stream #LeetCode_75_Monotonic_Stack
// #2022_03_28_Time_47_ms_(76.17%)_Space_88.8_MB_(5.16%)
import java.util.Deque;
diff --git a/src/main/java/g0901_1000/s0909_snakes_and_ladders/Solution.java b/src/main/java/g0901_1000/s0909_snakes_and_ladders/Solution.java
index ba3117d64..e4bbfe538 100644
--- a/src/main/java/g0901_1000/s0909_snakes_and_ladders/Solution.java
+++ b/src/main/java/g0901_1000/s0909_snakes_and_ladders/Solution.java
@@ -1,7 +1,7 @@
package g0901_1000.s0909_snakes_and_ladders;
-// #Medium #Array #Breadth_First_Search #Matrix
-// #2022_03_28_Time_7_ms_(79.52%)_Space_47.7_MB_(58.43%)
+// #Medium #Array #Breadth_First_Search #Matrix #Top_Interview_150_Graph_BFS
+// #2025_03_09_Time_4_ms_(95.81%)_Space_43.82_MB_(99.52%)
import java.util.LinkedList;
import java.util.Queue;
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
diff --git a/src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java b/src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java
index 41ef79839..7f39c58e3 100644
--- a/src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java
+++ b/src/main/java/g0901_1000/s0918_maximum_sum_circular_subarray/Solution.java
@@ -1,7 +1,8 @@
package g0901_1000.s0918_maximum_sum_circular_subarray;
// #Medium #Array #Dynamic_Programming #Divide_and_Conquer #Queue #Monotonic_Queue
-// #Dynamic_Programming_I_Day_5 #2022_03_29_Time_3_ms_(92.86%)_Space_64.3_MB_(40.27%)
+// #Dynamic_Programming_I_Day_5 #Top_Interview_150_Kadane's_Algorithm
+// #2025_03_09_Time_2_ms_(99.34%)_Space_49.52_MB_(29.39%)
public class Solution {
private int kadane(int[] nums, int sign) {
diff --git a/src/main/java/g0901_1000/s0933_number_of_recent_calls/RecentCounter.java b/src/main/java/g0901_1000/s0933_number_of_recent_calls/RecentCounter.java
index db8e07a16..82b929886 100644
--- a/src/main/java/g0901_1000/s0933_number_of_recent_calls/RecentCounter.java
+++ b/src/main/java/g0901_1000/s0933_number_of_recent_calls/RecentCounter.java
@@ -1,6 +1,7 @@
package g0901_1000.s0933_number_of_recent_calls;
-// #Easy #Design #Queue #Data_Stream #2022_03_30_Time_16_ms_(97.58%)_Space_50.8_MB_(80.12%)
+// #Easy #Design #Queue #Data_Stream #LeetCode_75_Queue
+// #2022_03_30_Time_16_ms_(97.58%)_Space_50.8_MB_(80.12%)
import java.util.LinkedList;
import java.util.Queue;
diff --git a/src/main/java/g0901_1000/s0937_reorder_data_in_log_files/Solution.java b/src/main/java/g0901_1000/s0937_reorder_data_in_log_files/Solution.java
index 8bd94b3a4..7f9cd627f 100644
--- a/src/main/java/g0901_1000/s0937_reorder_data_in_log_files/Solution.java
+++ b/src/main/java/g0901_1000/s0937_reorder_data_in_log_files/Solution.java
@@ -1,6 +1,6 @@
package g0901_1000.s0937_reorder_data_in_log_files;
-// #Easy #Array #String #Sorting #2022_03_30_Time_4_ms_(92.15%)_Space_46_MB_(66.46%)
+// #Medium #Array #String #Sorting #2022_03_30_Time_4_ms_(92.15%)_Space_46_MB_(66.46%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g0901_1000/s0972_equal_rational_numbers/Solution.java b/src/main/java/g0901_1000/s0972_equal_rational_numbers/Solution.java
index 13e8b3539..842b8c763 100644
--- a/src/main/java/g0901_1000/s0972_equal_rational_numbers/Solution.java
+++ b/src/main/java/g0901_1000/s0972_equal_rational_numbers/Solution.java
@@ -29,10 +29,6 @@ public boolean isRationalEqual(String s, String t) {
}
private String repeat(String a) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 100; i++) {
- sb.append(a);
- }
- return sb.toString();
+ return String.valueOf(a).repeat(100);
}
}
diff --git a/src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java b/src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java
index 1a0b2692f..263f7523f 100644
--- a/src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java
+++ b/src/main/java/g0901_1000/s0976_largest_perimeter_triangle/Solution.java
@@ -1,7 +1,7 @@
package g0901_1000.s0976_largest_perimeter_triangle;
// #Easy #Array #Math #Sorting #Greedy #Programming_Skills_I_Day_3_Conditional_Statements
-// #2022_03_31_Time_12_ms_(26.01%)_Space_53.8_MB_(69.91%)
+// #2024_12_19_Time_7_ms_(99.33%)_Space_45.5_MB_(8.45%)
import java.util.Arrays;
diff --git a/src/main/java/g0901_1000/s0990_satisfiability_of_equality_equations/Solution.java b/src/main/java/g0901_1000/s0990_satisfiability_of_equality_equations/Solution.java
index 5efe07d45..eef8007f5 100644
--- a/src/main/java/g0901_1000/s0990_satisfiability_of_equality_equations/Solution.java
+++ b/src/main/java/g0901_1000/s0990_satisfiability_of_equality_equations/Solution.java
@@ -1,59 +1,32 @@
package g0901_1000.s0990_satisfiability_of_equality_equations;
-// #Medium #Array #String #Graph #Union_Find #2022_03_31_Time_5_ms_(24.79%)_Space_43.5_MB_(18.67%)
-
-import java.util.HashMap;
+// #Medium #Array #String #Graph #Union_Find #2024_05_13_Time_0_ms_(100.00%)_Space_41.9_MB_(47.21%)
public class Solution {
- private int[] par;
+ private int[] parent = new int[26];
- public boolean equationsPossible(String[] equations) {
- int counter = 0;
- HashMap map = new HashMap<>();
- for (String str : equations) {
- char ch = str.charAt(0);
- if (!map.containsKey(ch)) {
- map.put(ch, counter);
- counter++;
- }
- ch = str.charAt(3);
- if (!map.containsKey(ch)) {
- map.put(ch, counter);
- counter++;
- }
+ private int find(int x) {
+ if (parent[x] == x) {
+ return x;
}
- par = new int[counter];
- for (int i = 0; i < par.length; i++) {
- par[i] = i;
+ parent[x] = find(parent[x]);
+ return parent[x];
+ }
+
+ public boolean equationsPossible(String[] equations) {
+ for (int i = 0; i < 26; i++) {
+ parent[i] = i;
}
- for (String str : equations) {
- String oper = str.substring(1, 3);
- if (oper.equals("==")) {
- int px = find(map.get(str.charAt(0)));
- int py = find(map.get(str.charAt(3)));
- if (px != py) {
- par[px] = py;
- }
+ for (String e : equations) {
+ if (e.charAt(1) == '=') {
+ parent[find(e.charAt(0) - 'a')] = find(e.charAt(3) - 'a');
}
}
- for (String str : equations) {
- String oper = str.substring(1, 3);
- if (oper.equals("!=")) {
- int px = find(map.get(str.charAt(0)));
- int py = find(map.get(str.charAt(3)));
- if (px == py) {
- return false;
- }
+ for (String e : equations) {
+ if (e.charAt(1) == '!' && find(e.charAt(0) - 'a') == find(e.charAt(3) - 'a')) {
+ return false;
}
}
return true;
}
-
- private int find(int x) {
- if (par[x] == x) {
- return x;
- }
- par[x] = find(par[x]);
- return par[x];
- }
}
diff --git a/src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java b/src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java
index a67f5a4a3..ce9a7533a 100644
--- a/src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java
+++ b/src/main/java/g0901_1000/s0994_rotting_oranges/Solution.java
@@ -1,6 +1,6 @@
package g0901_1000.s0994_rotting_oranges;
-// #Medium #Array #Breadth_First_Search #Matrix
+// #Medium #Top_100_Liked_Questions #Array #Breadth_First_Search #Matrix #LeetCode_75_Graphs/BFS
// #Algorithm_I_Day_9_Breadth_First_Search_Depth_First_Search #Level_2_Day_10_Graph/BFS/DFS
// #2022_02_17_Time_3_ms_(74.27%)_Space_42.9_MB_(18.68%)
diff --git a/src/main/java/g0901_1000/s0999_available_captures_for_rook/Solution.java b/src/main/java/g0901_1000/s0999_available_captures_for_rook/Solution.java
index e9b4f09f6..00c075b9f 100644
--- a/src/main/java/g0901_1000/s0999_available_captures_for_rook/Solution.java
+++ b/src/main/java/g0901_1000/s0999_available_captures_for_rook/Solution.java
@@ -1,97 +1,61 @@
package g0901_1000.s0999_available_captures_for_rook;
-// #Easy #Array #Matrix #Simulation #2022_03_31_Time_0_ms_(100.00%)_Space_41.8_MB_(28.74%)
+// #Easy #Array #Matrix #Simulation #2025_03_13_Time_0_ms_(100.00%)_Space_40.75_MB_(94.97%)
@SuppressWarnings("java:S135")
public class Solution {
- private int[] directions = new int[] {0, 1, 0, -1, 0};
-
public int numRookCaptures(char[][] board) {
- int m = board.length;
- int n = board[0].length;
- int rowR = -1;
- int colR = -1;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
+ // Find the position of the rook
+ int rookRow = -1;
+ int rookCol = -1;
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0; j < 8; j++) {
if (board[i][j] == 'R') {
- rowR = i;
- colR = j;
+ rookRow = i;
+ rookCol = j;
break;
}
}
- }
- int[] count = {0};
- for (int i = 0; i < 4; i++) {
- int neighborRow = rowR + directions[i];
- int neighborCol = colR + directions[i + 1];
- if (neighborRow >= 0
- && neighborRow < m
- && neighborCol >= 0
- && neighborCol < n
- && board[neighborRow][neighborCol] != 'B') {
- if (directions[i] == 0 && directions[i + 1] == 1) {
- extracted(board, n, count, neighborRow, neighborCol);
- } else if (directions[i] == 1 && directions[i + 1] == 0) {
- extracted1(board, m, count, neighborRow, neighborCol);
- } else if (directions[i] == 0 && directions[i + 1] == -1) {
- extracted(board, count, neighborRow, neighborCol);
- } else {
- extracted1(board, count, neighborRow, neighborCol);
- }
- }
- }
- return count[0];
- }
-
- private void extracted(char[][] board, int[] count, int neighborRow, int neighborCol) {
- while (neighborCol >= 0) {
- if (board[neighborRow][neighborCol] == 'p') {
- count[0]++;
- break;
- } else if (board[neighborRow][neighborCol] == 'B') {
- break;
- } else {
- neighborCol--;
- }
- }
- }
-
- private void extracted(char[][] board, int n, int[] count, int neighborRow, int neighborCol) {
- while (neighborCol < n) {
- if (board[neighborRow][neighborCol] == 'p') {
- count[0]++;
- break;
- } else if (board[neighborRow][neighborCol] == 'B') {
- break;
- } else {
- neighborCol++;
- }
- }
- }
-
- private void extracted1(char[][] board, int[] count, int neighborRow, int neighborCol) {
- while (neighborRow >= 0) {
- if (board[neighborRow][neighborCol] == 'p') {
- count[0]++;
+ if (rookRow != -1) {
break;
- } else if (board[neighborRow][neighborCol] == 'B') {
- break;
- } else {
- neighborRow--;
}
}
- }
-
- private void extracted1(char[][] board, int m, int[] count, int neighborRow, int neighborCol) {
- while (neighborRow < m) {
- if (board[neighborRow][neighborCol] == 'p') {
- count[0]++;
- break;
- } else if (board[neighborRow][neighborCol] == 'B') {
- break;
- } else {
- neighborRow++;
+ // Define the four directions: up, right, down, left
+ int[][] directions = {
+ // up
+ {-1, 0},
+ // right
+ {0, 1},
+ // down
+ {1, 0},
+ // left
+ {0, -1}
+ };
+ int captureCount = 0;
+ // Check each direction
+ for (int[] dir : directions) {
+ int row = rookRow;
+ int col = rookCol;
+ while (true) {
+ // Move one step in the current direction
+ row += dir[0];
+ col += dir[1];
+ // Check if out of bounds
+ if (row < 0 || row >= 8 || col < 0 || col >= 8) {
+ break;
+ }
+ // If we hit a bishop, we're blocked
+ if (board[row][col] == 'B') {
+ break;
+ }
+ // If we hit a pawn, we can capture it and then we're blocked
+ if (board[row][col] == 'p') {
+ captureCount++;
+ break;
+ }
+ // Otherwise (empty square), continue in the same direction
}
}
+ return captureCount;
}
}
diff --git a/src/main/java/g1001_1100/s1002_find_common_characters/Solution.java b/src/main/java/g1001_1100/s1002_find_common_characters/Solution.java
index 6e2458687..f1b2aa5bf 100644
--- a/src/main/java/g1001_1100/s1002_find_common_characters/Solution.java
+++ b/src/main/java/g1001_1100/s1002_find_common_characters/Solution.java
@@ -26,7 +26,7 @@ public List commonChars(String[] words) {
}
private String getCommon(String s1, String s2) {
- if (s1.length() == 0 || s2.length() == 0) {
+ if (s1.isEmpty() || s2.isEmpty()) {
return "";
}
int[] c1c = countChars(s1);
diff --git a/src/main/java/g1001_1100/s1004_max_consecutive_ones_iii/Solution.java b/src/main/java/g1001_1100/s1004_max_consecutive_ones_iii/Solution.java
index e1499b469..522d2e319 100644
--- a/src/main/java/g1001_1100/s1004_max_consecutive_ones_iii/Solution.java
+++ b/src/main/java/g1001_1100/s1004_max_consecutive_ones_iii/Solution.java
@@ -1,6 +1,6 @@
package g1001_1100.s1004_max_consecutive_ones_iii;
-// #Medium #Array #Binary_Search #Prefix_Sum #Sliding_Window
+// #Medium #Array #Binary_Search #Prefix_Sum #Sliding_Window #LeetCode_75_Sliding_Window
// #2022_02_27_Time_3_ms_(79.01%)_Space_68.2_MB_(65.91%)
public class Solution {
diff --git a/src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java b/src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java
index 836f64449..b71b70df1 100644
--- a/src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java
+++ b/src/main/java/g1001_1100/s1009_complement_of_base_10_integer/Solution.java
@@ -20,7 +20,7 @@ public int bitwiseComplement(int n) {
int exp = list.size() - 1;
for (int i = list.size() - 1; i >= 0; i--) {
if (list.get(i) == 0) {
- result += Math.pow(2, exp);
+ result += (int) Math.pow(2, exp);
}
exp--;
}
diff --git a/src/main/java/g1001_1100/s1012_numbers_with_repeated_digits/Solution.java b/src/main/java/g1001_1100/s1012_numbers_with_repeated_digits/Solution.java
index 58fc32905..affbacdb3 100644
--- a/src/main/java/g1001_1100/s1012_numbers_with_repeated_digits/Solution.java
+++ b/src/main/java/g1001_1100/s1012_numbers_with_repeated_digits/Solution.java
@@ -1,6 +1,6 @@
package g1001_1100.s1012_numbers_with_repeated_digits;
-// #Hard #Dynamic_Programming #Math #2022_02_25_Time_3_ms_(28.17%)_Space_41.8_MB_(7.04%)
+// #Hard #Dynamic_Programming #Math #2025_04_23_Time_2_ms_(50.64%)_Space_40.70_MB_(60.90%)
import java.util.HashSet;
diff --git a/src/main/java/g1001_1100/s1022_sum_of_root_to_leaf_binary_numbers/Solution.java b/src/main/java/g1001_1100/s1022_sum_of_root_to_leaf_binary_numbers/Solution.java
index 2a3b4fb2f..7e092fa5b 100644
--- a/src/main/java/g1001_1100/s1022_sum_of_root_to_leaf_binary_numbers/Solution.java
+++ b/src/main/java/g1001_1100/s1022_sum_of_root_to_leaf_binary_numbers/Solution.java
@@ -1,10 +1,9 @@
package g1001_1100.s1022_sum_of_root_to_leaf_binary_numbers;
-// #Easy #Depth_First_Search #Tree #Binary_Tree #2022_02_26_Time_3_ms_(28.58%)_Space_43.6_MB_(5.47%)
+// #Easy #Depth_First_Search #Tree #Binary_Tree
+// #2025_05_03_Time_0_ms_(100.00%)_Space_42.08_MB_(64.36%)
import com_github_leetcode.TreeNode;
-import java.util.ArrayList;
-import java.util.List;
/*
* Definition for a binary tree node.
@@ -23,31 +22,17 @@
*/
public class Solution {
public int sumRootToLeaf(TreeNode root) {
- List> paths = new ArrayList<>();
- dfs(root, paths, new ArrayList<>());
- int sum = 0;
- for (List list : paths) {
- int num = 0;
- for (int i : list) {
- num = (num << 1) + i;
- }
- sum += num;
- }
- return sum;
+ return sumRootToLeaf(root, 0);
}
- private void dfs(TreeNode root, List> paths, List path) {
- path.add(root.val);
- if (root.left != null) {
- dfs(root.left, paths, path);
- path.remove(path.size() - 1);
- }
- if (root.right != null) {
- dfs(root.right, paths, path);
- path.remove(path.size() - 1);
+ private int sumRootToLeaf(TreeNode root, int sum) {
+ if (root == null) {
+ return 0;
}
+ sum = 2 * sum + root.val;
if (root.left == null && root.right == null) {
- paths.add(new ArrayList<>(path));
+ return sum;
}
+ return sumRootToLeaf(root.left, sum) + sumRootToLeaf(root.right, sum);
}
}
diff --git a/src/main/java/g1001_1100/s1071_greatest_common_divisor_of_strings/Solution.java b/src/main/java/g1001_1100/s1071_greatest_common_divisor_of_strings/Solution.java
index f3a3fff8b..1cb90dd33 100644
--- a/src/main/java/g1001_1100/s1071_greatest_common_divisor_of_strings/Solution.java
+++ b/src/main/java/g1001_1100/s1071_greatest_common_divisor_of_strings/Solution.java
@@ -1,6 +1,7 @@
package g1001_1100.s1071_greatest_common_divisor_of_strings;
-// #Easy #String #Math #2022_02_27_Time_1_ms_(82.09%)_Space_42.6_MB_(33.55%)
+// #Easy #String #Math #LeetCode_75_Array/String
+// #2022_02_27_Time_1_ms_(82.09%)_Space_42.6_MB_(33.55%)
public class Solution {
public String gcdOfStrings(String str1, String str2) {
diff --git a/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java b/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java
index 448036bf0..9fea6a156 100644
--- a/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java
+++ b/src/main/java/g1001_1100/s1095_find_in_mountain_array/MountainArray.java
@@ -1,6 +1,6 @@
package g1001_1100.s1095_find_in_mountain_array;
-interface MountainArray {
+public interface MountainArray {
int get(int index);
int length();
diff --git a/src/main/java/g1101_1200/s1131_maximum_of_absolute_value_expression/Solution.java b/src/main/java/g1101_1200/s1131_maximum_of_absolute_value_expression/Solution.java
index d68812495..fb00f6f76 100644
--- a/src/main/java/g1101_1200/s1131_maximum_of_absolute_value_expression/Solution.java
+++ b/src/main/java/g1101_1200/s1131_maximum_of_absolute_value_expression/Solution.java
@@ -1,30 +1,31 @@
package g1101_1200.s1131_maximum_of_absolute_value_expression;
-// #Medium #Array #Math #2023_06_01_Time_13_ms_(24.81%)_Space_52.7_MB_(5.43%)
+// #Medium #Array #Math #2024_05_13_Time_1_ms_(100.00%)_Space_53_MB_(70.47%)
public class Solution {
- public int maxAbsValExpr(int[] arr1, int[] arr2) {
- if (arr1.length != arr2.length) {
+ private int max(int[] a1, int[] a2, int k1, int k2, int k3) {
+ int result = Integer.MIN_VALUE;
+ for (int i = 0; i < a1.length; i++) {
+ result = Math.max(result, a1[i] * k1 + a2[i] * k2 + i * k3);
+ }
+ return result;
+ }
+
+ private int min(int[] a1, int[] a2, int k1, int k2, int k3) {
+ return -max(a1, a2, -k1, -k2, -k3);
+ }
+
+ public int maxAbsValExpr(int[] a1, int[] a2) {
+ if (a1 == null || a2 == null || a1.length == 0 || a2.length == 0) {
return 0;
}
- int max1 = Integer.MIN_VALUE;
- int max2 = Integer.MIN_VALUE;
- int max3 = Integer.MIN_VALUE;
- int max4 = Integer.MIN_VALUE;
- int min1 = Integer.MAX_VALUE;
- int min2 = Integer.MAX_VALUE;
- int min3 = Integer.MAX_VALUE;
- int min4 = Integer.MAX_VALUE;
- for (int i = 0; i < arr1.length; i++) {
- max1 = Math.max(arr1[i] + arr2[i] + i, max1);
- min1 = Math.min(arr1[i] + arr2[i] + i, min1);
- max2 = Math.max(i - arr1[i] - arr2[i], max2);
- min2 = Math.min(i - arr1[i] - arr2[i], min2);
- max3 = Math.max(arr1[i] - arr2[i] + i, max3);
- min3 = Math.min(arr1[i] - arr2[i] + i, min3);
- max4 = Math.max(arr2[i] - arr1[i] + i, max4);
- min4 = Math.min(arr2[i] - arr1[i] + i, min4);
+ int result = 0;
+ int[][] ksArray = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}};
+ for (int[] ks : ksArray) {
+ int max = max(a1, a2, ks[0], ks[1], ks[2]);
+ int min = min(a1, a2, ks[0], ks[1], ks[2]);
+ result = Math.max(result, max - min);
}
- return Math.max(Math.max(max1 - min1, max2 - min2), Math.max(max3 - min3, max4 - min4));
+ return result;
}
}
diff --git a/src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java b/src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java
index f8e0b7a88..b5acb7225 100644
--- a/src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java
+++ b/src/main/java/g1101_1200/s1137_n_th_tribonacci_number/Solution.java
@@ -1,6 +1,6 @@
package g1101_1200.s1137_n_th_tribonacci_number;
-// #Easy #Dynamic_Programming #Math #Memoization #Dynamic_Programming_I_Day_1
+// #Easy #Dynamic_Programming #Math #Memoization #LeetCode_75_DP/1D #Dynamic_Programming_I_Day_1
// #2023_06_01_Time_0_ms_(100.00%)_Space_39.6_MB_(48.37%)
public class Solution {
diff --git a/src/main/java/g1101_1200/s1138_alphabet_board_path/Solution.java b/src/main/java/g1101_1200/s1138_alphabet_board_path/Solution.java
index 3a75061c6..8f6b70c56 100644
--- a/src/main/java/g1101_1200/s1138_alphabet_board_path/Solution.java
+++ b/src/main/java/g1101_1200/s1138_alphabet_board_path/Solution.java
@@ -4,7 +4,7 @@
public class Solution {
public String alphabetBoardPath(String target) {
- if (target.length() == 0) {
+ if (target.isEmpty()) {
return "";
}
int sourceRow = 0;
@@ -35,9 +35,7 @@ public String alphabetBoardPath(String target) {
public StringBuilder helper(String dir, int time) {
StringBuilder path = new StringBuilder();
- for (int i = 0; i < time; i++) {
- path.append(dir);
- }
+ path.append(String.valueOf(dir).repeat(Math.max(0, time)));
return path;
}
}
diff --git a/src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java b/src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java
index 5a48ae3ff..363f23b1d 100644
--- a/src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java
+++ b/src/main/java/g1101_1200/s1143_longest_common_subsequence/Solution.java
@@ -1,9 +1,9 @@
package g1101_1200.s1143_longest_common_subsequence;
-// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming
+// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming #LeetCode_75_DP/Multidimensional
// #Algorithm_II_Day_17_Dynamic_Programming #Dynamic_Programming_I_Day_19
// #Udemy_Dynamic_Programming #Big_O_Time_O(n*m)_Space_O(n*m)
-// #2023_06_01_Time_33_ms_(46.23%)_Space_48.2_MB_(90.63%)
+// #2024_11_17_Time_19_ms_(89.05%)_Space_50.9_MB_(33.70%)
public class Solution {
public int longestCommonSubsequence(String text1, String text2) {
diff --git a/src/main/java/g1101_1200/s1161_maximum_level_sum_of_a_binary_tree/Solution.java b/src/main/java/g1101_1200/s1161_maximum_level_sum_of_a_binary_tree/Solution.java
index d06730a8b..4a4c590d1 100644
--- a/src/main/java/g1101_1200/s1161_maximum_level_sum_of_a_binary_tree/Solution.java
+++ b/src/main/java/g1101_1200/s1161_maximum_level_sum_of_a_binary_tree/Solution.java
@@ -1,6 +1,6 @@
package g1101_1200.s1161_maximum_level_sum_of_a_binary_tree;
-// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
+// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/BFS
// #2023_06_02_Time_7_ms_(97.19%)_Space_46.3_MB_(31.31%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java b/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java
index 6d28b4dec..4c51832e2 100644
--- a/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java
+++ b/src/main/java/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.java
@@ -3,13 +3,13 @@
// #Medium #Array #Dynamic_Programming #2022_03_03_Time_6_ms_(73.85%)_Space_59.8_MB_(30.38%)
public class Solution {
- private long mod = 1000000007;
+ private static final long MOD = 1000000007;
public int kConcatenationMaxSum(int[] arr, int k) {
// int kadane = Kadane(arr);
// #1 when k 1 simply calculate kadanes
if (k == 1) {
- return (int) (kadane(arr) % mod);
+ return (int) (kadane(arr) % MOD);
}
// #2 else calculate the total sum and then check if sum is -Ve or +Ve
long totalSum = 0;
@@ -19,11 +19,11 @@ public int kConcatenationMaxSum(int[] arr, int k) {
// #3 when negative then calculate of arr 2 times only the answer is in there only
if (totalSum < 0) {
// when -ve sum put a extra check here of max from 0
- return (int) Math.max(kadaneTwo(arr) % mod, 0);
+ return (int) Math.max(kadaneTwo(arr) % MOD, 0);
} else {
// #4 when sum is positve then the ans is kadane of 2 + sum * (k-2);
// these two are used sUm*(k-2) ensures that all other are also included
- return (int) ((kadaneTwo(arr) + ((k - 2) * totalSum) + mod) % mod);
+ return (int) ((kadaneTwo(arr) + ((k - 2) * totalSum) + MOD) % MOD);
}
}
diff --git a/src/main/java/g1101_1200/s1195_fizz_buzz_multithreaded/FizzBuzz.java b/src/main/java/g1101_1200/s1195_fizz_buzz_multithreaded/FizzBuzz.java
index 627efd08f..8765da324 100644
--- a/src/main/java/g1101_1200/s1195_fizz_buzz_multithreaded/FizzBuzz.java
+++ b/src/main/java/g1101_1200/s1195_fizz_buzz_multithreaded/FizzBuzz.java
@@ -1,61 +1,75 @@
package g1101_1200.s1195_fizz_buzz_multithreaded;
-// #Medium #Concurrency #2022_03_03_Time_8_ms_(80.09%)_Space_43.2_MB_(6.17%)
+// #Medium #Concurrency #2024_11_24_Time_6_ms_(94.88%)_Space_43.1_MB_(8.61%)
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntConsumer;
@SuppressWarnings("java:S1130")
public class FizzBuzz {
- private final AtomicInteger count = new AtomicInteger(1);
-
private final int n;
+ private int current;
public FizzBuzz(int n) {
this.n = n;
+ this.current = 1;
}
// printFizz.run() outputs "fizz".
public void fizz(Runnable printFizz) throws InterruptedException {
- int i;
- while ((i = count.get()) <= n) {
- if (i % 3 == 0 && i % 5 != 0) {
- printFizz.run();
- count.compareAndSet(i, i + 1);
+ synchronized (this) {
+ while (current <= n) {
+ if (current % 3 == 0 && current % 5 != 0) {
+ printFizz.run();
+ current += 1;
+ notifyAll();
+ } else {
+ wait();
+ }
}
}
}
// printBuzz.run() outputs "buzz".
public void buzz(Runnable printBuzz) throws InterruptedException {
- int i;
- while ((i = count.get()) <= n) {
- count.get();
- if (i % 5 == 0 && i % 3 != 0) {
- printBuzz.run();
- count.compareAndSet(i, i + 1);
+ synchronized (this) {
+ while (current <= n) {
+ if (current % 3 != 0 && current % 5 == 0) {
+ printBuzz.run();
+ current += 1;
+ notifyAll();
+ } else {
+ wait();
+ }
}
}
}
// printFizzBuzz.run() outputs "fizzbuzz".
public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException {
- int i;
- while ((i = count.get()) <= n) {
- if (i % 15 == 0) {
- printFizzBuzz.run();
- count.compareAndSet(i, i + 1);
+ synchronized (this) {
+ while (current <= n) {
+ if (current % 15 == 0) {
+ printFizzBuzz.run();
+ current += 1;
+ notifyAll();
+ } else {
+ wait();
+ }
}
}
}
// printNumber.accept(x) outputs "x", where x is an integer.
public void number(IntConsumer printNumber) throws InterruptedException {
- int i;
- while ((i = count.get()) <= n) {
- if (i % 5 != 0 && i % 3 != 0) {
- printNumber.accept(i);
- count.compareAndSet(i, i + 1);
+ synchronized (this) {
+ while (current <= n) {
+ if (current % 3 != 0 && current % 5 != 0) {
+ printNumber.accept(current);
+ current += 1;
+ notifyAll();
+ } else {
+ wait();
+ }
}
}
}
diff --git a/src/main/java/g1201_1300/s1207_unique_number_of_occurrences/Solution.java b/src/main/java/g1201_1300/s1207_unique_number_of_occurrences/Solution.java
index cb3c6d89d..2eef033e2 100644
--- a/src/main/java/g1201_1300/s1207_unique_number_of_occurrences/Solution.java
+++ b/src/main/java/g1201_1300/s1207_unique_number_of_occurrences/Solution.java
@@ -1,6 +1,7 @@
package g1201_1300.s1207_unique_number_of_occurrences;
-// #Easy #Array #Hash_Table #2022_04_29_Time_2_ms_(82.71%)_Space_42.4_MB_(34.08%)
+// #Easy #Array #Hash_Table #LeetCode_75_Hash_Map/Set
+// #2022_04_29_Time_2_ms_(82.71%)_Space_42.4_MB_(34.08%)
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/java/g1201_1300/s1209_remove_all_adjacent_duplicates_in_string_ii/Solution.java b/src/main/java/g1201_1300/s1209_remove_all_adjacent_duplicates_in_string_ii/Solution.java
index ff28b995b..85ef555d9 100644
--- a/src/main/java/g1201_1300/s1209_remove_all_adjacent_duplicates_in_string_ii/Solution.java
+++ b/src/main/java/g1201_1300/s1209_remove_all_adjacent_duplicates_in_string_ii/Solution.java
@@ -7,7 +7,7 @@ public String removeDuplicates(String s, int k) {
StringBuilder sb = new StringBuilder();
int dupCount = 0;
for (int i = 0; i < s.length(); i++) {
- if (sb.length() != 0 && sb.charAt(sb.length() - 1) == s.charAt(i)) {
+ if (!sb.isEmpty() && sb.charAt(sb.length() - 1) == s.charAt(i)) {
dupCount++;
} else {
dupCount = 1;
diff --git a/src/main/java/g1201_1300/s1268_search_suggestions_system/Solution.java b/src/main/java/g1201_1300/s1268_search_suggestions_system/Solution.java
index 5ca04e9b7..8bc61bd45 100644
--- a/src/main/java/g1201_1300/s1268_search_suggestions_system/Solution.java
+++ b/src/main/java/g1201_1300/s1268_search_suggestions_system/Solution.java
@@ -1,6 +1,6 @@
package g1201_1300.s1268_search_suggestions_system;
-// #Medium #Array #String #2022_03_14_Time_28_ms_(78.06%)_Space_73.1_MB_(38.32%)
+// #Medium #Array #String #LeetCode_75_Trie #2022_03_14_Time_28_ms_(78.06%)_Space_73.1_MB_(38.32%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game/Solution.java b/src/main/java/g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game/Solution.java
index 806bb473b..b100843eb 100644
--- a/src/main/java/g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game/Solution.java
+++ b/src/main/java/g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game/Solution.java
@@ -22,24 +22,22 @@ public String tictactoe(int[][] moves) {
private String wins(String[][] board) {
for (int i = 0; i < 3; i++) {
if (board[i][0] == null) {
- break;
+ continue;
}
String str = board[i][0];
if (str.equals(board[i][1]) && str.equals(board[i][2])) {
return getWinner(str);
}
}
-
for (int j = 0; j < 3; j++) {
if (board[0][j] == null) {
- break;
+ continue;
}
String str = board[0][j];
if (str.equals(board[1][j]) && str.equals(board[2][j])) {
return getWinner(str);
}
}
-
if (board[1][1] == null) {
return "";
}
diff --git a/src/main/java/g1201_1300/s1286_iterator_for_combination/CombinationIterator.java b/src/main/java/g1201_1300/s1286_iterator_for_combination/CombinationIterator.java
index e3d1a5c19..ef417d567 100644
--- a/src/main/java/g1201_1300/s1286_iterator_for_combination/CombinationIterator.java
+++ b/src/main/java/g1201_1300/s1286_iterator_for_combination/CombinationIterator.java
@@ -10,13 +10,12 @@ public class CombinationIterator {
private List list;
private int index;
private int combinationLength;
- private boolean[] visited;
public CombinationIterator(String characters, int combinationLength) {
this.index = 0;
this.list = new ArrayList<>();
this.combinationLength = combinationLength;
- this.visited = new boolean[characters.length()];
+ boolean[] visited = new boolean[characters.length()];
buildAllCombinations(characters, 0, new StringBuilder(), visited);
}
diff --git a/src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java b/src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java
index 2076665f1..6fee96b42 100644
--- a/src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java
+++ b/src/main/java/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping/Solution.java
@@ -1,54 +1,26 @@
package g1301_1400.s1309_decrypt_string_from_alphabet_to_integer_mapping;
// #Easy #String #Programming_Skills_I_Day_9_String
-// #2022_03_15_Time_6_ms_(28.25%)_Space_42.6_MB_(29.40%)
-
-import java.util.HashMap;
-import java.util.Map;
+// #2025_04_23_Time_0_ms_(100.00%)_Space_41.42_MB_(89.95%)
public class Solution {
public String freqAlphabets(String s) {
- Map map = new HashMap<>();
- map.put("1", "a");
- map.put("2", "b");
- map.put("3", "c");
- map.put("4", "d");
- map.put("5", "e");
- map.put("6", "f");
- map.put("7", "g");
- map.put("8", "h");
- map.put("9", "i");
- map.put("10#", "j");
- map.put("11#", "k");
- map.put("12#", "l");
- map.put("13#", "m");
- map.put("14#", "n");
- map.put("15#", "o");
- map.put("16#", "p");
- map.put("17#", "q");
- map.put("18#", "r");
- map.put("19#", "s");
- map.put("20#", "t");
- map.put("21#", "u");
- map.put("22#", "v");
- map.put("23#", "w");
- map.put("24#", "x");
- map.put("25#", "y");
- map.put("26#", "z");
- StringBuilder sb = new StringBuilder();
- int i = 0;
- while (i < s.length()) {
- if ((Integer.parseInt("" + s.charAt(i)) == 1 || Integer.parseInt("" + s.charAt(i)) == 2)
- && i + 1 < s.length()
- && i + 2 < s.length()
- && s.charAt(i + 2) == '#') {
- sb.append(map.get(s.substring(i, i + 3)));
- i += 3;
+ StringBuilder builder = new StringBuilder();
+ int i = s.length() - 1;
+ while (i >= 0) {
+ if (s.charAt(i) == '#') {
+ decryptor(builder, i - 1, i - 2, s);
+ i -= 3;
} else {
- sb.append(map.get("" + s.charAt(i)));
- i++;
+ char ch = (char) (s.charAt(i) - '0' + 96);
+ builder.append(ch);
+ i--;
}
}
- return sb.toString();
+ return builder.reverse().toString();
+ }
+
+ private void decryptor(StringBuilder builder, int a, int b, String s) {
+ builder.append((char) (((s.charAt(b) - '0') * 10 + s.charAt(a) - '0') + 96));
}
}
diff --git a/src/main/java/g1301_1400/s1318_minimum_flips_to_make_a_or_b_equal_to_c/Solution.java b/src/main/java/g1301_1400/s1318_minimum_flips_to_make_a_or_b_equal_to_c/Solution.java
index 007e50311..f6afffa22 100644
--- a/src/main/java/g1301_1400/s1318_minimum_flips_to_make_a_or_b_equal_to_c/Solution.java
+++ b/src/main/java/g1301_1400/s1318_minimum_flips_to_make_a_or_b_equal_to_c/Solution.java
@@ -1,6 +1,7 @@
package g1301_1400.s1318_minimum_flips_to_make_a_or_b_equal_to_c;
-// #Medium #Bit_Manipulation #2022_03_19_Time_0_ms_(100.00%)_Space_40.6_MB_(60.32%)
+// #Medium #Bit_Manipulation #LeetCode_75_Bit_Manipulation
+// #2022_03_19_Time_0_ms_(100.00%)_Space_40.6_MB_(60.32%)
public class Solution {
public static int csb(int n) {
diff --git a/src/main/java/g1301_1400/s1329_sort_the_matrix_diagonally/Solution.java b/src/main/java/g1301_1400/s1329_sort_the_matrix_diagonally/Solution.java
index 1a2cd7205..bb0045f13 100644
--- a/src/main/java/g1301_1400/s1329_sort_the_matrix_diagonally/Solution.java
+++ b/src/main/java/g1301_1400/s1329_sort_the_matrix_diagonally/Solution.java
@@ -1,41 +1,35 @@
package g1301_1400.s1329_sort_the_matrix_diagonally;
-// #Medium #Array #Sorting #Matrix #2022_03_19_Time_15_ms_(26.03%)_Space_47.7_MB_(56.76%)
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+// #Medium #Array #Sorting #Matrix #2024_12_19_Time_0_ms_(100.00%)_Space_44.7_MB_(81.35%)
public class Solution {
- public int[][] diagonalSort(int[][] mat) {
- int m = mat.length;
- int n = mat[0].length;
- int[][] sorted = new int[m][n];
- for (int i = m - 1; i >= 0; i--) {
- int iCopy = i;
- List list = new ArrayList<>();
- for (int j = 0; j < n && iCopy < m; j++, iCopy++) {
- list.add(mat[iCopy][j]);
- }
- Collections.sort(list);
- iCopy = i;
- for (int j = 0; j < n && iCopy < m; j++, iCopy++) {
- sorted[iCopy][j] = list.get(j);
+ private int[] count = new int[101];
+ private int m;
+ private int n;
+
+ public void search(int[][] mat, int i, int j) {
+ for (int ti = i, tj = j; ti < m && tj < n; ti++, tj++) {
+ count[mat[ti][tj]]++;
+ }
+ int c = 0;
+ for (int ti = i, tj = j; ti < m && tj < n; ti++, tj++) {
+ while (count[c] == 0) {
+ c++;
}
+ mat[ti][tj] = c;
+ count[c]--;
}
+ }
- for (int j = n - 1; j > 0; j--) {
- int jCopy = j;
- List list = new ArrayList<>();
- for (int i = 0; i < m && jCopy < n; i++, jCopy++) {
- list.add(mat[i][jCopy]);
- }
- Collections.sort(list);
- jCopy = j;
- for (int i = 0; i < m && jCopy < n; i++, jCopy++) {
- sorted[i][jCopy] = list.get(i);
- }
+ public int[][] diagonalSort(int[][] mat) {
+ m = mat.length;
+ n = mat[0].length;
+ for (int i = 0; i < m; i++) {
+ search(mat, i, 0);
+ }
+ for (int i = 1; i < n; i++) {
+ search(mat, 0, i);
}
- return sorted;
+ return mat;
}
}
diff --git a/src/main/java/g1301_1400/s1354_construct_target_array_with_multiple_sums/Solution.java b/src/main/java/g1301_1400/s1354_construct_target_array_with_multiple_sums/Solution.java
index 235becf12..417d0fecd 100644
--- a/src/main/java/g1301_1400/s1354_construct_target_array_with_multiple_sums/Solution.java
+++ b/src/main/java/g1301_1400/s1354_construct_target_array_with_multiple_sums/Solution.java
@@ -21,7 +21,7 @@ public boolean isPossible(int[] target) {
|| target[maxIndex] % remainingSum == 0) {
return false;
}
- target[maxIndex] %= remainingSum;
+ target[maxIndex] %= (int) remainingSum;
return isPossible(target);
}
}
diff --git a/src/main/java/g1301_1400/s1372_longest_zigzag_path_in_a_binary_tree/Solution.java b/src/main/java/g1301_1400/s1372_longest_zigzag_path_in_a_binary_tree/Solution.java
index 31200e0d6..efdd937bf 100644
--- a/src/main/java/g1301_1400/s1372_longest_zigzag_path_in_a_binary_tree/Solution.java
+++ b/src/main/java/g1301_1400/s1372_longest_zigzag_path_in_a_binary_tree/Solution.java
@@ -1,6 +1,6 @@
package g1301_1400.s1372_longest_zigzag_path_in_a_binary_tree;
-// #Medium #Dynamic_Programming #Depth_First_Search #Tree #Binary_Tree
+// #Medium #Dynamic_Programming #Depth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS
// #2022_03_21_Time_9_ms_(64.47%)_Space_74_MB_(56.45%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g1301_1400/s1391_check_if_there_is_a_valid_path_in_a_grid/Solution.java b/src/main/java/g1301_1400/s1391_check_if_there_is_a_valid_path_in_a_grid/Solution.java
index 72c77c052..73b0ae60d 100644
--- a/src/main/java/g1301_1400/s1391_check_if_there_is_a_valid_path_in_a_grid/Solution.java
+++ b/src/main/java/g1301_1400/s1391_check_if_there_is_a_valid_path_in_a_grid/Solution.java
@@ -15,6 +15,7 @@ public class Solution {
{{0, -1}, {-1, 0}},
{{0, 1}, {-1, 0}}
};
+
// the idea is you need to check port direction match, you can go to next cell and check whether
// you can come back.
public boolean hasValidPath(int[][] grid) {
diff --git a/src/main/java/g1301_1400/s1392_longest_happy_prefix/Solution.java b/src/main/java/g1301_1400/s1392_longest_happy_prefix/Solution.java
index 962190237..b1e2b98ad 100644
--- a/src/main/java/g1301_1400/s1392_longest_happy_prefix/Solution.java
+++ b/src/main/java/g1301_1400/s1392_longest_happy_prefix/Solution.java
@@ -1,25 +1,29 @@
package g1301_1400.s1392_longest_happy_prefix;
// #Hard #String #Hash_Function #String_Matching #Rolling_Hash
-// #2022_03_17_Time_39_ms_(28.37%)_Space_42.6_MB_(94.23%)
+// #2025_04_23_Time_5_ms_(100.00%)_Space_45.92_MB_(23.63%)
public class Solution {
public String longestPrefix(String s) {
- int times = 2;
- long prefixHash = 0;
- long suffixHash = 0;
- long multiplier = 1;
- long len = 0;
- // use some large prime as a modulo to avoid overflow errors, e.g. 10 ^ 9 + 7.
- long mod = 1000000007;
- for (int i = 0; i < s.length() - 1; i++) {
- prefixHash = (prefixHash * times + s.charAt(i)) % mod;
- suffixHash = (multiplier * s.charAt(s.length() - i - 1) + suffixHash) % mod;
- if (prefixHash == suffixHash) {
- len = (long) i + 1;
+ char[] c = s.toCharArray();
+ int n = c.length;
+ int[] a = new int[n];
+ int max = 0;
+ int i = 1;
+ while (i < n) {
+ if (c[max] == c[i]) {
+ max++;
+ a[i] = max;
+ i++;
+ } else {
+ if (max > 0) {
+ max = a[max - 1];
+ } else {
+ a[i] = 0;
+ i++;
+ }
}
- multiplier = multiplier * times % mod;
}
- return s.substring(0, (int) len);
+ return s.substring(0, a[n - 1]);
}
}
diff --git a/src/main/java/g1401_1500/s1408_string_matching_in_an_array/Solution.java b/src/main/java/g1401_1500/s1408_string_matching_in_an_array/Solution.java
index 70be26d25..8d2c2c3ee 100644
--- a/src/main/java/g1401_1500/s1408_string_matching_in_an_array/Solution.java
+++ b/src/main/java/g1401_1500/s1408_string_matching_in_an_array/Solution.java
@@ -1,22 +1,31 @@
package g1401_1500.s1408_string_matching_in_an_array;
-// #Easy #String #String_Matching #2022_03_26_Time_8_ms_(24.88%)_Space_43.3_MB_(13.46%)
+// #Easy #String #String_Matching #2024_12_19_Time_1_ms_(100.00%)_Space_42.7_MB_(5.57%)
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
public class Solution {
public List stringMatching(String[] words) {
- Set set = new HashSet<>();
- for (String word : words) {
- for (String s : words) {
- if (!word.equals(s) && word.length() < s.length() && s.contains(word)) {
- set.add(word);
- }
+ List matchedStrings = new ArrayList<>();
+ for (int i = 0; i < words.length; i++) {
+ boolean containsSubstring = checkContains(words, i);
+ if (containsSubstring) {
+ matchedStrings.add(words[i]);
}
}
- return new ArrayList<>(set);
+ return matchedStrings;
+ }
+
+ private boolean checkContains(String[] words, int index) {
+ for (int j = 0; j < words.length; j++) {
+ if (index == j) {
+ continue;
+ }
+ if (words[j].contains(words[index])) {
+ return true;
+ }
+ }
+ return false;
}
}
diff --git a/src/main/java/g1401_1500/s1431_kids_with_the_greatest_number_of_candies/Solution.java b/src/main/java/g1401_1500/s1431_kids_with_the_greatest_number_of_candies/Solution.java
index 1f0ac0d72..06f5b630e 100644
--- a/src/main/java/g1401_1500/s1431_kids_with_the_greatest_number_of_candies/Solution.java
+++ b/src/main/java/g1401_1500/s1431_kids_with_the_greatest_number_of_candies/Solution.java
@@ -1,6 +1,6 @@
package g1401_1500.s1431_kids_with_the_greatest_number_of_candies;
-// #Easy #Array #2022_03_28_Time_1_ms_(84.43%)_Space_43.3_MB_(19.35%)
+// #Easy #Array #LeetCode_75_Array/String #2022_03_28_Time_1_ms_(84.43%)_Space_43.3_MB_(19.35%)
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/g1401_1500/s1441_build_an_array_with_stack_operations/Solution.java b/src/main/java/g1401_1500/s1441_build_an_array_with_stack_operations/Solution.java
index a2a8d2e98..dfaab970d 100644
--- a/src/main/java/g1401_1500/s1441_build_an_array_with_stack_operations/Solution.java
+++ b/src/main/java/g1401_1500/s1441_build_an_array_with_stack_operations/Solution.java
@@ -1,6 +1,6 @@
package g1401_1500.s1441_build_an_array_with_stack_operations;
-// #Easy #Array #Stack #Simulation #2022_03_28_Time_1_ms_(38.47%)_Space_43.3_MB_(57.71%)
+// #Medium #Array #Stack #Simulation #2022_03_28_Time_1_ms_(38.47%)_Space_43.3_MB_(57.71%)
import java.util.ArrayList;
import java.util.HashSet;
diff --git a/src/main/java/g1401_1500/s1448_count_good_nodes_in_binary_tree/Solution.java b/src/main/java/g1401_1500/s1448_count_good_nodes_in_binary_tree/Solution.java
index ff4ba0138..e67fc9ba4 100644
--- a/src/main/java/g1401_1500/s1448_count_good_nodes_in_binary_tree/Solution.java
+++ b/src/main/java/g1401_1500/s1448_count_good_nodes_in_binary_tree/Solution.java
@@ -1,6 +1,6 @@
package g1401_1500.s1448_count_good_nodes_in_binary_tree;
-// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
+// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #LeetCode_75_Binary_Tree/DFS
// #2022_03_28_Time_2_ms_(99.63%)_Space_60.1_MB_(26.46%)
import com_github_leetcode.TreeNode;
diff --git a/src/main/java/g1401_1500/s1456_maximum_number_of_vowels_in_a_substring_of_given_length/Solution.java b/src/main/java/g1401_1500/s1456_maximum_number_of_vowels_in_a_substring_of_given_length/Solution.java
index 8d597766c..301f44a19 100644
--- a/src/main/java/g1401_1500/s1456_maximum_number_of_vowels_in_a_substring_of_given_length/Solution.java
+++ b/src/main/java/g1401_1500/s1456_maximum_number_of_vowels_in_a_substring_of_given_length/Solution.java
@@ -1,6 +1,7 @@
package g1401_1500.s1456_maximum_number_of_vowels_in_a_substring_of_given_length;
-// #Medium #String #Sliding_Window #2022_03_28_Time_19_ms_(53.73%)_Space_47.8_MB_(64.37%)
+// #Medium #String #Sliding_Window #LeetCode_75_Sliding_Window
+// #2022_03_28_Time_19_ms_(53.73%)_Space_47.8_MB_(64.37%)
public class Solution {
private boolean isVowel(char c) {
diff --git a/src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java b/src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java
index 49079df42..612096c3c 100644
--- a/src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java
+++ b/src/main/java/g1401_1500/s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero/Solution.java
@@ -1,6 +1,6 @@
package g1401_1500.s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero;
-// #Medium #Depth_First_Search #Breadth_First_Search #Graph
+// #Medium #Depth_First_Search #Breadth_First_Search #Graph #LeetCode_75_Graphs/DFS
// #Graph_Theory_I_Day_10_Standard_Traversal #2022_03_29_Time_39_ms_(97.71%)_Space_65.2_MB_(94.87%)
import java.util.ArrayList;
diff --git a/src/main/java/g1401_1500/s1493_longest_subarray_of_1s_after_deleting_one_element/Solution.java b/src/main/java/g1401_1500/s1493_longest_subarray_of_1s_after_deleting_one_element/Solution.java
index 997c825c2..2a56a4a4c 100644
--- a/src/main/java/g1401_1500/s1493_longest_subarray_of_1s_after_deleting_one_element/Solution.java
+++ b/src/main/java/g1401_1500/s1493_longest_subarray_of_1s_after_deleting_one_element/Solution.java
@@ -1,6 +1,6 @@
package g1401_1500.s1493_longest_subarray_of_1s_after_deleting_one_element;
-// #Medium #Dynamic_Programming #Math #Sliding_Window
+// #Medium #Dynamic_Programming #Math #Sliding_Window #LeetCode_75_Sliding_Window
// #2022_03_23_Time_2_ms_(87.25%)_Space_58.4_MB_(29.26%)
public class Solution {
diff --git a/src/main/java/g1501_1600/s1519_number_of_nodes_in_the_sub_tree_with_the_same_label/Solution.java b/src/main/java/g1501_1600/s1519_number_of_nodes_in_the_sub_tree_with_the_same_label/Solution.java
index c255789d7..5d959d74b 100644
--- a/src/main/java/g1501_1600/s1519_number_of_nodes_in_the_sub_tree_with_the_same_label/Solution.java
+++ b/src/main/java/g1501_1600/s1519_number_of_nodes_in_the_sub_tree_with_the_same_label/Solution.java
@@ -8,7 +8,7 @@
public class Solution {
public int[] countSubTrees(int n, int[][] edges, String labelsString) {
int[] labelsCount = new int[n];
- if (n <= 0 || edges == null || labelsString == null) {
+ if (n == 0 || edges == null || labelsString == null) {
return labelsCount;
}
diff --git a/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java b/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java
index 0ae0a15b7..a066f07c8 100644
--- a/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java
+++ b/src/main/java/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.java
@@ -32,12 +32,13 @@ public int minCostConnectPoints(int[][] points) {
return cost;
}
- public void constructMST(
+ private void constructMST(
int[] parent, int[][] points, boolean[] mst, PriorityQueue pq, int[] dist) {
if (!containsFalse(mst)) {
return;
}
Pair newPair = pq.poll();
+ assert newPair != null;
int pointIndex = newPair.getV();
mst[pointIndex] = true;
for (int i = 0; i < parent.length; i++) {
diff --git a/src/main/java/g1501_1600/s1592_rearrange_spaces_between_words/Solution.java b/src/main/java/g1501_1600/s1592_rearrange_spaces_between_words/Solution.java
index 14f2a02fd..20e62ab4f 100644
--- a/src/main/java/g1501_1600/s1592_rearrange_spaces_between_words/Solution.java
+++ b/src/main/java/g1501_1600/s1592_rearrange_spaces_between_words/Solution.java
@@ -12,11 +12,7 @@ public String reorderSpaces(String text) {
}
String[] words = text.trim().split("\\s+");
if (words.length == 1) {
- StringBuilder sb = new StringBuilder(words[0]);
- for (int i = 0; i < spaceCount; i++) {
- sb.append(" ");
- }
- return sb.toString();
+ return words[0] + " ".repeat(Math.max(0, spaceCount));
}
int trailingSpaces = spaceCount % (words.length - 1);
int newSpaces = spaceCount / (words.length - 1);
@@ -24,13 +20,9 @@ public String reorderSpaces(String text) {
for (int j = 0; j < words.length; j++) {
sb.append(words[j]);
if (j < words.length - 1) {
- for (int i = 0; i < newSpaces; i++) {
- sb.append(" ");
- }
+ sb.append(" ".repeat(Math.max(0, newSpaces)));
} else {
- for (int i = 0; i < trailingSpaces; i++) {
- sb.append(" ");
- }
+ sb.append(" ".repeat(Math.max(0, trailingSpaces)));
}
}
return sb.toString();
diff --git a/src/main/java/g1601_1700/s1616_split_two_strings_to_make_palindrome/Solution.java b/src/main/java/g1601_1700/s1616_split_two_strings_to_make_palindrome/Solution.java
index f45860a9e..95a950eac 100644
--- a/src/main/java/g1601_1700/s1616_split_two_strings_to_make_palindrome/Solution.java
+++ b/src/main/java/g1601_1700/s1616_split_two_strings_to_make_palindrome/Solution.java
@@ -1,28 +1,32 @@
package g1601_1700.s1616_split_two_strings_to_make_palindrome;
-// #Medium #String #Greedy #Two_Pointers #2022_04_13_Time_4_ms_(89.77%)_Space_43.3_MB_(85.58%)
+// #Medium #String #Greedy #Two_Pointers #2024_09_04_Time_2_ms_(100.00%)_Space_45.1_MB_(97.99%)
@SuppressWarnings("java:S2234")
public class Solution {
public boolean checkPalindromeFormation(String a, String b) {
- return check(a, b) || check(b, a);
- }
-
- private boolean check(String a, String b) {
- int i = 0;
- int j = b.length() - 1;
- while (j > i && a.charAt(i) == b.charAt(j)) {
- ++i;
- --j;
+ int n = a.length();
+ int s = 0;
+ int e = n - 1;
+ if (isPalindrome(a, b, s, e, true)) {
+ return true;
+ } else {
+ return isPalindrome(b, a, s, e, true);
}
- return isPalindrome(a, i, j) || isPalindrome(b, i, j);
}
- private boolean isPalindrome(String s, int i, int j) {
- while (j > i && s.charAt(i) == s.charAt(j)) {
- ++i;
- --j;
+ private boolean isPalindrome(String a, String b, int s, int e, boolean check) {
+ if (s == e) {
+ return true;
+ }
+ while (s < e) {
+ if (a.charAt(s) != b.charAt(e)) {
+ return check
+ && (isPalindrome(a, a, s, e, false) || isPalindrome(b, b, s, e, false));
+ }
+ s++;
+ e--;
}
- return i >= j;
+ return true;
}
}
diff --git a/src/main/java/g1601_1700/s1637_widest_vertical_area_between_two_points_containing_no_points/Solution.java b/src/main/java/g1601_1700/s1637_widest_vertical_area_between_two_points_containing_no_points/Solution.java
index d9095745a..d9a6432cf 100644
--- a/src/main/java/g1601_1700/s1637_widest_vertical_area_between_two_points_containing_no_points/Solution.java
+++ b/src/main/java/g1601_1700/s1637_widest_vertical_area_between_two_points_containing_no_points/Solution.java
@@ -1,6 +1,6 @@
package g1601_1700.s1637_widest_vertical_area_between_two_points_containing_no_points;
-// #Medium #Array #Sorting #2022_04_20_Time_17_ms_(74.19%)_Space_78.6_MB_(62.28%)
+// #Easy #Array #Sorting #2022_04_20_Time_17_ms_(74.19%)_Space_78.6_MB_(62.28%)
import java.util.Arrays;
diff --git a/src/main/java/g1601_1700/s1643_kth_smallest_instructions/Solution.java b/src/main/java/g1601_1700/s1643_kth_smallest_instructions/Solution.java
index ffaca6cb9..f76372ce7 100644
--- a/src/main/java/g1601_1700/s1643_kth_smallest_instructions/Solution.java
+++ b/src/main/java/g1601_1700/s1643_kth_smallest_instructions/Solution.java
@@ -19,14 +19,10 @@ public String kthSmallestPath(int[] destination, int k) {
k -= range;
}
if (v == 0) {
- for (int i = 1; i <= n; i++) {
- sb.append('H');
- }
+ sb.append("H".repeat(Math.max(0, n)));
break;
} else if (v == n) {
- for (int i = 1; i <= v; i++) {
- sb.append('V');
- }
+ sb.append("V".repeat(Math.max(0, v)));
break;
}
}
diff --git a/src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java b/src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java
index 9d8969faa..bb9119e2c 100644
--- a/src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java
+++ b/src/main/java/g1601_1700/s1648_sell_diminishing_valued_colored_balls/Solution.java
@@ -18,7 +18,7 @@ public int maxProfit(int[] inventory, int orders) {
long diff = i == 0 ? inventory[i] : inventory[i] - inventory[i - 1];
if (count * diff < orders) {
totalValue += (2L * inventory[i] - diff + 1) * diff * count / 2 % mod;
- orders -= count * diff;
+ orders -= (int) (count * diff);
} else {
diff = orders / count;
long remainder = orders % count;
diff --git a/src/main/java/g1601_1700/s1657_determine_if_two_strings_are_close/Solution.java b/src/main/java/g1601_1700/s1657_determine_if_two_strings_are_close/Solution.java
index 2d04b9c2b..51c637c8c 100644
--- a/src/main/java/g1601_1700/s1657_determine_if_two_strings_are_close/Solution.java
+++ b/src/main/java/g1601_1700/s1657_determine_if_two_strings_are_close/Solution.java
@@ -1,6 +1,7 @@
package g1601_1700.s1657_determine_if_two_strings_are_close;
-// #Medium #String #Hash_Table #Sorting #2022_04_23_Time_12_ms_(97.58%)_Space_59.6_MB_(39.11%)
+// #Medium #String #Hash_Table #Sorting #LeetCode_75_Hash_Map/Set
+// #2022_04_23_Time_12_ms_(97.58%)_Space_59.6_MB_(39.11%)
import java.util.Arrays;
diff --git a/src/main/java/g1601_1700/s1659_maximize_grid_happiness/Solution.java b/src/main/java/g1601_1700/s1659_maximize_grid_happiness/Solution.java
index f10850cc8..fe6561f40 100644
--- a/src/main/java/g1601_1700/s1659_maximize_grid_happiness/Solution.java
+++ b/src/main/java/g1601_1700/s1659_maximize_grid_happiness/Solution.java
@@ -1,74 +1,96 @@
package g1601_1700.s1659_maximize_grid_happiness;
// #Hard #Dynamic_Programming #Bit_Manipulation #Bitmask #Memoization
-// #2022_04_23_Time_95_ms_(75.00%)_Space_53.1_MB_(58.33%)
+// #2025_04_04_Time_39_ms_(86.36%)_Space_54.76_MB_(72.73%)
+@SuppressWarnings("java:S107")
public class Solution {
- private int m;
- private int n;
- private int[][][][][] dp;
- private int notPlace = 0;
- private int intro = 1;
- private int extro = 2;
- private int mod;
+ private static final int NONE = 0;
+ private static final int INTROVERT = 1;
+ private static final int EXTROVERT = 2;
- public int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {
- this.m = m;
- this.n = n;
- int numOfState = (int) Math.pow(3, n);
- this.dp = new int[m][n][introvertsCount + 1][extrovertsCount + 1][numOfState];
- this.mod = numOfState / 3;
- return dfs(0, 0, introvertsCount, extrovertsCount, 0);
- }
-
- private int dfs(int x, int y, int ic, int ec, int state) {
- if (x == m) {
+ private int maxHappiness(
+ int index,
+ int m,
+ int n,
+ int introverts,
+ int extroverts,
+ int board,
+ int[][][][] dp,
+ int tmask) {
+ if (index >= m * n) {
return 0;
- } else if (y == n) {
- return dfs(x + 1, 0, ic, ec, state);
}
- if (dp[x][y][ic][ec][state] != 0) {
- return dp[x][y][ic][ec][state];
+ if (dp[index][introverts][extroverts][board] != 0) {
+ return dp[index][introverts][extroverts][board];
}
- // 1 - not place
- int max = dfs(x, y + 1, ic, ec, (state % mod) * 3);
- int up = state / mod;
- int left = state % 3;
- // 2 - place intro
- if (ic > 0) {
- int temp = 120;
- if (x > 0 && up != notPlace) {
- temp -= 30;
- temp += up == intro ? -30 : 20;
- }
- if (y > 0 && left != notPlace) {
- temp -= 30;
- temp += left == intro ? -30 : 20;
- }
- int nextState = state;
- nextState %= mod;
- nextState *= 3;
- nextState += intro;
- max = Math.max(max, temp + dfs(x, y + 1, ic - 1, ec, nextState));
+ int introScore = -1;
+ int extroScore = -1;
+ if (introverts > 0) {
+ int newBoard = ((board << 2) | INTROVERT) & tmask;
+ introScore =
+ 120
+ + adjust(board, INTROVERT, n, index)
+ + maxHappiness(
+ index + 1,
+ m,
+ n,
+ introverts - 1,
+ extroverts,
+ newBoard,
+ dp,
+ tmask);
+ }
+ if (extroverts > 0) {
+ int newBoard = ((board << 2) | EXTROVERT) & tmask;
+ extroScore =
+ 40
+ + adjust(board, EXTROVERT, n, index)
+ + maxHappiness(
+ index + 1,
+ m,
+ n,
+ introverts,
+ extroverts - 1,
+ newBoard,
+ dp,
+ tmask);
}
- // 3 - place extro
- if (ec > 0) {
- int temp = 40;
- if (x > 0 && up != notPlace) {
- temp += 20;
- temp += up == intro ? -30 : 20;
+ int newBoard = ((board << 2) | NONE) & tmask;
+ int skip = maxHappiness(index + 1, m, n, introverts, extroverts, newBoard, dp, tmask);
+ dp[index][introverts][extroverts][board] = Math.max(skip, Math.max(introScore, extroScore));
+ return dp[index][introverts][extroverts][board];
+ }
+
+ private int adjust(int board, int thisIs, int col, int index) {
+ int shiftBy = 2 * (col - 1);
+ int left = board & 0x03;
+ if (index % col == 0) {
+ left = NONE;
+ }
+ int up = (board >> shiftBy) & 0x03;
+ int[] combination = new int[] {left, up};
+ int adjustment = 0;
+ for (int neighbor : combination) {
+ if (neighbor == NONE) {
+ continue;
}
- if (y > 0 && left != notPlace) {
- temp += 20;
- temp += left == intro ? -30 : 20;
+ if (neighbor == INTROVERT && thisIs == INTROVERT) {
+ adjustment -= 60;
+ } else if (neighbor == INTROVERT && thisIs == EXTROVERT) {
+ adjustment -= 10;
+ } else if (neighbor == EXTROVERT && thisIs == INTROVERT) {
+ adjustment -= 10;
+ } else if (neighbor == EXTROVERT && thisIs == EXTROVERT) {
+ adjustment += 40;
}
- int nextState = state;
- nextState %= mod;
- nextState *= 3;
- nextState += extro;
- max = Math.max(max, temp + dfs(x, y + 1, ic, ec - 1, nextState));
}
- dp[x][y][ic][ec][state] = max;
- return max;
+ return adjustment;
+ }
+
+ public int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {
+ int[][][][] dp = new int[m * n][introvertsCount + 1][extrovertsCount + 1][(1 << (2 * n))];
+ int tmask = (1 << (2 * n)) - 1;
+ return maxHappiness(0, m, n, introvertsCount, extrovertsCount, 0, dp, tmask);
}
}
diff --git a/src/main/java/g1601_1700/s1663_smallest_string_with_a_given_numeric_value/Solution.java b/src/main/java/g1601_1700/s1663_smallest_string_with_a_given_numeric_value/Solution.java
index 9b05a99f7..21ffdd4fa 100644
--- a/src/main/java/g1601_1700/s1663_smallest_string_with_a_given_numeric_value/Solution.java
+++ b/src/main/java/g1601_1700/s1663_smallest_string_with_a_given_numeric_value/Solution.java
@@ -10,7 +10,7 @@ public String getSmallestString(int n, int k) {
Arrays.fill(res, 'a');
k -= n;
while (k > 0) {
- res[--n] += Math.min(25, k);
+ res[--n] += (char) Math.min(25, k);
k -= Math.min(25, k);
}
return String.valueOf(res);
diff --git a/src/main/java/g1601_1700/s1679_max_number_of_k_sum_pairs/Solution.java b/src/main/java/g1601_1700/s1679_max_number_of_k_sum_pairs/Solution.java
index 965d430e3..671a5ab51 100644
--- a/src/main/java/g1601_1700/s1679_max_number_of_k_sum_pairs/Solution.java
+++ b/src/main/java/g1601_1700/s1679_max_number_of_k_sum_pairs/Solution.java
@@ -1,6 +1,6 @@
package g1601_1700.s1679_max_number_of_k_sum_pairs;
-// #Medium #Array #Hash_Table #Sorting #Two_Pointers
+// #Medium #Array #Hash_Table #Sorting #Two_Pointers #LeetCode_75_Two_Pointers
// #2022_04_21_Time_20_ms_(91.22%)_Space_52.7_MB_(87.98%)
import java.util.Arrays;
diff --git a/src/main/java/g1701_1800/s1703_minimum_adjacent_swaps_for_k_consecutive_ones/Solution.java b/src/main/java/g1701_1800/s1703_minimum_adjacent_swaps_for_k_consecutive_ones/Solution.java
index 96b682dc6..4dac6ad58 100644
--- a/src/main/java/g1701_1800/s1703_minimum_adjacent_swaps_for_k_consecutive_ones/Solution.java
+++ b/src/main/java/g1701_1800/s1703_minimum_adjacent_swaps_for_k_consecutive_ones/Solution.java
@@ -32,7 +32,7 @@ private long getSum(int[] arr, int l, int h, long[] sum) {
int mid = l + (h - l) / 2;
int k = h - l + 1;
int radius = mid - l;
- long res = sum[h + 1] - sum[mid + 1] - (sum[mid] - sum[l]) - (1 + radius) * radius;
+ long res = sum[h + 1] - sum[mid + 1] - (sum[mid] - sum[l]) - (long) (1 + radius) * radius;
if (k % 2 == 0) {
res = res - arr[mid] - (radius + 1);
}
diff --git a/src/main/java/g1701_1800/s1704_determine_if_string_halves_are_alike/Solution.java b/src/main/java/g1701_1800/s1704_determine_if_string_halves_are_alike/Solution.java
index 1c1a1b792..11592e7da 100644
--- a/src/main/java/g1701_1800/s1704_determine_if_string_halves_are_alike/Solution.java
+++ b/src/main/java/g1701_1800/s1704_determine_if_string_halves_are_alike/Solution.java
@@ -4,7 +4,7 @@
public class Solution {
public boolean halvesAreAlike(String s) {
- if (s.length() < 1) {
+ if (s.isEmpty()) {
return false;
}
return countVowel(0, s.length() / 2, s) == countVowel(s.length() / 2, s.length(), s);
diff --git a/src/main/java/g1701_1800/s1732_find_the_highest_altitude/Solution.java b/src/main/java/g1701_1800/s1732_find_the_highest_altitude/Solution.java
index c7387ec64..500917a43 100644
--- a/src/main/java/g1701_1800/s1732_find_the_highest_altitude/Solution.java
+++ b/src/main/java/g1701_1800/s1732_find_the_highest_altitude/Solution.java
@@ -1,6 +1,7 @@
package g1701_1800.s1732_find_the_highest_altitude;
-// #Easy #Array #Prefix_Sum #2022_04_28_Time_0_ms_(100.00%)_Space_40.1_MB_(83.65%)
+// #Easy #Array #Prefix_Sum #LeetCode_75_Prefix_Sum
+// #2022_04_28_Time_0_ms_(100.00%)_Space_40.1_MB_(83.65%)
public class Solution {
public int largestAltitude(int[] gain) {
diff --git a/src/main/java/g1701_1800/s1764_form_array_by_concatenating_subarrays_of_another_array/Solution.java b/src/main/java/g1701_1800/s1764_form_array_by_concatenating_subarrays_of_another_array/Solution.java
index e64a88dc9..2b1f59592 100644
--- a/src/main/java/g1701_1800/s1764_form_array_by_concatenating_subarrays_of_another_array/Solution.java
+++ b/src/main/java/g1701_1800/s1764_form_array_by_concatenating_subarrays_of_another_array/Solution.java
@@ -7,17 +7,17 @@
public class Solution {
public boolean canChoose(int[][] groups, int[] nums) {
int prev = 0;
- for (int i = 0; i < groups.length; i++) {
- int[] temp = new int[groups[i].length];
- if (prev + groups[i].length > nums.length) {
+ for (int[] group : groups) {
+ int[] temp = new int[group.length];
+ if (prev + group.length > nums.length) {
return false;
}
int index = 0;
int j;
- for (j = prev; j < prev + groups[i].length; j++) {
+ for (j = prev; j < prev + group.length; j++) {
temp[index++] = nums[j];
}
- if (Arrays.equals(temp, groups[i])) {
+ if (Arrays.equals(temp, group)) {
prev = j;
continue;
}
@@ -28,7 +28,7 @@ public boolean canChoose(int[][] groups, int[] nums) {
temp[l] = temp[l + 1];
}
temp[l] = nums[k];
- if (Arrays.equals(temp, groups[i])) {
+ if (Arrays.equals(temp, group)) {
prev = k + 1;
break;
}
diff --git a/src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java b/src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java
index 4a60ee249..f0fcde621 100644
--- a/src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java
+++ b/src/main/java/g1701_1800/s1768_merge_strings_alternately/Solution.java
@@ -1,6 +1,6 @@
package g1701_1800.s1768_merge_strings_alternately;
-// #Easy #String #Two_Pointers #Programming_Skills_I_Day_8_String
+// #Easy #String #Two_Pointers #LeetCode_75_Array/String #Programming_Skills_I_Day_8_String
// #2022_04_27_Time_1_ms_(86.26%)_Space_41.7_MB_(79.68%)
public class Solution {
diff --git a/src/main/java/g1701_1800/s1770_maximum_score_from_performing_multiplication_operations/Solution.java b/src/main/java/g1701_1800/s1770_maximum_score_from_performing_multiplication_operations/Solution.java
index afcbdf92f..f34c1ebeb 100644
--- a/src/main/java/g1701_1800/s1770_maximum_score_from_performing_multiplication_operations/Solution.java
+++ b/src/main/java/g1701_1800/s1770_maximum_score_from_performing_multiplication_operations/Solution.java
@@ -1,6 +1,6 @@
package g1701_1800.s1770_maximum_score_from_performing_multiplication_operations;
-// #Medium #Array #Dynamic_Programming #2022_04_30_Time_31_ms_(92.41%)_Space_53.2_MB_(88.74%)
+// #Hard #Array #Dynamic_Programming #2022_04_30_Time_31_ms_(92.41%)_Space_53.2_MB_(88.74%)
public class Solution {
public int maximumScore(int[] nums, int[] mult) {
diff --git a/src/main/java/g1801_1900/s1815_maximum_number_of_groups_getting_fresh_donuts/Solution.java b/src/main/java/g1801_1900/s1815_maximum_number_of_groups_getting_fresh_donuts/Solution.java
index 8060c27df..adf572e28 100644
--- a/src/main/java/g1801_1900/s1815_maximum_number_of_groups_getting_fresh_donuts/Solution.java
+++ b/src/main/java/g1801_1900/s1815_maximum_number_of_groups_getting_fresh_donuts/Solution.java
@@ -1,60 +1,89 @@
package g1801_1900.s1815_maximum_number_of_groups_getting_fresh_donuts;
// #Hard #Array #Dynamic_Programming #Bit_Manipulation #Bitmask #Memoization
-// #2022_05_03_Time_7_ms_(86.67%)_Space_43.6_MB_(73.33%)
+// #2025_02_21_Time_2_ms_(100.00%)_Space_41.56_MB_(100.00%)
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Solution {
- private static final Map MAP = new HashMap<>();
-
public int maxHappyGroups(int batchSize, int[] groups) {
- int[] count = new int[batchSize];
- int res = 0;
- int remGroup = 0;
- for (int group : groups) {
- int g = group % batchSize;
- if (g == 0) {
- res++;
- } else if (count[batchSize - g] > 0) {
- remGroup--;
- res++;
- count[batchSize - g]--;
- } else {
- count[g]++;
- remGroup++;
- }
+ if (batchSize == 1) {
+ return groups.length;
+ }
+ int[] withSize = new int[batchSize];
+ for (int size : groups) {
+ withSize[size % batchSize]++;
+ }
+ int fromZero = withSize[0];
+ withSize[0] = 0;
+ int fromEnds = 0;
+ for (int l = 1, r = batchSize - 1; l < r; l++, r--) {
+ int usable = Math.min(withSize[l], withSize[r]);
+ fromEnds += usable;
+ withSize[l] -= usable;
+ withSize[r] -= usable;
}
- res += dfs(0, remGroup, count, batchSize);
- return res;
+ int fromMid = 0;
+ if (batchSize % 2 == 0) {
+ fromMid = withSize[batchSize / 2] / 2;
+ withSize[batchSize / 2] -= fromMid * 2;
+ }
+ return get(pruneEnd(withSize), batchSize, 0, new HashMap<>())
+ + fromZero
+ + fromEnds
+ + fromMid;
}
- private int dfs(int curr, int remain, int[] count, int batch) {
- if (remain == 0) {
- return 0;
+ private int get(int[] ar, int batchSize, int rem, Map cache) {
+ long hash = 0;
+ for (int e : ar) {
+ hash = hash * 69L + e;
}
- int res = 0;
- String s = Arrays.toString(count);
- if (MAP.containsKey(s)) {
- return MAP.get(s);
+ Integer fromCache = cache.get(hash);
+ if (fromCache != null) {
+ return fromCache;
}
- if (curr == 0) {
- res++;
- curr = batch;
+ if (zeroed(ar)) {
+ cache.put(hash, 0);
+ return 0;
}
- int val = 0;
- for (int i = 1; i < count.length; i++) {
- if (count[i] == 0) {
+ int max = 0;
+ for (int i = 0; i < ar.length; i++) {
+ if (ar[i] == 0) {
continue;
}
- count[i]--;
- val = Math.max(val, dfs((curr - i + batch) % batch, remain - 1, count, batch));
- count[i]++;
+ ar[i]--;
+ int from = get(ar, batchSize, (rem + i) % batchSize, cache);
+ if (from > max) {
+ max = from;
+ }
+ ar[i]++;
+ }
+ int score = max + (rem == 0 ? 1 : 0);
+ cache.put(hash, score);
+ return score;
+ }
+
+ private int[] pruneEnd(int[] in) {
+ int endingZeros = 0;
+ for (int i = in.length - 1; i >= 0; i--) {
+ if (in[i] != 0) {
+ break;
+ }
+ endingZeros++;
+ }
+ int[] out = new int[in.length - endingZeros];
+ System.arraycopy(in, 0, out, 0, out.length);
+ return out;
+ }
+
+ private boolean zeroed(int[] ar) {
+ for (int e : ar) {
+ if (e != 0) {
+ return false;
+ }
}
- res += val;
- MAP.put(s, res);
- return res;
+ return true;
}
}
diff --git a/src/main/java/g1801_1900/s1825_finding_mk_average/MKAverage.java b/src/main/java/g1801_1900/s1825_finding_mk_average/MKAverage.java
index 05b80f672..a5404e32a 100644
--- a/src/main/java/g1801_1900/s1825_finding_mk_average/MKAverage.java
+++ b/src/main/java/g1801_1900/s1825_finding_mk_average/MKAverage.java
@@ -1,141 +1,70 @@
package g1801_1900.s1825_finding_mk_average;
// #Hard #Design #Heap_Priority_Queue #Ordered_Set #Queue
-// #2022_05_06_Time_83_ms_(60.59%)_Space_96.3_MB_(77.83%)
+// #2025_03_13_Time_37_ms_(100.00%)_Space_100.84_MB_(46.09%)
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.TreeMap;
+import java.util.LinkedList;
+import java.util.TreeSet;
-@SuppressWarnings("java:S2184")
public class MKAverage {
- private final double m;
- private final double k;
- private final double c;
- private double avg;
- private final Bst middle;
- private final Bst min;
- private final Bst max;
- private final Deque q;
+ private final int capacity;
+ private final int boundary;
+ private final int[] nums;
+ private final TreeSet numSet;
+ private final LinkedList order;
public MKAverage(int m, int k) {
- this.m = m;
- this.k = k;
- this.c = m - k * 2;
- this.avg = 0;
- this.middle = new Bst();
- this.min = new Bst();
- this.max = new Bst();
- this.q = new ArrayDeque<>();
+ this.capacity = m;
+ this.boundary = k;
+ nums = new int[100001];
+ numSet = new TreeSet<>();
+ order = new LinkedList<>();
}
public void addElement(int num) {
- if (min.size < k) {
- min.add(num);
- q.offer(num);
- return;
- }
- if (max.size < k) {
- min.add(num);
- max.add(min.removeMax());
- q.offer(num);
- return;
- }
-
- if (num >= min.lastKey() && num <= max.firstKey()) {
- middle.add(num);
- avg += num / c;
- } else if (num < min.lastKey()) {
- min.add(num);
- int val = min.removeMax();
- middle.add(val);
- avg += val / c;
- } else if (num > max.firstKey()) {
- max.add(num);
- int val = max.removeMin();
- middle.add(val);
- avg += val / c;
- }
-
- q.offer(num);
-
- if (q.size() > m) {
- num = q.poll();
- if (middle.containsKey(num)) {
- avg -= num / c;
- middle.remove(num);
- } else if (min.containsKey(num)) {
- min.remove(num);
- int val = middle.removeMin();
- avg -= val / c;
- min.add(val);
- } else if (max.containsKey(num)) {
- max.remove(num);
- int val = middle.removeMax();
- avg -= val / c;
- max.add(val);
+ if (order.size() == capacity) {
+ int numToDelete = order.removeFirst();
+ nums[numToDelete] = nums[numToDelete] - 1;
+ if (nums[numToDelete] == 0) {
+ numSet.remove(numToDelete);
}
}
+ nums[num]++;
+ numSet.add(num);
+ order.add(num);
}
public int calculateMKAverage() {
- if (q.size() < m) {
- return -1;
- }
- return (int) avg;
- }
-
- static class Bst {
- TreeMap map;
- int size;
-
- public Bst() {
- this.map = new TreeMap<>();
- this.size = 0;
- }
-
- void add(int num) {
- int count = map.getOrDefault(num, 0) + 1;
- map.put(num, count);
- size++;
- }
-
- void remove(int num) {
- int count = map.getOrDefault(num, 1) - 1;
- if (count > 0) {
- map.put(num, count);
- } else {
- map.remove(num);
+ if (order.size() == capacity) {
+ int skipCount = boundary;
+ int numsCount = capacity - 2 * boundary;
+ int freq = capacity - 2 * boundary;
+ int sum = 0;
+ for (int num : numSet) {
+ int count = nums[num];
+ if (skipCount < 0) {
+ sum += num * Math.min(count, numsCount);
+ numsCount -= Math.min(count, numsCount);
+ } else {
+ skipCount -= count;
+ if (skipCount < 0) {
+ sum += num * Math.min(Math.abs(skipCount), numsCount);
+ numsCount -= Math.min(Math.abs(skipCount), numsCount);
+ }
+ }
+ if (numsCount == 0) {
+ break;
+ }
}
- size--;
- }
-
- int removeMin() {
- int key = map.firstKey();
-
- remove(key);
-
- return key;
- }
-
- int removeMax() {
- int key = map.lastKey();
-
- remove(key);
-
- return key;
- }
-
- boolean containsKey(int key) {
- return map.containsKey(key);
- }
-
- int firstKey() {
- return map.firstKey();
- }
-
- int lastKey() {
- return map.lastKey();
+ return sum / freq;
}
+ return -1;
}
}
+
+/*
+ * Your MKAverage object will be instantiated and called as such:
+ * MKAverage obj = new MKAverage(m, k);
+ * obj.addElement(num);
+ * int param_2 = obj.calculateMKAverage();
+ */
diff --git a/src/main/java/g1801_1900/s1837_sum_of_digits_in_base_k/Solution.java b/src/main/java/g1801_1900/s1837_sum_of_digits_in_base_k/Solution.java
index aa01dfd1e..1f091a150 100644
--- a/src/main/java/g1801_1900/s1837_sum_of_digits_in_base_k/Solution.java
+++ b/src/main/java/g1801_1900/s1837_sum_of_digits_in_base_k/Solution.java
@@ -1,13 +1,17 @@
package g1801_1900.s1837_sum_of_digits_in_base_k;
-// #Easy #Math #2022_05_07_Time_1_ms_(10.42%)_Space_38.9_MB_(91.55%)
+// #Easy #Math #2025_02_23_Time_0_ms_(100.00%)_Space_40.80_MB_(21.87%)
public class Solution {
public int sumBase(int n, int k) {
- String str = Integer.toString(Integer.parseInt(n + "", 10), k);
+ int a;
int sum = 0;
- for (char c : str.toCharArray()) {
- sum += Character.getNumericValue(c);
+ int b;
+ while (n != 0) {
+ a = n % k;
+ b = n / k;
+ sum += a;
+ n = b;
}
return sum;
}
diff --git a/src/main/java/g1801_1900/s1893_check_if_all_the_integers_in_a_range_are_covered/Solution.java b/src/main/java/g1801_1900/s1893_check_if_all_the_integers_in_a_range_are_covered/Solution.java
index 0e8b94eb0..4a12f2eba 100644
--- a/src/main/java/g1801_1900/s1893_check_if_all_the_integers_in_a_range_are_covered/Solution.java
+++ b/src/main/java/g1801_1900/s1893_check_if_all_the_integers_in_a_range_are_covered/Solution.java
@@ -9,7 +9,7 @@ public boolean isCovered(int[][] ranges, int left, int right) {
int start = range[0];
int end = range[ranges[0].length - 1];
temp[start] += 1;
- temp[end + 1] += -1;
+ temp[end + 1] -= 1;
}
for (int i = 1; i < temp.length; i++) {
temp[i] += temp[i - 1];
diff --git a/src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java b/src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java
index 700eb2ff3..4e0cda338 100644
--- a/src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java
+++ b/src/main/java/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.java
@@ -5,7 +5,7 @@
public class Solution {
public int maximumRemovals(String s, String p, int[] removable) {
- if (s == null || s.length() == 0) {
+ if (s == null || s.isEmpty()) {
return 0;
}
// binary search for the k which need to be removed
diff --git a/src/main/java/g1901_2000/s1903_largest_odd_number_in_string/Solution.java b/src/main/java/g1901_2000/s1903_largest_odd_number_in_string/Solution.java
index 7e297e025..85a19ff77 100644
--- a/src/main/java/g1901_2000/s1903_largest_odd_number_in_string/Solution.java
+++ b/src/main/java/g1901_2000/s1903_largest_odd_number_in_string/Solution.java
@@ -1,14 +1,17 @@
package g1901_2000.s1903_largest_odd_number_in_string;
-// #Easy #String #Math #Greedy #2022_05_11_Time_6_ms_(23.18%)_Space_43.2_MB_(81.76%)
+// #Easy #String #Math #Greedy #2024_03_29_Time_1_ms_(100.00%)_Space_45.3_MB_(55.03%)
public class Solution {
public String largestOddNumber(String num) {
+ String str = "";
for (int i = num.length() - 1; i >= 0; i--) {
- if (Integer.parseInt("" + num.charAt(i)) % 2 == 1) {
- return num.substring(0, i + 1);
+ char c = num.charAt(i);
+ if (c % 2 == 1) {
+ str = num.substring(0, i + 1);
+ break;
}
}
- return "";
+ return str;
}
}
diff --git a/src/main/java/g1901_2000/s1916_count_ways_to_build_rooms_in_an_ant_colony/Solution.java b/src/main/java/g1901_2000/s1916_count_ways_to_build_rooms_in_an_ant_colony/Solution.java
index 75188b031..04a185a3b 100644
--- a/src/main/java/g1901_2000/s1916_count_ways_to_build_rooms_in_an_ant_colony/Solution.java
+++ b/src/main/java/g1901_2000/s1916_count_ways_to_build_rooms_in_an_ant_colony/Solution.java
@@ -46,7 +46,7 @@ private long[] dfs(int root) {
long com = 1;
for (long[] p : list) {
long choose = c(cnt, (int) (p[0]));
- cnt -= p[0];
+ cnt -= (int) p[0];
com = com * choose;
com %= MOD;
com = com * p[1];
diff --git a/src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java b/src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java
index 7e58a9512..39eae18ba 100644
--- a/src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java
+++ b/src/main/java/g1901_2000/s1926_nearest_exit_from_entrance_in_maze/Solution.java
@@ -1,6 +1,7 @@
package g1901_2000.s1926_nearest_exit_from_entrance_in_maze;
-// #Medium #Array #Breadth_First_Search #Matrix #Graph_Theory_I_Day_6_Matrix_Related_Problems
+// #Medium #Array #Breadth_First_Search #Matrix #LeetCode_75_Graphs/BFS
+// #Graph_Theory_I_Day_6_Matrix_Related_Problems
// #2022_05_14_Time_12_ms_(40.55%)_Space_43.3_MB_(92.19%)
import java.util.LinkedList;
diff --git a/src/main/java/g1901_2000/s1948_delete_duplicate_folders_in_system/Solution.java b/src/main/java/g1901_2000/s1948_delete_duplicate_folders_in_system/Solution.java
index a29a47039..c83d84d85 100644
--- a/src/main/java/g1901_2000/s1948_delete_duplicate_folders_in_system/Solution.java
+++ b/src/main/java/g1901_2000/s1948_delete_duplicate_folders_in_system/Solution.java
@@ -66,14 +66,14 @@ private void calculateHash() {
folder.calculateHash();
builder.append('#');
builder.append(foldername);
- if (folder.folderHash.length() > 0) {
+ if (!folder.folderHash.isEmpty()) {
builder.append('(');
builder.append(folder.folderHash);
builder.append(')');
}
}
folderHash = builder.toString();
- if (folderHash.length() > 0) {
+ if (!folderHash.isEmpty()) {
ArrayList duplicateFolders =
duplicates.computeIfAbsent(folderHash, k -> new ArrayList<>());
duplicateFolders.add(this);
diff --git a/src/main/java/g1901_2000/s1993_operations_on_tree/LockingTree.java b/src/main/java/g1901_2000/s1993_operations_on_tree/LockingTree.java
index 9d48e1db6..b6968574e 100644
--- a/src/main/java/g1901_2000/s1993_operations_on_tree/LockingTree.java
+++ b/src/main/java/g1901_2000/s1993_operations_on_tree/LockingTree.java
@@ -1,82 +1,103 @@
package g1901_2000.s1993_operations_on_tree;
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Tree #Design
-// #2022_05_19_Time_394_ms_(23.03%)_Space_167.4_MB_(5.26%)
+// #2024_03_29_Time_58_ms_(99.38%)_Space_47.6_MB_(83.13%)
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
+@SuppressWarnings("unchecked")
public class LockingTree {
- private int[][] a;
- private HashMap> map = new HashMap<>();
+ private List[] graph;
+ private boolean[] locked;
+ private int[] parent;
+ private int[] users;
+ private int[] control;
public LockingTree(int[] parent) {
- int l = parent.length;
- a = new int[l][2];
- for (int i = 0; i < l; i++) {
- a[i][0] = parent[i];
- a[i][1] = -1;
- map.putIfAbsent(parent[i], new ArrayList<>());
- List p = map.get(parent[i]);
- p.add(i);
- map.put(parent[i], p);
+ int n = parent.length;
+ this.parent = parent;
+ graph = new ArrayList[n];
+ for (int i = 0; i < n; i++) {
+ graph[i] = new ArrayList<>();
}
+ for (int i = 1; i < n; i++) {
+ graph[parent[i]].add(i);
+ }
+ locked = new boolean[n];
+ users = new int[n];
+ control = new int[n];
}
- public boolean lock(int num, int user) {
- int userId = a[num][1];
- if (userId == -1) {
- a[num][1] = user;
- return true;
- }
- return false;
+ private void setLock(int id, int user) {
+ locked[id] = true;
+ users[id] = user;
}
- public boolean unlock(int num, int user) {
- int y = a[num][1];
- if (y == user) {
- a[num][1] = -1;
- return true;
+ private void subNodeUnlock(int id) {
+ for (int child : graph[id]) {
+ locked[child] = false;
+ if (control[child] <= 0) {
+ continue;
+ }
+ control[child] = 0;
+ subNodeUnlock(child);
}
- return false;
}
- public boolean upgrade(int num, int user) {
- int par = num;
- while (par >= 0) {
- int lop = a[par][1];
- if (lop != -1) {
- return false;
- }
- par = a[par][0];
+ public boolean lock(int id, int user) {
+ if (locked[id]) {
+ return false;
}
- int f = 0;
- LinkedList que = new LinkedList<>();
- int[] v = new int[a.length];
- que.add(num);
- v[num] = 1;
- while (!que.isEmpty()) {
- int t = que.get(0);
- que.remove(0);
- List p = map.getOrDefault(t, new ArrayList<>());
- for (int e : p) {
- if (a[e][1] != -1) {
- f = 1;
- a[e][1] = -1;
+ setLock(id, user);
+ if (control[id] == 0) {
+ int node = parent[id];
+ while (node != -1) {
+ control[node]++;
+ if (locked[node] || control[node] > 1) {
+ break;
}
- if (v[e] == 0) {
- que.add(e);
- v[e] = 1;
+ node = parent[node];
+ }
+ }
+ return true;
+ }
+
+ public boolean unlock(int id, int user) {
+ if (!locked[id] || users[id] != user) {
+ return false;
+ }
+ locked[id] = false;
+ if (control[id] == 0) {
+ int node = parent[id];
+ while (node != -1) {
+ control[node]--;
+ if (locked[node] || control[node] >= 1) {
+ break;
}
+ node = parent[node];
+ }
+ }
+ return true;
+ }
+
+ public boolean upgrade(int id, int user) {
+ if (locked[id] || control[id] == 0) {
+ return false;
+ }
+ int cur = parent[id];
+ while (cur != -1) {
+ if (locked[cur]) {
+ return false;
}
+ cur = parent[cur];
}
- if (f == 1) {
- a[num][1] = user;
- return true;
+ setLock(id, user);
+ if (control[id] > 0) {
+ control[id] = 0;
+ subNodeUnlock(id);
}
- return false;
+ return true;
}
}
diff --git a/src/main/java/g2001_2100/s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter/Solution.java b/src/main/java/g2001_2100/s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter/Solution.java
index 4a75f251c..3212b21cd 100644
--- a/src/main/java/g2001_2100/s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter/Solution.java
+++ b/src/main/java/g2001_2100/s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter/Solution.java
@@ -12,7 +12,7 @@ public String smallestSubsequence(String s, int k, char letter, int repetition)
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); count -= s.charAt(i++) == letter ? 1 : 0) {
while (sb.length() + s.length() > i + k
- && sb.length() > 0
+ && !sb.isEmpty()
&& s.charAt(i) < sb.charAt(sb.length() - 1)
&& (sb.charAt(sb.length() - 1) != letter || count != repetition)) {
repetition += sb.charAt(sb.length() - 1) == letter ? 1 : 0;
diff --git a/src/main/java/g2001_2100/s2054_two_best_non_overlapping_events/Solution.java b/src/main/java/g2001_2100/s2054_two_best_non_overlapping_events/Solution.java
index beecfb0c2..016313511 100644
--- a/src/main/java/g2001_2100/s2054_two_best_non_overlapping_events/Solution.java
+++ b/src/main/java/g2001_2100/s2054_two_best_non_overlapping_events/Solution.java
@@ -1,7 +1,7 @@
package g2001_2100.s2054_two_best_non_overlapping_events;
// #Medium #Array #Dynamic_Programming #Sorting #Binary_Search #Heap_Priority_Queue
-// #2022_05_24_Time_58_ms(70.59%)_Space_109.2_MB_(88.24%)
+// #2022_05_24_Time_58_ms_(70.59%)_Space_109.2_MB_(88.24%)
import java.util.Arrays;
diff --git a/src/main/java/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.java b/src/main/java/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.java
index 253ae4d33..1686f95a2 100644
--- a/src/main/java/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.java
+++ b/src/main/java/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.java
@@ -1,7 +1,7 @@
package g2001_2100.s2056_number_of_valid_move_combinations_on_chessboard;
// #Hard #Array #String #Simulation #Backtracking
-// #2022_05_30_Time_433_ms_(24.83%)_Space_144.4_MB_(12.75%)
+// #2024_05_13_Time_195_ms_(41.18%)_Space_44.8_MB_(47.06%)
import java.util.ArrayList;
import java.util.HashSet;
@@ -55,7 +55,7 @@ public int countCombinations(String[] pieces, int[][] positions) {
return dfs(positions, endPosition, new int[pieces.length], 0);
}
- private int dfs(int[][] positions, ArrayList[] stop, int[] stopIndex, int cur) {
+ private int dfs(int[][] positions, ArrayList[] stop, int[] stopIndex, int cur) {
if (cur == stopIndex.length) {
int[][] p = new int[positions.length][2];
for (int i = 0; i < p.length; i++) {
diff --git a/src/main/java/g2001_2100/s2062_count_vowel_substrings_of_a_string/Solution.java b/src/main/java/g2001_2100/s2062_count_vowel_substrings_of_a_string/Solution.java
index 566cbdfa8..a6f2b4111 100644
--- a/src/main/java/g2001_2100/s2062_count_vowel_substrings_of_a_string/Solution.java
+++ b/src/main/java/g2001_2100/s2062_count_vowel_substrings_of_a_string/Solution.java
@@ -1,32 +1,45 @@
package g2001_2100.s2062_count_vowel_substrings_of_a_string;
-// #Easy #String #Hash_Table #2022_05_29_Time_34_ms_(23.83%)_Space_41.9_MB_(71.28%)
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+// #Easy #String #Hash_Table #2024_03_29_Time_1_ms_(99.82%)_Space_41.5_MB_(72.24%)
public class Solution {
public int countVowelSubstrings(String word) {
- int count = 0;
- Set vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
- Set window = new HashSet<>();
- for (int i = 0; i < word.length(); i++) {
- window.clear();
- if (vowels.contains(word.charAt(i))) {
- window.add(word.charAt(i));
- for (int j = i + 1; j < word.length(); j++) {
- if (!vowels.contains(word.charAt(j))) {
- break;
- } else {
- window.add(word.charAt(j));
- if (window.size() == 5) {
- count++;
- }
- }
+ final int length = word.length();
+ boolean[] vows = new boolean[128];
+ vows['a'] = true;
+ vows['e'] = true;
+ vows['i'] = true;
+ vows['o'] = true;
+ vows['u'] = true;
+ int[] counts = new int[128];
+ int uniqVows = 0;
+ int originalBegin = 0;
+ int begin = 0;
+ int result = 0;
+ for (int i = 0; i < length; i++) {
+ char ch = word.charAt(i);
+ if (vows[ch]) {
+ counts[ch]++;
+ if (counts[ch] == 1) {
+ uniqVows++;
+ }
+ while (uniqVows == 5) {
+ uniqVows -= --counts[word.charAt(begin)] == 0 ? 1 : 0;
+ begin++;
+ }
+ result += begin - originalBegin;
+ } else {
+ if (uniqVows != 0) {
+ uniqVows = 0;
+ counts['a'] = 0;
+ counts['e'] = 0;
+ counts['i'] = 0;
+ counts['o'] = 0;
+ counts['u'] = 0;
}
+ originalBegin = begin = i + 1;
}
}
- return count;
+ return result;
}
}
diff --git a/src/main/java/g2001_2100/s2090_k_radius_subarray_averages/Solution.java b/src/main/java/g2001_2100/s2090_k_radius_subarray_averages/Solution.java
index 58925734d..e34a50061 100644
--- a/src/main/java/g2001_2100/s2090_k_radius_subarray_averages/Solution.java
+++ b/src/main/java/g2001_2100/s2090_k_radius_subarray_averages/Solution.java
@@ -14,7 +14,7 @@ public int[] getAverages(int[] nums, int k) {
return res;
}
long sum = 0;
- long range = 2 * k + 1L;
+ long range = 2L * k + 1L;
// take sum of all elements from 0 to k*2 index
for (int i = 0; i <= 2 * k; ++i) {
sum += nums[i];
diff --git a/src/main/java/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/Solution.java b/src/main/java/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/Solution.java
index 3235ec42a..2b9e1329f 100644
--- a/src/main/java/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/Solution.java
+++ b/src/main/java/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/Solution.java
@@ -1,6 +1,7 @@
package g2001_2100.s2095_delete_the_middle_node_of_a_linked_list;
-// #Medium #Two_Pointers #Linked_List #2022_05_24_Time_4_ms_(95.21%)_Space_221.2_MB_(35.96%)
+// #Medium #Two_Pointers #Linked_List #LeetCode_75_LinkedList
+// #2022_05_24_Time_4_ms_(95.21%)_Space_221.2_MB_(35.96%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/Solution.java b/src/main/java/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/Solution.java
index 797b46259..e4c6e7745 100644
--- a/src/main/java/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/Solution.java
+++ b/src/main/java/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/Solution.java
@@ -15,7 +15,7 @@ private boolean find(TreeNode n, int val, StringBuilder sb) {
} else if (n.right != null && find(n.right, val, sb)) {
sb.append("R");
}
- return sb.length() > 0;
+ return !sb.isEmpty();
}
public String getDirections(TreeNode root, int startValue, int destValue) {
@@ -28,11 +28,6 @@ public String getDirections(TreeNode root, int startValue, int destValue) {
while (i < maxI && s.charAt(s.length() - i - 1) == d.charAt(d.length() - i - 1)) {
++i;
}
- StringBuilder result = new StringBuilder();
- for (int j = 0; j < s.length() - i; j++) {
- result.append("U");
- }
- result.append(d.reverse().substring(i));
- return result.toString();
+ return "U".repeat(Math.max(0, s.length() - i)) + d.reverse().substring(i);
}
}
diff --git a/src/main/java/g2101_2200/s2104_sum_of_subarray_ranges/Solution.java b/src/main/java/g2101_2200/s2104_sum_of_subarray_ranges/Solution.java
index 770e33a7f..fba444e01 100644
--- a/src/main/java/g2101_2200/s2104_sum_of_subarray_ranges/Solution.java
+++ b/src/main/java/g2101_2200/s2104_sum_of_subarray_ranges/Solution.java
@@ -17,7 +17,7 @@ public long subArrayRanges(int[] nums) {
int cur = q.removeLast();
int left = q.peekLast();
int right = i;
- sum += 1L * (cur - left) * (right - cur) * nums[cur];
+ sum += (long) (cur - left) * (right - cur) * nums[cur];
}
q.add(i);
}
@@ -29,7 +29,7 @@ public long subArrayRanges(int[] nums) {
int cur = q.removeLast();
int left = q.peekLast();
int right = i;
- sum -= 1L * (cur - left) * (right - cur) * nums[cur];
+ sum -= (long) (cur - left) * (right - cur) * nums[cur];
}
q.add(i);
}
diff --git a/src/main/java/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/Solution.java b/src/main/java/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/Solution.java
index dbc43761d..355b4ed05 100644
--- a/src/main/java/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/Solution.java
+++ b/src/main/java/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/Solution.java
@@ -1,45 +1,35 @@
package g2101_2200.s2111_minimum_operations_to_make_the_array_k_increasing;
-// #Hard #Array #Binary_Search #2022_05_31_Time_97_ms_(22.90%)_Space_123.6_MB_(54.96%)
+// #Hard #Array #Binary_Search #2024_03_29_Time_12_ms_(100.00%)_Space_60.7_MB_(31.91%)
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
public class Solution {
- public int kIncreasing(int[] a, int k) {
- int n = a.length;
+ public int kIncreasing(int[] arr, int k) {
+ int n = arr.length;
int res = 0;
- for (int s = 0; s < k; s++) {
- List dp = new ArrayList<>();
- for (int i = s; i < n; i += k) {
- if (!bsearch(dp, a[i])) {
- dp.add(a[i]);
+ int[] dp = new int[n / k + 5];
+ for (int i = 0; i < k; i++) {
+ int lis = 0;
+ Arrays.fill(dp, 0);
+ for (int j = i; j < n; j += k) {
+ int low = 0;
+ int high = lis;
+ while (low < high) {
+ int mid = (low + high) >> 1;
+ if (arr[j] < dp[mid]) {
+ high = mid;
+ } else {
+ low = mid + 1;
+ }
+ }
+ dp[low] = arr[j];
+ if (high == lis) {
+ lis++;
}
}
- res += dp.size();
+ res += lis;
}
return n - res;
}
-
- private boolean bsearch(List dp, int target) {
- if (dp.isEmpty()) {
- return false;
- }
- int lo = 0;
- int hi = dp.size() - 1;
- while (lo < hi) {
- int mid = lo + (hi - lo) / 2;
- if (dp.get(mid) <= target) {
- lo = mid + 1;
- } else {
- hi = mid;
- }
- }
-
- if (dp.get(lo) > target) {
- dp.set(lo, target);
- return true;
- }
- return false;
- }
}
diff --git a/src/main/java/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/Solution.java b/src/main/java/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/Solution.java
index 78c2d2d46..94a325415 100644
--- a/src/main/java/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/Solution.java
+++ b/src/main/java/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/Solution.java
@@ -1,6 +1,7 @@
package g2101_2200.s2130_maximum_twin_sum_of_a_linked_list;
-// #Medium #Two_Pointers #Stack #Linked_List #2022_06_03_Time_9_ms_(57.92%)_Space_118.7_MB_(38.33%)
+// #Medium #Two_Pointers #Stack #Linked_List #LeetCode_75_LinkedList
+// #2022_06_03_Time_9_ms_(57.92%)_Space_118.7_MB_(38.33%)
import com_github_leetcode.ListNode;
diff --git a/src/main/java/g2201_2300/s2213_longest_substring_of_one_repeating_character/Solution.java b/src/main/java/g2201_2300/s2213_longest_substring_of_one_repeating_character/Solution.java
index a2b9731d6..b308fbc96 100644
--- a/src/main/java/g2201_2300/s2213_longest_substring_of_one_repeating_character/Solution.java
+++ b/src/main/java/g2201_2300/s2213_longest_substring_of_one_repeating_character/Solution.java
@@ -1,93 +1,73 @@
package g2201_2300.s2213_longest_substring_of_one_repeating_character;
// #Hard #Array #String #Ordered_Set #Segment_Tree
-// #2022_06_12_Time_141_ms_(86.81%)_Space_148.3_MB_(47.22%)
+// #2025_03_25_Time_79_ms_(89.74%)_Space_66.05_MB_(89.74%)
public class Solution {
- static class TreeNode {
- int start;
- int end;
- char leftChar;
- int leftCharLen;
- char rightChar;
- int rightCharLen;
- int max;
- TreeNode left;
- TreeNode right;
-
- TreeNode(int start, int end) {
- this.start = start;
- this.end = end;
- left = null;
- right = null;
- }
- }
+ private char[] ca;
public int[] longestRepeating(String s, String queryCharacters, int[] queryIndices) {
- char[] sChar = s.toCharArray();
- char[] qChar = queryCharacters.toCharArray();
- TreeNode root = buildTree(sChar, 0, sChar.length - 1);
- int[] result = new int[qChar.length];
- for (int i = 0; i < qChar.length; i++) {
- updateTree(root, queryIndices[i], qChar[i]);
- if (root != null) {
- result[i] = root.max;
- }
+ ca = s.toCharArray();
+ int[] result = new int[queryIndices.length];
+ SegmentTree root = new SegmentTree(0, ca.length);
+ for (int i = 0; i < queryIndices.length; i++) {
+ ca[queryIndices[i]] = queryCharacters.charAt(i);
+ root.update(queryIndices[i]);
+ result[i] = root.longest;
}
return result;
}
- private TreeNode buildTree(char[] s, int from, int to) {
- if (from > to) {
- return null;
- }
- TreeNode root = new TreeNode(from, to);
- if (from == to) {
- root.max = 1;
- root.rightChar = root.leftChar = s[from];
- root.leftCharLen = root.rightCharLen = 1;
- return root;
- }
- int middle = from + (to - from) / 2;
- root.left = buildTree(s, from, middle);
- root.right = buildTree(s, middle + 1, to);
- updateNode(root);
- return root;
- }
+ private class SegmentTree {
+ final int start;
+ final int end;
+ int longest;
+ int leftLength;
+ int rightLength;
+ SegmentTree left;
+ SegmentTree right;
- private void updateTree(TreeNode root, int index, char c) {
- if (root == null || root.start > index || root.end < index) {
- return;
- }
- if (root.start == index && root.end == index) {
- root.leftChar = root.rightChar = c;
- return;
+ SegmentTree(int start, int end) {
+ this.start = start;
+ this.end = end;
+ if (end - start > 1) {
+ int mid = (start + end) / 2;
+ left = new SegmentTree(start, mid);
+ right = new SegmentTree(mid, end);
+ merge();
+ } else {
+ longest = leftLength = rightLength = 1;
+ }
}
- updateTree(root.left, index, c);
- updateTree(root.right, index, c);
- updateNode(root);
- }
- private void updateNode(TreeNode root) {
- if (root == null) {
- return;
- }
- root.leftChar = root.left.leftChar;
- root.leftCharLen = root.left.leftCharLen;
- root.rightChar = root.right.rightChar;
- root.rightCharLen = root.right.rightCharLen;
- root.max = Math.max(root.left.max, root.right.max);
- if (root.left.rightChar == root.right.leftChar) {
- int len = root.left.rightCharLen + root.right.leftCharLen;
- if (root.left.leftChar == root.left.rightChar
- && root.left.leftCharLen == root.left.end - root.left.start + 1) {
- root.leftCharLen = len;
+ void update(int index) {
+ if (end - start == 1) {
+ return;
+ }
+ if (index < left.end) {
+ left.update(index);
+ } else {
+ right.update(index);
}
- if (root.right.leftChar == root.right.rightChar
- && root.right.leftCharLen == root.right.end - root.right.start + 1) {
- root.rightCharLen = len;
+ merge();
+ }
+
+ private void merge() {
+ longest = Math.max(left.longest, right.longest);
+ if (ca[left.end - 1] == ca[right.start]) {
+ longest = Math.max(longest, left.rightLength + right.leftLength);
+ leftLength =
+ (left.leftLength == left.end - left.start)
+ ? left.leftLength + right.leftLength
+ : left.leftLength;
+ rightLength =
+ (right.rightLength == right.end - right.start)
+ ? right.rightLength + left.rightLength
+ : right.rightLength;
+ } else {
+ leftLength = left.leftLength;
+ rightLength = right.rightLength;
}
- root.max = Math.max(root.max, len);
}
}
}
diff --git a/src/main/java/g2201_2300/s2215_find_the_difference_of_two_arrays/Solution.java b/src/main/java/g2201_2300/s2215_find_the_difference_of_two_arrays/Solution.java
index 8d3b49d51..9a953366d 100644
--- a/src/main/java/g2201_2300/s2215_find_the_difference_of_two_arrays/Solution.java
+++ b/src/main/java/g2201_2300/s2215_find_the_difference_of_two_arrays/Solution.java
@@ -1,6 +1,7 @@
package g2201_2300.s2215_find_the_difference_of_two_arrays;
-// #Easy #Array #Hash_Table #2022_06_09_Time_11_ms_(87.39%)_Space_43.2_MB_(77.06%)
+// #Easy #Array #Hash_Table #LeetCode_75_Hash_Map/Set
+// #2022_06_09_Time_11_ms_(87.39%)_Space_43.2_MB_(77.06%)
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/main/java/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/Solution.java b/src/main/java/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/Solution.java
index 23b6b8973..2bc93fd5b 100644
--- a/src/main/java/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/Solution.java
+++ b/src/main/java/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/Solution.java
@@ -32,6 +32,6 @@ public int largestInteger(int num) {
str[i] = temp;
str[swapIndex] = tempStr;
}
- return Integer.valueOf(new String(str));
+ return Integer.parseInt(new String(str));
}
}
diff --git a/src/main/java/g2201_2300/s2241_design_an_atm_machine/ATM.java b/src/main/java/g2201_2300/s2241_design_an_atm_machine/ATM.java
index fa0d76aca..dda24a218 100644
--- a/src/main/java/g2201_2300/s2241_design_an_atm_machine/ATM.java
+++ b/src/main/java/g2201_2300/s2241_design_an_atm_machine/ATM.java
@@ -1,6 +1,6 @@
package g2201_2300.s2241_design_an_atm_machine;
-// #Medium #Array #Greedy #Design #2022_06_08_Time_192_ms_(24.16%)_Space_120.4_MB_(5.07%)
+// #Medium #Array #Greedy #Design #2024_05_13_Time_55_ms_(94.44%)_Space_48.6_MB_(19.59%)
public class ATM {
private int[] nominals;
@@ -35,7 +35,7 @@ public int[] withdraw(int amount) {
return new int[] {-1};
}
for (int i = 0; i < 5; i++) {
- counts[i] += -delivery[i];
+ counts[i] -= delivery[i];
}
return delivery;
}
diff --git a/src/main/java/g2201_2300/s2262_total_appeal_of_a_string/Solution.java b/src/main/java/g2201_2300/s2262_total_appeal_of_a_string/Solution.java
index b2d2ad8b4..d43a24cb0 100644
--- a/src/main/java/g2201_2300/s2262_total_appeal_of_a_string/Solution.java
+++ b/src/main/java/g2201_2300/s2262_total_appeal_of_a_string/Solution.java
@@ -13,7 +13,7 @@ public long appealSum(String s) {
long res = 0;
for (int i = 0; i < len; i++) {
int idx = s.charAt(i) - 'a';
- res += (i - lastPos[idx]) * (len - i);
+ res += (long) (i - lastPos[idx]) * (len - i);
lastPos[idx] = i;
}
return res;
diff --git a/src/main/java/g2201_2300/s2272_substring_with_largest_variance/Solution.java b/src/main/java/g2201_2300/s2272_substring_with_largest_variance/Solution.java
index 343c665ba..ab1c9d536 100644
--- a/src/main/java/g2201_2300/s2272_substring_with_largest_variance/Solution.java
+++ b/src/main/java/g2201_2300/s2272_substring_with_largest_variance/Solution.java
@@ -1,6 +1,6 @@
package g2201_2300.s2272_substring_with_largest_variance;
-// #Hard #Array #Dynamic_Programming #2022_06_16_Time_469_ms_(23.66%)_Space_43.7_MB_(32.44%)
+// #Hard #Array #Dynamic_Programming #2024_03_29_Time_159_ms_(39.25%)_Space_41.9_MB_(97.66%)
public class Solution {
public int largestVariance(String s) {
diff --git a/src/main/java/g2201_2300/s2288_apply_discount_to_prices/Solution.java b/src/main/java/g2201_2300/s2288_apply_discount_to_prices/Solution.java
index b58e1784b..878a0e2a7 100644
--- a/src/main/java/g2201_2300/s2288_apply_discount_to_prices/Solution.java
+++ b/src/main/java/g2201_2300/s2288_apply_discount_to_prices/Solution.java
@@ -23,7 +23,7 @@ private String applyDiscount(String s, int discount) {
return s;
}
price *= 10;
- price += (s.charAt(i) - '0') * (100 - discount);
+ price += (long) (s.charAt(i) - '0') * (100 - discount);
}
String stringPrice = String.valueOf(price);
if (price < 10) {
diff --git a/src/main/java/g2201_2300/s2300_successful_pairs_of_spells_and_potions/Solution.java b/src/main/java/g2201_2300/s2300_successful_pairs_of_spells_and_potions/Solution.java
index 7ee5a3b48..843406962 100644
--- a/src/main/java/g2201_2300/s2300_successful_pairs_of_spells_and_potions/Solution.java
+++ b/src/main/java/g2201_2300/s2300_successful_pairs_of_spells_and_potions/Solution.java
@@ -1,6 +1,6 @@
package g2201_2300.s2300_successful_pairs_of_spells_and_potions;
-// #Medium #Array #Sorting #Binary_Search #Two_Pointers
+// #Medium #Array #Sorting #Binary_Search #Two_Pointers #LeetCode_75_Binary_Search
// #2022_06_14_Time_85_ms_(71.70%)_Space_135.9_MB_(33.90%)
import java.util.Arrays;
diff --git a/src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java b/src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java
index 647d6f493..cffc70d89 100644
--- a/src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java
+++ b/src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java
@@ -15,7 +15,7 @@ public long countPairs(int n, int[][] edges) {
long ans = 0;
for (int i = 0; i < n; i++) {
int p = d.findParent(i);
- int cnt = map.containsKey(p) ? map.get(p) : 0;
+ int cnt = map.getOrDefault(p, 0);
ans += i - cnt;
map.put(p, map.getOrDefault(p, 0) + 1);
}
diff --git a/src/main/java/g2301_2400/s2318_number_of_distinct_roll_sequences/Solution.java b/src/main/java/g2301_2400/s2318_number_of_distinct_roll_sequences/Solution.java
index beca62187..91c6cd805 100644
--- a/src/main/java/g2301_2400/s2318_number_of_distinct_roll_sequences/Solution.java
+++ b/src/main/java/g2301_2400/s2318_number_of_distinct_roll_sequences/Solution.java
@@ -3,9 +3,8 @@
// #Hard #Dynamic_Programming #Memoization #2022_06_26_Time_254_ms_(91.67%)_Space_51.6_MB_(58.33%)
public class Solution {
- private int[][][] memo = new int[10001][7][7];
- private int mod = 1000000007;
- private int[][] m = {
+ private static final int MOD = 1000000007;
+ private static final int[][] M = {
{1, 2, 3, 4, 5, 6},
{2, 3, 4, 5, 6},
{1, 3, 5},
@@ -14,6 +13,7 @@ public class Solution {
{1, 2, 3, 4, 6},
{1, 5}
};
+ private final int[][][] memo = new int[10001][7][7];
public int distinctSequences(int n) {
return dp(n, 0, 0);
@@ -27,9 +27,9 @@ private int dp(int n, int prev, int pprev) {
return memo[n][prev][pprev];
}
int ans = 0;
- for (int x : m[prev]) {
+ for (int x : M[prev]) {
if (x != pprev) {
- ans = (ans + dp(n - 1, x, prev)) % mod;
+ ans = (ans + dp(n - 1, x, prev)) % MOD;
}
}
memo[n][prev][pprev] = ans;
diff --git a/src/main/java/g2301_2400/s2332_the_latest_time_to_catch_a_bus/Solution.java b/src/main/java/g2301_2400/s2332_the_latest_time_to_catch_a_bus/Solution.java
index 2f16cca0f..81e57a047 100644
--- a/src/main/java/g2301_2400/s2332_the_latest_time_to_catch_a_bus/Solution.java
+++ b/src/main/java/g2301_2400/s2332_the_latest_time_to_catch_a_bus/Solution.java
@@ -32,7 +32,7 @@ public int latestTimeCatchTheBus(int[] buses, int[] passengers, int capacity) {
b++;
}
}
- int start = 0;
+ int start;
if (c == capacity) {
// capcity is full in last bus, find time last passenger might have boarded
start = Math.min(passengers[p - 1], buses[blen - 1]);
diff --git a/src/main/java/g2301_2400/s2333_minimum_sum_of_squared_difference/Solution.java b/src/main/java/g2301_2400/s2333_minimum_sum_of_squared_difference/Solution.java
index 7f4e6bbf0..e725daa20 100644
--- a/src/main/java/g2301_2400/s2333_minimum_sum_of_squared_difference/Solution.java
+++ b/src/main/java/g2301_2400/s2333_minimum_sum_of_squared_difference/Solution.java
@@ -33,8 +33,8 @@ public long minSumSquareDiff(int[] nums1, int[] nums2, int k1, int k2) {
// if current group has more differences than the totalK, we can only move k of them
// to the lower level.
if (diffs[i] >= kSum) {
- diffs[i] -= kSum;
- diffs[i - 1] += kSum;
+ diffs[i] -= (int) kSum;
+ diffs[i - 1] += (int) kSum;
kSum = 0;
} else {
// else, we can make this whole group one level lower.
diff --git a/src/main/java/g2301_2400/s2336_smallest_number_in_infinite_set/SmallestInfiniteSet.java b/src/main/java/g2301_2400/s2336_smallest_number_in_infinite_set/SmallestInfiniteSet.java
index 2c7195a5e..02a6d7479 100644
--- a/src/main/java/g2301_2400/s2336_smallest_number_in_infinite_set/SmallestInfiniteSet.java
+++ b/src/main/java/g2301_2400/s2336_smallest_number_in_infinite_set/SmallestInfiniteSet.java
@@ -1,6 +1,6 @@
package g2301_2400.s2336_smallest_number_in_infinite_set;
-// #Medium #Hash_Table #Design #Heap_Priority_Queue
+// #Medium #Hash_Table #Design #Heap_Priority_Queue #LeetCode_75_Heap/Priority_Queue
// #2022_07_13_Time_12_ms_(96.69%)_Space_54.8_MB_(57.87%)
public class SmallestInfiniteSet {
diff --git a/src/main/java/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/Solution.java b/src/main/java/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/Solution.java
index d35d47171..c61d09d9d 100644
--- a/src/main/java/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/Solution.java
+++ b/src/main/java/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/Solution.java
@@ -13,7 +13,7 @@ public int maximumSum(int[] nums) {
for (int num : nums) {
int s = 0;
for (char digit : String.valueOf(num).toCharArray()) {
- s += Integer.valueOf(digit - '0');
+ s += digit - '0';
}
if (!map.containsKey(s)) {
map.put(s, num);
diff --git a/src/main/java/g2301_2400/s2352_equal_row_and_column_pairs/Solution.java b/src/main/java/g2301_2400/s2352_equal_row_and_column_pairs/Solution.java
index 6c3d9badb..96aec3e04 100644
--- a/src/main/java/g2301_2400/s2352_equal_row_and_column_pairs/Solution.java
+++ b/src/main/java/g2301_2400/s2352_equal_row_and_column_pairs/Solution.java
@@ -1,6 +1,6 @@
package g2301_2400.s2352_equal_row_and_column_pairs;
-// #Medium #Array #Hash_Table #Matrix #Simulation
+// #Medium #Array #Hash_Table #Matrix #Simulation #LeetCode_75_Hash_Map/Set
// #2022_08_07_Time_7_ms_(98.94%)_Space_71.4_MB_(27.97%)
import java.util.Arrays;
diff --git a/src/main/java/g2301_2400/s2365_task_scheduler_ii/Solution.java b/src/main/java/g2301_2400/s2365_task_scheduler_ii/Solution.java
index c9b8c3a4b..35b1ebd60 100644
--- a/src/main/java/g2301_2400/s2365_task_scheduler_ii/Solution.java
+++ b/src/main/java/g2301_2400/s2365_task_scheduler_ii/Solution.java
@@ -9,15 +9,15 @@ public long taskSchedulerII(int[] tasks, int space) {
long days = 0;
space++;
HashMap lastOccurence = new HashMap<>();
- for (int i = 0; i < tasks.length; i++) {
- if (lastOccurence.containsKey(tasks[i])) {
- long lastTimeOccurred = lastOccurence.get(tasks[i]);
+ for (int task : tasks) {
+ if (lastOccurence.containsKey(task)) {
+ long lastTimeOccurred = lastOccurence.get(task);
long daysDifference = days - lastTimeOccurred;
if (daysDifference < space) {
days += (space - daysDifference);
}
}
- lastOccurence.put(tasks[i], days);
+ lastOccurence.put(task, days);
days++;
}
return days;
diff --git a/src/main/java/g2301_2400/s2366_minimum_replacements_to_sort_the_array/Solution.java b/src/main/java/g2301_2400/s2366_minimum_replacements_to_sort_the_array/Solution.java
index 3c1406dd0..225ea5f6f 100644
--- a/src/main/java/g2301_2400/s2366_minimum_replacements_to_sort_the_array/Solution.java
+++ b/src/main/java/g2301_2400/s2366_minimum_replacements_to_sort_the_array/Solution.java
@@ -1,18 +1,19 @@
package g2301_2400.s2366_minimum_replacements_to_sort_the_array;
-// #Hard #Array #Math #Greedy #2022_08_14_Time_10_ms_(28.57%)_Space_81.5_MB_(28.57%)
+// #Hard #Array #Math #Greedy #2025_05_03_Time_3_ms_(98.58%)_Space_56.46_MB_(8.49%)
public class Solution {
public long minimumReplacement(int[] nums) {
- int limit = nums[nums.length - 1];
+ int n = nums.length;
+ int prev = nums[n - 1];
long ans = 0;
- for (int i = nums.length - 2; i >= 0; i--) {
- int replacements = nums[i] / limit - 1;
- if (nums[i] % limit != 0) {
- replacements++;
+ for (int i = n - 2; i >= 0; i--) {
+ int noOfTime = nums[i] / prev;
+ if (nums[i] % prev != 0) {
+ noOfTime++;
+ prev = nums[i] / noOfTime;
}
- ans += replacements;
- limit = nums[i] / (replacements + 1);
+ ans += noOfTime - 1;
}
return ans;
}
diff --git a/src/main/java/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/Solution.java b/src/main/java/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/Solution.java
index b3569a1fb..276647d08 100644
--- a/src/main/java/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/Solution.java
+++ b/src/main/java/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/Solution.java
@@ -7,7 +7,7 @@ public class Solution {
public int secondsToRemoveOccurrences(String s) {
int lastOne = -1;
int result = 0;
- int prevResult = 0;
+ int prevResult;
int curResult = 0;
int countOne = 0;
int countZero = 0;
diff --git a/src/main/java/g2301_2400/s2384_largest_palindromic_number/Solution.java b/src/main/java/g2301_2400/s2384_largest_palindromic_number/Solution.java
index ab9fabc12..8d3b1cf26 100644
--- a/src/main/java/g2301_2400/s2384_largest_palindromic_number/Solution.java
+++ b/src/main/java/g2301_2400/s2384_largest_palindromic_number/Solution.java
@@ -11,17 +11,17 @@ public String largestPalindromic(String num) {
for (char c : num.toCharArray()) {
count[c - '0']++;
}
- int c = 0;
+ int c;
for (int i = 9; i >= 0; i--) {
c = 0;
if (count[i] % 2 == 1 && center == -1) {
center = i;
}
- if (first.length() == 0 && i == 0) {
+ if (first.isEmpty() && i == 0) {
continue;
}
while (c < count[i] / 2) {
- first.append(String.valueOf(i));
+ first.append(i);
c++;
}
}
@@ -29,7 +29,7 @@ public String largestPalindromic(String num) {
if (center != -1) {
first.append(center);
}
- first.append(second.reverse().toString());
- return first.length() == 0 ? "0" : first.toString();
+ first.append(second.reverse());
+ return first.isEmpty() ? "0" : first.toString();
}
}
diff --git a/src/main/java/g2301_2400/s2390_removing_stars_from_a_string/Solution.java b/src/main/java/g2301_2400/s2390_removing_stars_from_a_string/Solution.java
index 727adfb84..9fd3eac20 100644
--- a/src/main/java/g2301_2400/s2390_removing_stars_from_a_string/Solution.java
+++ b/src/main/java/g2301_2400/s2390_removing_stars_from_a_string/Solution.java
@@ -1,6 +1,7 @@
package g2301_2400.s2390_removing_stars_from_a_string;
-// #Medium #String #Stack #Simulation #2022_09_02_Time_31_ms_(90.55%)_Space_62.6_MB_(76.40%)
+// #Medium #String #Stack #Simulation #LeetCode_75_Stack
+// #2022_09_02_Time_31_ms_(90.55%)_Space_62.6_MB_(76.40%)
public class Solution {
public String removeStars(String s) {
diff --git a/src/main/java/g2301_2400/s2397_maximum_rows_covered_by_columns/Solution.java b/src/main/java/g2301_2400/s2397_maximum_rows_covered_by_columns/Solution.java
index b19466b3b..0ef035dd7 100644
--- a/src/main/java/g2301_2400/s2397_maximum_rows_covered_by_columns/Solution.java
+++ b/src/main/java/g2301_2400/s2397_maximum_rows_covered_by_columns/Solution.java
@@ -7,7 +7,7 @@ public class Solution {
private int ans = 0;
public int maximumRows(int[][] matrix, int numSelect) {
- dfs(matrix, /*colIndex=*/ 0, numSelect, /*mask=*/ 0);
+ dfs(matrix, /* colIndex= */ 0, numSelect, /* mask= */ 0);
return ans;
}
diff --git a/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java b/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java
index 4ccdd77ef..746708d05 100644
--- a/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java
+++ b/src/main/java/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/Solution.java
@@ -4,7 +4,7 @@
// #2022_09_19_Time_1_ms_(99.66%)_Space_41.7_MB_(91.83%)
public class Solution {
- private int mod = 1000000007;
+ private static final int MOD = 1000000007;
public int numberOfWays(int startPos, int endPos, int k) {
if (Math.abs(endPos - startPos) > k) {
@@ -23,9 +23,9 @@ public int numberOfWays(int startPos, int endPos, int k) {
rev[1] = 1;
int ans = k;
for (int i = 2; i <= min; i++) {
- rev[i] = (int) ((long) (mod - mod / i) * (long) rev[mod % i] % mod);
- ans = (int) ((long) ans * (long) (k - i + 1) % mod);
- ans = (int) ((long) ans * (long) rev[i] % mod);
+ rev[i] = (int) ((long) (MOD - MOD / i) * (long) rev[MOD % i] % MOD);
+ ans = (int) ((long) ans * (long) (k - i + 1) % MOD);
+ ans = (int) ((long) ans * (long) rev[i] % MOD);
}
return ans;
}
diff --git a/src/main/java/g2401_2500/s2409_count_days_spent_together/Solution.java b/src/main/java/g2401_2500/s2409_count_days_spent_together/Solution.java
index 89e20535d..d987744cf 100644
--- a/src/main/java/g2401_2500/s2409_count_days_spent_together/Solution.java
+++ b/src/main/java/g2401_2500/s2409_count_days_spent_together/Solution.java
@@ -18,14 +18,14 @@ public int countDaysTogether(
Integer endMonth = Integer.valueOf(ends[0]);
int res = 0;
if (startMonth.equals(endMonth)) {
- res += (Integer.valueOf(ends[1]) - Integer.valueOf(starts[1]) + 1);
+ res += (Integer.parseInt(ends[1]) - Integer.parseInt(starts[1]) + 1);
return res;
}
for (int i = startMonth; i <= endMonth; i++) {
if (i == endMonth) {
- res += Integer.valueOf(ends[1]);
+ res += Integer.parseInt(ends[1]);
} else if (i == startMonth) {
- res += dates[i] - Integer.valueOf(starts[1]) + 1;
+ res += dates[i] - Integer.parseInt(starts[1]) + 1;
} else {
res += dates[i];
}
diff --git a/src/main/java/g2401_2500/s2410_maximum_matching_of_players_with_trainers/Solution.java b/src/main/java/g2401_2500/s2410_maximum_matching_of_players_with_trainers/Solution.java
index d1fc8de81..0998cc1b4 100644
--- a/src/main/java/g2401_2500/s2410_maximum_matching_of_players_with_trainers/Solution.java
+++ b/src/main/java/g2401_2500/s2410_maximum_matching_of_players_with_trainers/Solution.java
@@ -10,7 +10,7 @@ public class Solution {
public int matchPlayersAndTrainers(int[] players, int[] trainers) {
Arrays.sort(players);
Arrays.sort(trainers);
- int i = 0;
+ int i;
int j = 0;
int count = 0;
i = 0;
diff --git a/src/main/java/g2401_2500/s2441_largest_positive_integer_that_exists_with_its_negative/Solution.java b/src/main/java/g2401_2500/s2441_largest_positive_integer_that_exists_with_its_negative/Solution.java
index bb4bb1e48..677713361 100644
--- a/src/main/java/g2401_2500/s2441_largest_positive_integer_that_exists_with_its_negative/Solution.java
+++ b/src/main/java/g2401_2500/s2441_largest_positive_integer_that_exists_with_its_negative/Solution.java
@@ -8,9 +8,9 @@ public class Solution {
public int findMaxK(int[] nums) {
int[] arr = new int[nums.length];
int j = 0;
- for (int i = 0; i < nums.length; i++) {
- if (nums[i] < 0) {
- arr[j++] = nums[i];
+ for (int k : nums) {
+ if (k < 0) {
+ arr[j++] = k;
}
}
Arrays.sort(arr);
diff --git a/src/main/java/g2401_2500/s2462_total_cost_to_hire_k_workers/Solution.java b/src/main/java/g2401_2500/s2462_total_cost_to_hire_k_workers/Solution.java
index d02ea1508..081a8d5ee 100644
--- a/src/main/java/g2401_2500/s2462_total_cost_to_hire_k_workers/Solution.java
+++ b/src/main/java/g2401_2500/s2462_total_cost_to_hire_k_workers/Solution.java
@@ -1,6 +1,6 @@
package g2401_2500.s2462_total_cost_to_hire_k_workers;
-// #Medium #Array #Two_Pointers #Heap_Priority_Queue #Simulation
+// #Medium #Array #Two_Pointers #Heap_Priority_Queue #Simulation #LeetCode_75_Heap/Priority_Queue
// #2023_01_07_Time_57_ms_(96.24%)_Space_54_MB_(92.26%)
import java.util.PriorityQueue;
diff --git a/src/main/java/g2401_2500/s2468_split_message_based_on_limit/Solution.java b/src/main/java/g2401_2500/s2468_split_message_based_on_limit/Solution.java
index e962bcf82..39a614f98 100644
--- a/src/main/java/g2401_2500/s2468_split_message_based_on_limit/Solution.java
+++ b/src/main/java/g2401_2500/s2468_split_message_based_on_limit/Solution.java
@@ -5,7 +5,7 @@
@SuppressWarnings("java:S3518")
public class Solution {
public String[] splitMessage(String message, int limit) {
- int total = 0;
+ int total;
int running = 0;
int count;
int totalReq;
diff --git a/src/main/java/g2401_2500/s2500_delete_greatest_value_in_each_row/Solution.java b/src/main/java/g2401_2500/s2500_delete_greatest_value_in_each_row/Solution.java
index b07d38a6a..c06b0d35a 100644
--- a/src/main/java/g2401_2500/s2500_delete_greatest_value_in_each_row/Solution.java
+++ b/src/main/java/g2401_2500/s2500_delete_greatest_value_in_each_row/Solution.java
@@ -7,14 +7,14 @@
public class Solution {
public int deleteGreatestValue(int[][] grid) {
int sum = 0;
- for (int i = 0; i < grid.length; i++) {
- Arrays.sort(grid[i]);
+ for (int[] value : grid) {
+ Arrays.sort(value);
}
for (int j = 0; j < grid[0].length; j++) {
int max = Integer.MIN_VALUE;
- for (int i = 0; i < grid.length; i++) {
- if (grid[i][j] > max) {
- max = grid[i][j];
+ for (int[] ints : grid) {
+ if (ints[j] > max) {
+ max = ints[j];
}
}
sum += max;
diff --git a/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java b/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java
index 5af33bfab..9a71e6ac6 100644
--- a/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java
+++ b/src/main/java/g2501_2600/s2502_design_memory_allocator/Allocator.java
@@ -4,7 +4,7 @@
// #2023_03_19_Time_9_ms_(100.00%)_Space_43_MB_(66.82%)
public class Allocator {
- Node root;
+ private final Node root;
public Allocator(int n) {
root = new Node(0, n, -1);
@@ -36,7 +36,7 @@ public int free(int mID) {
return collapse(root, mID);
}
- public int collapse(Node cur, int id) {
+ private int collapse(Node cur, int id) {
// base case
if (cur == null) {
return 0;
diff --git a/src/main/java/g2501_2600/s2528_maximize_the_minimum_powered_city/Solution.java b/src/main/java/g2501_2600/s2528_maximize_the_minimum_powered_city/Solution.java
index 45f76f491..b60a6b146 100644
--- a/src/main/java/g2501_2600/s2528_maximize_the_minimum_powered_city/Solution.java
+++ b/src/main/java/g2501_2600/s2528_maximize_the_minimum_powered_city/Solution.java
@@ -19,7 +19,7 @@ private boolean canIBeTheMinimum(long[] power, long minimum, int k, int r) {
if (req > k) {
return false;
}
- k -= req;
+ k -= (int) req;
extraPower[i] += (req);
if (i + 2 * r + 1 < n) {
extraPower[i + 2 * r + 1] -= (req);
diff --git a/src/main/java/g2501_2600/s2542_maximum_subsequence_score/Solution.java b/src/main/java/g2501_2600/s2542_maximum_subsequence_score/Solution.java
index d7952158a..925c9209d 100644
--- a/src/main/java/g2501_2600/s2542_maximum_subsequence_score/Solution.java
+++ b/src/main/java/g2501_2600/s2542_maximum_subsequence_score/Solution.java
@@ -1,6 +1,6 @@
package g2501_2600.s2542_maximum_subsequence_score;
-// #Medium #Array #Sorting #Greedy #Heap_Priority_Queue
+// #Medium #Array #Sorting #Greedy #Heap_Priority_Queue #LeetCode_75_Heap/Priority_Queue
// #2023_05_09_Time_94_ms_(84.75%)_Space_56.5_MB_(81.92%)
import java.util.Arrays;
diff --git a/src/main/java/g2501_2600/s2598_smallest_missing_non_negative_integer_after_operations/Solution.java b/src/main/java/g2501_2600/s2598_smallest_missing_non_negative_integer_after_operations/Solution.java
index bf350b3cc..ec29c8c40 100644
--- a/src/main/java/g2501_2600/s2598_smallest_missing_non_negative_integer_after_operations/Solution.java
+++ b/src/main/java/g2501_2600/s2598_smallest_missing_non_negative_integer_after_operations/Solution.java
@@ -9,8 +9,8 @@ public int findSmallestInteger(int[] nums, int value) {
return n;
}
int[] a = new int[value];
- for (int i = 0; i < n; i++) {
- int k = nums[i] % value;
+ for (int num : nums) {
+ int k = num % value;
if (k < 0) {
k = (value + k) % value;
}
diff --git a/src/main/java/g2601_2700/s2610_convert_an_array_into_a_2d_array_with_conditions/Solution.java b/src/main/java/g2601_2700/s2610_convert_an_array_into_a_2d_array_with_conditions/Solution.java
index c07d2924f..a98641f11 100644
--- a/src/main/java/g2601_2700/s2610_convert_an_array_into_a_2d_array_with_conditions/Solution.java
+++ b/src/main/java/g2601_2700/s2610_convert_an_array_into_a_2d_array_with_conditions/Solution.java
@@ -1,23 +1,20 @@
package g2601_2700.s2610_convert_an_array_into_a_2d_array_with_conditions;
-// #Medium #Array #Hash_Table #2023_08_30_Time_2_ms_(97.24%)_Space_43.9_MB_(80.58%)
+// #Medium #Array #Hash_Table #2025_02_25_Time_1_ms_(100.00%)_Space_45.01_MB_(53.07%)
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
public class Solution {
public List> findMatrix(int[] nums) {
List> res = new ArrayList<>();
- Map map = new HashMap<>();
- for (int x : nums) {
- map.put(x, map.getOrDefault(x, 0) + 1);
- int idx = map.get(x);
- if (res.size() < idx) {
+ int n = nums.length;
+ int[] freq = new int[n + 1];
+ for (int num : nums) {
+ if (res.size() < ++freq[num]) {
res.add(new ArrayList<>());
}
- res.get(idx - 1).add(x);
+ res.get(freq[num] - 1).add(num);
}
return res;
}
diff --git a/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java b/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java
index df22d64da..684618448 100644
--- a/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java
+++ b/src/main/java/g2601_2700/s2612_minimum_reverse_operations/Solution.java
@@ -4,14 +4,13 @@
// #2023_08_30_Time_19_ms_(100.00%)_Space_59_MB_(78.00%)
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
public class Solution {
public int[] minReverseOperations(int n, int p, int[] banned, int k) {
int[] out = new int[n];
- for (int i = 0; i < n; i++) {
- out[i] = -1;
- }
+ Arrays.fill(out, -1);
for (int node : banned) {
out[node] = -2;
}
diff --git a/src/main/java/g2601_2700/s2619_array_prototype_last/solution.ts b/src/main/java/g2601_2700/s2619_array_prototype_last/solution.ts
index c79440611..9f5e789cc 100644
--- a/src/main/java/g2601_2700/s2619_array_prototype_last/solution.ts
+++ b/src/main/java/g2601_2700/s2619_array_prototype_last/solution.ts
@@ -7,7 +7,7 @@ declare global {
}
Array.prototype.last = function () { //NOSONAR
- return this.length !== 0 ? this[this.length - 1] : -1
+ return this.length !== 0 ? this[this.length - 1] : -1 //NOSONAR
}
/*
@@ -15,4 +15,4 @@ Array.prototype.last = function () { //NOSONAR
* arr.last(); // 3
*/
-export {}
+export {} //NOSONAR
diff --git a/src/main/java/g2601_2700/s2622_cache_with_time_limit/solution.ts b/src/main/java/g2601_2700/s2622_cache_with_time_limit/solution.ts
index cbe76b904..f23053e51 100644
--- a/src/main/java/g2601_2700/s2622_cache_with_time_limit/solution.ts
+++ b/src/main/java/g2601_2700/s2622_cache_with_time_limit/solution.ts
@@ -1,7 +1,7 @@
// #Medium #2023_08_31_Time_51_ms_(94.82%)_Space_42.2_MB_(94.26%)
class TimeLimitedCache {
- private keyMap: Map
+ private readonly keyMap: Map
constructor() {
this.keyMap = new Map()
}
diff --git a/src/main/java/g2601_2700/s2624_snail_traversal/solution.ts b/src/main/java/g2601_2700/s2624_snail_traversal/solution.ts
index fa9303cb7..4c29f5af8 100644
--- a/src/main/java/g2601_2700/s2624_snail_traversal/solution.ts
+++ b/src/main/java/g2601_2700/s2624_snail_traversal/solution.ts
@@ -1,4 +1,4 @@
-// #Medium #2023_08_31_Time_175_ms_(92.96%)_Space_64.2_MB_(32.75%)
+// #Medium #2025_04_29_Time_157_ms_(81.82%)_Space_71.07_MB_(18.18%)
declare global {
interface Array {
@@ -13,7 +13,7 @@ Array.prototype.snail = function (rowsCount: number, colsCount: number): number[
let col = Math.floor(i / rowsCount)
let row = i % rowsCount
row = col % 2 === 0 ? row : rowsCount - row - 1
- if (res[row] === undefined) res[row] = []
+ res[row] = res[row] ?? []
res[row].push(this[i])
}
return res
@@ -24,4 +24,4 @@ Array.prototype.snail = function (rowsCount: number, colsCount: number): number[
* arr.snail(1,4); // [[1,2,3,4]]
*/
-export {}
+export {} //NOSONAR
diff --git a/src/main/java/g2601_2700/s2626_array_reduce_transformation/solution.ts b/src/main/java/g2601_2700/s2626_array_reduce_transformation/solution.ts
index 14d4c31f3..db8eb1a7c 100644
--- a/src/main/java/g2601_2700/s2626_array_reduce_transformation/solution.ts
+++ b/src/main/java/g2601_2700/s2626_array_reduce_transformation/solution.ts
@@ -4,7 +4,7 @@ type Fn = (accum: number, curr: number) => number
function reduce(nums: number[], fn: Fn, init: number): number {
let accumulator = init
- nums.forEach((num) => {
+ nums.forEach((num) => { //NOSONAR
accumulator = fn(accumulator, num)
})
return accumulator
diff --git a/src/main/java/g2601_2700/s2630_memoize_ii/solution.ts b/src/main/java/g2601_2700/s2630_memoize_ii/solution.ts
index ad10c8dc2..edec30866 100644
--- a/src/main/java/g2601_2700/s2630_memoize_ii/solution.ts
+++ b/src/main/java/g2601_2700/s2630_memoize_ii/solution.ts
@@ -36,7 +36,7 @@ function memoize(fn: Fn): Fn {
let value = fn(...args)
- currentCache.set(args[args.length - 1], value)
+ currentCache.set(args[args.length - 1], value) //NOSONAR
return value
}
}
diff --git a/src/main/java/g2601_2700/s2631_group_by/solution.ts b/src/main/java/g2601_2700/s2631_group_by/solution.ts
index d0d798e13..fac77e3ae 100644
--- a/src/main/java/g2601_2700/s2631_group_by/solution.ts
+++ b/src/main/java/g2601_2700/s2631_group_by/solution.ts
@@ -23,4 +23,4 @@ Array.prototype.groupBy = function (fn: (item: T) => string) { //NOSONAR
* [1,2,3].groupBy(String) // {"1":[1],"2":[2],"3":[3]}
*/
-export {}
+export {} //NOSONAR
diff --git a/src/main/java/g2601_2700/s2661_first_completely_painted_row_or_column/Solution.java b/src/main/java/g2601_2700/s2661_first_completely_painted_row_or_column/Solution.java
index 9bf10072a..5097e691c 100644
--- a/src/main/java/g2601_2700/s2661_first_completely_painted_row_or_column/Solution.java
+++ b/src/main/java/g2601_2700/s2661_first_completely_painted_row_or_column/Solution.java
@@ -1,39 +1,30 @@
package g2601_2700.s2661_first_completely_painted_row_or_column;
-// #Medium #Array #Hash_Table #Matrix #2023_09_09_Time_22_ms_(85.61%)_Space_64.7_MB_(58.25%)
-
-import java.util.HashMap;
+// #Medium #Array #Hash_Table #Matrix #2025_02_25_Time_2_ms_(100.00%)_Space_57.98_MB_(96.93%)
public class Solution {
public int firstCompleteIndex(int[] arr, int[][] mat) {
- HashMap map = new HashMap<>();
+ int[] numMapIndex = new int[mat.length * mat[0].length + 1];
for (int i = 0; i < arr.length; i++) {
- map.put(arr[i], i);
- }
-
- for (int i = 0; i < mat.length; i++) {
- for (int j = 0; j < mat[0].length; j++) {
- mat[i][j] = map.get(mat[i][j]);
- }
+ numMapIndex[arr[i]] = i;
}
-
int ans = Integer.MAX_VALUE;
- for (int[] ints : mat) {
- int max = 0;
- for (int j = 0; j < mat[0].length; j++) {
- max = Math.max(max, ints[j]);
+ for (int[] value : mat) {
+ int rowMin = Integer.MIN_VALUE;
+ for (int i : value) {
+ int index = numMapIndex[i];
+ rowMin = Math.max(rowMin, index);
}
- ans = Math.min(ans, max);
+ ans = Math.min(ans, rowMin);
}
-
for (int i = 0; i < mat[0].length; i++) {
- int max = 0;
+ int colMin = Integer.MIN_VALUE;
for (int[] ints : mat) {
- max = Math.max(max, ints[i]);
+ int index = numMapIndex[ints[i]];
+ colMin = Math.max(colMin, index);
}
- ans = Math.min(ans, max);
+ ans = Math.min(ans, colMin);
}
-
return ans;
}
}
diff --git a/src/main/java/g2601_2700/s2678_number_of_senior_citizens/Solution.java b/src/main/java/g2601_2700/s2678_number_of_senior_citizens/Solution.java
index 8fca4316f..d11b5b073 100644
--- a/src/main/java/g2601_2700/s2678_number_of_senior_citizens/Solution.java
+++ b/src/main/java/g2601_2700/s2678_number_of_senior_citizens/Solution.java
@@ -1,16 +1,16 @@
package g2601_2700.s2678_number_of_senior_citizens;
-// #Easy #Array #String #2023_09_11_Time_0_ms_(100.00%)_Space_40.7_MB_(97.65%)
+// #Easy #Array #String #2025_02_26_Time_0_ms_(100.00%)_Space_42.10_MB_(95.99%)
public class Solution {
public int countSeniors(String[] details) {
- int count = 0;
+ int seniorCitizen = 0;
for (String detail : details) {
- if (((detail.charAt(11) - '0' == 6) && (detail.charAt(12) - '0' > 0))
- || (detail.charAt(11) - '0' > 6)) {
- count++;
+ int age = (detail.charAt(11) - '0') * 10 + detail.charAt(12) - '0';
+ if (age > 60) {
+ seniorCitizen++;
}
}
- return count;
+ return seniorCitizen;
}
}
diff --git a/src/main/java/g2601_2700/s2679_sum_in_a_matrix/Solution.java b/src/main/java/g2601_2700/s2679_sum_in_a_matrix/Solution.java
index b8860696f..fdabf7acd 100644
--- a/src/main/java/g2601_2700/s2679_sum_in_a_matrix/Solution.java
+++ b/src/main/java/g2601_2700/s2679_sum_in_a_matrix/Solution.java
@@ -8,12 +8,10 @@
public class Solution {
public int matrixSum(int[][] nums) {
int result = 0;
-
for (int[] row : nums) {
Arrays.sort(row);
reverseArray(row);
}
-
for (int i = 0; i < nums[0].length; i++) {
int max = 0;
for (int[] num : nums) {
@@ -21,7 +19,6 @@ public int matrixSum(int[][] nums) {
}
result += max;
}
-
return result;
}
diff --git a/src/main/java/g2601_2700/s2693_call_function_with_custom_context/solution.ts b/src/main/java/g2601_2700/s2693_call_function_with_custom_context/solution.ts
index f78ad1bb3..37e8fb02c 100644
--- a/src/main/java/g2601_2700/s2693_call_function_with_custom_context/solution.ts
+++ b/src/main/java/g2601_2700/s2693_call_function_with_custom_context/solution.ts
@@ -16,4 +16,4 @@ Function.prototype.callPolyfill = function (context, ...args): any { //NOSONAR
* increment.callPolyfill({count: 1}); // 2
*/
-export {}
+export {} //NOSONAR
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 319a59b6d..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 {
@@ -32,7 +32,7 @@ class EventEmitter {
emit(eventName: string, args: any[] = []): any[] {
const res = []
- this.eventMap.get(eventName)?.forEach((cb) => res.push(cb(...args)))
+ this.eventMap.get(eventName)?.forEach((cb) => res.push(cb(...args))) //NOSONAR
return res
}
}
diff --git a/src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.ts b/src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.ts
index 4a30aab86..96b94092a 100644
--- a/src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.ts
+++ b/src/main/java/g2701_2800/s2703_return_length_of_arguments_passed/solution.ts
@@ -1,6 +1,8 @@
-// #Easy #2023_09_14_Time_49_ms_(86.01%)_Space_42.9_MB_(39.39%)
+// #Easy #2025_02_26_Time_50_ms_(82.03%)_Space_54.95_MB_(7.19%)
-function argumentsLength(...args: any[]): number {
+type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
+
+function argumentsLength(...args: JSONValue[]): number {
return args.length
}
diff --git a/src/main/java/g2701_2800/s2705_compact_object/solution.ts b/src/main/java/g2701_2800/s2705_compact_object/solution.ts
index 979e3bfaa..c57b14bd7 100644
--- a/src/main/java/g2701_2800/s2705_compact_object/solution.ts
+++ b/src/main/java/g2701_2800/s2705_compact_object/solution.ts
@@ -5,7 +5,7 @@ type Obj = Record
function compactObject(obj: Obj): Obj {
if (Array.isArray(obj)) {
let retArr = []
- obj.forEach((e, idx) => {
+ obj.forEach((e, idx) => { //NOSONAR
if (e) {
retArr.push(compactObject(e))
}
diff --git a/src/main/java/g2701_2800/s2706_buy_two_chocolates/Solution.java b/src/main/java/g2701_2800/s2706_buy_two_chocolates/Solution.java
index 81488cd8e..e4501092d 100644
--- a/src/main/java/g2701_2800/s2706_buy_two_chocolates/Solution.java
+++ b/src/main/java/g2701_2800/s2706_buy_two_chocolates/Solution.java
@@ -6,7 +6,6 @@ public class Solution {
public int buyChoco(int[] prices, int money) {
int minPrice1 = Integer.MAX_VALUE;
int minPrice2 = Integer.MAX_VALUE;
-
for (int price : prices) {
if (price < minPrice1) {
minPrice2 = minPrice1;
@@ -15,9 +14,7 @@ public int buyChoco(int[] prices, int money) {
minPrice2 = price;
}
}
-
int totalPrice = minPrice1 + minPrice2;
-
if (totalPrice > money) {
return money;
} else {
diff --git a/src/main/java/g2701_2800/s2711_difference_of_number_of_distinct_values_on_diagonals/Solution.java b/src/main/java/g2701_2800/s2711_difference_of_number_of_distinct_values_on_diagonals/Solution.java
index 649610c5b..ebfa6118a 100644
--- a/src/main/java/g2701_2800/s2711_difference_of_number_of_distinct_values_on_diagonals/Solution.java
+++ b/src/main/java/g2701_2800/s2711_difference_of_number_of_distinct_values_on_diagonals/Solution.java
@@ -11,7 +11,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
int n = grid[0].length;
int[][] arrTopLeft = new int[m][n];
int[][] arrBotRight = new int[m][n];
-
for (int i = m - 1; i >= 0; i--) {
int c = 0;
int r = i;
@@ -21,7 +20,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r++][c++]);
}
}
-
for (int i = 1; i < n; i++) {
int r = 0;
int c = i;
@@ -31,7 +29,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r++][c++]);
}
}
-
for (int i = 0; i < n; i++) {
int r = m - 1;
int c = i;
@@ -41,7 +38,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r--][c--]);
}
}
-
for (int i = m - 1; i >= 0; i--) {
int c = n - 1;
int r = i;
@@ -51,14 +47,12 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r--][c--]);
}
}
-
int[][] result = new int[m][n];
for (int r = 0; r < m; r++) {
for (int c = 0; c < n; c++) {
result[r][c] = Math.abs(arrTopLeft[r][c] - arrBotRight[r][c]);
}
}
-
return result;
}
diff --git a/src/main/java/g2701_2800/s2726_calculator_with_method_chaining/solution.ts b/src/main/java/g2701_2800/s2726_calculator_with_method_chaining/solution.ts
index e13976d03..a387ead7d 100644
--- a/src/main/java/g2701_2800/s2726_calculator_with_method_chaining/solution.ts
+++ b/src/main/java/g2701_2800/s2726_calculator_with_method_chaining/solution.ts
@@ -23,7 +23,7 @@ class Calculator {
}
divide(value: number): Calculator { //NOSONAR
- if (value === 0) throw Error('Division by zero is not allowed')
+ if (value === 0) throw new Error('Division by zero is not allowed')
this.init /= value
return this
}
diff --git a/src/main/java/g2701_2800/s2732_find_a_good_subset_of_the_matrix/Solution.java b/src/main/java/g2701_2800/s2732_find_a_good_subset_of_the_matrix/Solution.java
index 6efea9fa6..800bbc89a 100644
--- a/src/main/java/g2701_2800/s2732_find_a_good_subset_of_the_matrix/Solution.java
+++ b/src/main/java/g2701_2800/s2732_find_a_good_subset_of_the_matrix/Solution.java
@@ -1,50 +1,47 @@
package g2701_2800.s2732_find_a_good_subset_of_the_matrix;
// #Hard #Array #Greedy #Matrix #Bit_Manipulation
-// #2023_09_22_Time_7_ms_(70.65%)_Space_57.2_MB_(5.43%)
+// #2025_02_25_Time_2_ms_(100.00%)_Space_58.01_MB_(13.79%)
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.List;
-import java.util.Map;
public class Solution {
+ private int[] arr = new int[32];
+
public List goodSubsetofBinaryMatrix(int[][] grid) {
- int m = grid.length;
- int n = grid[0].length;
- if (m == 1 && sumArray(grid[0]) == 0) {
- return List.of(0);
- }
- Map pos = new HashMap<>();
- for (int i = 0; i < m; i++) {
- for (int mask = 0; mask < (1 << n); mask++) {
- boolean valid = true;
- for (int j = 0; j < n; j++) {
- if ((mask & (1 << j)) != 0 && grid[i][j] + 1 > 1) {
- valid = false;
- break;
- }
- }
- if (valid && pos.containsKey(mask)) {
- return List.of(pos.get(mask), i);
- }
+ List list = new ArrayList<>();
+ int n = grid.length;
+ Arrays.fill(arr, -1);
+ for (int i = 0; i < n; ++i) {
+ int j = get(grid[i]);
+ if (j == 0) {
+ list.add(i);
+ return list;
+ }
+ if (arr[j] != -1) {
+ list.add(arr[j]);
+ list.add(i);
+ return list;
}
- int curr = 0;
- for (int j = 0; j < n; j++) {
- if (grid[i][j] == 1) {
- curr = curr | (1 << j);
+ for (int k = 0; k < 32; ++k) {
+ if ((k & j) == 0) {
+ arr[k] = i;
}
}
- pos.put(curr, i);
}
- return new ArrayList<>();
+ return list;
}
- private int sumArray(int[] arr) {
- int sum = 0;
- for (int num : arr) {
- sum += num;
+ private int get(int[] nums) {
+ int n = nums.length;
+ int rs = 0;
+ for (int i = 0; i < n; ++i) {
+ if (nums[i] == 1) {
+ rs = (rs | (1 << i));
+ }
}
- return sum;
+ return rs;
}
}
diff --git a/src/main/java/g2701_2800/s2742_painting_the_walls/Solution.java b/src/main/java/g2701_2800/s2742_painting_the_walls/Solution.java
index da8c4f90b..11649e322 100644
--- a/src/main/java/g2701_2800/s2742_painting_the_walls/Solution.java
+++ b/src/main/java/g2701_2800/s2742_painting_the_walls/Solution.java
@@ -10,13 +10,11 @@ public int paintWalls(int[] cost, int[] time) {
int[] dp = new int[n + 1];
Arrays.fill(dp, (int) 1e9);
dp[0] = 0;
-
for (int i = 0; i < n; ++i) {
for (int j = n; j > 0; --j) {
dp[j] = Math.min(dp[j], dp[Math.max(j - time[i] - 1, 0)] + cost[i]);
}
}
-
return dp[n];
}
}
diff --git a/src/main/java/g2701_2800/s2745_construct_the_longest_new_string/Solution.java b/src/main/java/g2701_2800/s2745_construct_the_longest_new_string/Solution.java
index b8e2deb17..d2596136c 100644
--- a/src/main/java/g2701_2800/s2745_construct_the_longest_new_string/Solution.java
+++ b/src/main/java/g2701_2800/s2745_construct_the_longest_new_string/Solution.java
@@ -5,7 +5,7 @@
public class Solution {
public int longestString(int x, int y, int z) {
int min = Math.min(x, y);
- int res = 0;
+ int res;
if (x == y) {
res = 2 * min + z;
} else {
diff --git a/src/main/java/g2701_2800/s2747_count_zero_request_servers/Solution.java b/src/main/java/g2701_2800/s2747_count_zero_request_servers/Solution.java
index 97e8f178d..0c6c8260f 100644
--- a/src/main/java/g2701_2800/s2747_count_zero_request_servers/Solution.java
+++ b/src/main/java/g2701_2800/s2747_count_zero_request_servers/Solution.java
@@ -1,39 +1,42 @@
package g2701_2800.s2747_count_zero_request_servers;
// #Medium #Array #Hash_Table #Sorting #Sliding_Window
-// #2023_09_24_Time_43_ms_(76.92%)_Space_85.7_MB_(63.85%)
+// #2025_02_23_Time_22_ms_(100.00%)_Space_87.21_MB_(63.95%)
import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
public class Solution {
- public int[] countServers(int n, int[][] logs, int x, int[] qs) {
- int m = qs.length;
- var valIdx = new int[m][2];
+ public int[] countServers(int n, int[][] logs, int x, int[] queries) {
+ Arrays.sort(logs, (a, b) -> a[1] - b[1]);
+ int m = queries.length;
+ int len = logs.length;
+ int[][] qarr = new int[m][];
for (int i = 0; i < m; i++) {
- valIdx[i] = new int[] {qs[i], i};
+ qarr[i] = new int[] {i, queries[i]};
}
- Arrays.sort(valIdx, Comparator.comparingInt(a -> a[0]));
- Arrays.sort(logs, Comparator.comparingInt(a -> a[1]));
+ Arrays.sort(qarr, (a, b) -> a[1] - b[1]);
+ int[] ans = new int[m];
+ int[] freq = new int[n + 1];
int l = 0;
int r = 0;
- var res = new int[m];
- var servCount = new HashMap();
- for (var q : valIdx) {
- int rVal = q[0];
- int lVal = q[0] - x;
- int i = q[1];
- while (r < logs.length && logs[r][1] <= rVal) {
- servCount.merge(logs[r++][0], 1, Integer::sum);
+ int noReq = n;
+ for (int[] q : qarr) {
+ int i = q[0];
+ int t = q[1];
+ while (r < len && logs[r][1] <= t) {
+ if (freq[logs[r][0]]++ == 0) {
+ noReq--;
+ }
+ r++;
}
- while (l < r && logs[l][1] < lVal) {
- servCount.compute(logs[l][0], (k, v) -> v - 1);
- servCount.remove(logs[l][0], 0);
+ while (l < len && logs[l][1] < t - x) {
+ if (freq[logs[l][0]]-- == 1) {
+ noReq++;
+ }
l++;
}
- res[i] = n - servCount.size();
+ ans[i] = noReq;
}
- return res;
+ return ans;
}
}
diff --git a/src/main/java/g2701_2800/s2799_count_complete_subarrays_in_an_array/Solution.java b/src/main/java/g2701_2800/s2799_count_complete_subarrays_in_an_array/Solution.java
index a43e231e7..44afe3626 100644
--- a/src/main/java/g2701_2800/s2799_count_complete_subarrays_in_an_array/Solution.java
+++ b/src/main/java/g2701_2800/s2799_count_complete_subarrays_in_an_array/Solution.java
@@ -18,16 +18,16 @@ public int countCompleteSubarrays(int[] nums) {
map[nums[i]]++;
}
int ans = 0;
- for (int i = 0; i < n; ++i) {
+ for (int num : nums) {
ans += n - last;
- map[nums[i]]--;
- if (map[nums[i]] == 0) {
+ map[num]--;
+ if (map[num] == 0) {
int possLast = 0;
- for (int j = last + 1; j < n && map[nums[i]] == 0; ++j) {
+ for (int j = last + 1; j < n && map[num] == 0; ++j) {
map[nums[j]]++;
possLast = j;
}
- if (map[nums[i]] > 0) {
+ if (map[num] > 0) {
last = possLast;
} else {
break;
diff --git a/src/main/java/g2801_2900/s2812_find_the_safest_path_in_a_grid/Solution.java b/src/main/java/g2801_2900/s2812_find_the_safest_path_in_a_grid/Solution.java
index 8f02d9b30..acc5e9afa 100644
--- a/src/main/java/g2801_2900/s2812_find_the_safest_path_in_a_grid/Solution.java
+++ b/src/main/java/g2801_2900/s2812_find_the_safest_path_in_a_grid/Solution.java
@@ -22,7 +22,7 @@ public int maximumSafenessFactor(List> grid) {
int[] tmpDeque;
int[] queue = new int[yLen * xLen];
int[] root = new int[yLen * xLen];
- int head = -1;
+ int head;
int tail = -1;
int qIdx = -1;
int end = yLen * xLen - 1;
diff --git a/src/main/java/g2801_2900/s2816_double_a_number_represented_as_a_linked_list/Solution.java b/src/main/java/g2801_2900/s2816_double_a_number_represented_as_a_linked_list/Solution.java
index 1c58b593e..43dcc06e7 100644
--- a/src/main/java/g2801_2900/s2816_double_a_number_represented_as_a_linked_list/Solution.java
+++ b/src/main/java/g2801_2900/s2816_double_a_number_represented_as_a_linked_list/Solution.java
@@ -40,7 +40,7 @@ public ListNode doubleIt(ListNode head) {
private ListNode revList(ListNode head) {
ListNode prev = null;
- ListNode nxt = null;
+ ListNode nxt;
ListNode current = head;
while (current != null) {
nxt = current.next;
diff --git a/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java b/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java
index db4db0a27..62a8bb891 100644
--- a/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java
+++ b/src/main/java/g2801_2900/s2858_minimum_edge_reversals_so_every_node_is_reachable/Solution.java
@@ -4,6 +4,7 @@
// #2023_12_19_Time_52_ms_(92.31%)_Space_119.5_MB_(75.38%)
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
@@ -22,9 +23,7 @@ public int[] minEdgeReversals(int n, int[][] edges) {
nexts[v].add(new int[] {-1, u});
}
int[] res = new int[n];
- for (int i = 0; i < n; i++) {
- res[i] = -1;
- }
+ Arrays.fill(res, -1);
res[0] = dfs(nexts, 0, -1);
Queue queue = new LinkedList<>();
queue.add(0);
diff --git a/src/main/java/g2801_2900/s2899_last_visited_integers/Solution.java b/src/main/java/g2801_2900/s2899_last_visited_integers/Solution.java
index dd96a8706..83029f264 100644
--- a/src/main/java/g2801_2900/s2899_last_visited_integers/Solution.java
+++ b/src/main/java/g2801_2900/s2899_last_visited_integers/Solution.java
@@ -10,10 +10,10 @@ public List lastVisitedIntegers(List words) {
List prevEle = new ArrayList<>();
List res = new ArrayList<>();
int count = 0;
- for (int i = 0; i < words.size(); i++) {
- if (!words.get(i).equals("prev")) {
+ for (String word : words) {
+ if (!word.equals("prev")) {
count = 0;
- prevEle.add(words.get(i));
+ prevEle.add(word);
continue;
}
if (count >= prevEle.size()) {
diff --git a/src/main/java/g2801_2900/s2900_longest_unequal_adjacent_groups_subsequence_i/Solution.java b/src/main/java/g2801_2900/s2900_longest_unequal_adjacent_groups_subsequence_i/Solution.java
index d7376109c..a5fc3cbb1 100644
--- a/src/main/java/g2801_2900/s2900_longest_unequal_adjacent_groups_subsequence_i/Solution.java
+++ b/src/main/java/g2801_2900/s2900_longest_unequal_adjacent_groups_subsequence_i/Solution.java
@@ -1,6 +1,6 @@
package g2801_2900.s2900_longest_unequal_adjacent_groups_subsequence_i;
-// #Medium #Array #String #Dynamic_Programming #Greedy
+// #Easy #Array #String #Dynamic_Programming #Greedy
// #2023_12_20_Time_1_ms_(100.00%)_Space_45_MB_(7.16%)
import java.util.ArrayList;
diff --git a/src/main/java/g2901_3000/s2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros/Solution.java b/src/main/java/g2901_3000/s2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros/Solution.java
index cbc044f62..e23546750 100644
--- a/src/main/java/g2901_3000/s2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros/Solution.java
+++ b/src/main/java/g2901_3000/s2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros/Solution.java
@@ -1,48 +1,40 @@
package g2901_3000.s2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros;
-// #Medium #Array #Greedy #2023_12_28_Time_3_ms_(98.52%)_Space_60.7_MB_(8.70%)
+// #Medium #Array #Greedy #2024_01_19_Time_1_ms_(100.00%)_Space_60.8_MB_(12.50%)
public class Solution {
public long minSum(int[] nums1, int[] nums2) {
- long s1 = 0;
- long s2 = 0;
- long l = 0;
- long r = 0;
- for (int i : nums1) {
- s1 += i;
- if (i == 0) {
- l++;
- }
+ long zero1Count = 0;
+ long sum1 = 0;
+ long zero2Count = 0;
+ long sum2 = 0;
+ for (int num : nums1) {
+ zero1Count += num == 0 ? 1 : 0;
+ sum1 += num;
}
- for (int i : nums2) {
- s2 += i;
- if (i == 0) {
- r++;
- }
+ for (int num : nums2) {
+ zero2Count += num == 0 ? 1 : 0;
+ sum2 += num;
}
- if (s1 == s2 && l == 0 && r == 0) {
- return s1;
+ if (zero1Count == 0 && zero2Count == 0) {
+ return sum1 == sum2 ? sum1 : -1;
}
- long x = Math.abs(s1 - s2);
- if (s1 > s2) {
- if (r == 0 || (l == 0 && r > x)) {
- return -1;
- }
- if (l == 0) {
- return s1;
- }
- return s1 + Math.max(l, r - x);
- } else {
- if (l == 0 || (r == 0 && l > x)) {
- return -1;
- }
- if (s1 == s2) {
- return s1 + Math.max(l, r);
- }
- if (r == 0) {
- return s2;
- }
- return s2 + Math.max(r, l - x);
+ if (zero1Count == 0) {
+ return (sum1 - sum2 >= zero2Count) ? sum1 : -1;
}
+ if (zero2Count == 0) {
+ return (sum2 - sum1 >= zero1Count) ? sum2 : -1;
+ }
+ long ans = Long.MAX_VALUE;
+ long p1 = zero1Count;
+ long p2 = zero1Count - (sum2 - sum1);
+ if (p2 >= zero2Count) {
+ ans = Math.min(ans, sum1 + p1);
+ }
+ p1 = (sum2 - sum1) + zero2Count;
+ if (p1 >= zero1Count) {
+ ans = Math.min(ans, sum1 + p1);
+ }
+ return ans != Long.MAX_VALUE ? ans : -1;
}
}
diff --git a/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/Solution.java b/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/Solution.java
new file mode 100644
index 000000000..e72408c0a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/Solution.java
@@ -0,0 +1,31 @@
+package g2901_3000.s2930_number_of_strings_which_can_be_rearranged_to_contain_substring;
+
+// #Medium #Dynamic_Programming #Math #Combinatorics
+// #2024_01_02_Time_1_ms_(80.56%)_Space_40.8_MB_(66.67%)
+
+public class Solution {
+ private long pow(long x, long n, long mod) {
+ long result = 1;
+ long p = x % mod;
+ while (n != 0) {
+ if ((n & 1) != 0) {
+ result = (result * p) % mod;
+ }
+ p = (p * p) % mod;
+ n >>= 1;
+ }
+ return result;
+ }
+
+ public int stringCount(int n) {
+ long mod = (int) 1e9 + 7L;
+ return (int)
+ (((pow(26, n, mod)
+ - (n + 75) * pow(25, n - 1L, mod)
+ + (2 * n + 72) * pow(24, n - 1L, mod)
+ - (n + 23) * pow(23, n - 1L, mod))
+ % mod
+ + mod)
+ % mod);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/readme.md b/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/readme.md
new file mode 100644
index 000000000..8aa8ffbaa
--- /dev/null
+++ b/src/main/java/g2901_3000/s2930_number_of_strings_which_can_be_rearranged_to_contain_substring/readme.md
@@ -0,0 +1,38 @@
+2930\. Number of Strings Which Can Be Rearranged to Contain Substring
+
+Medium
+
+You are given an integer `n`.
+
+A string `s` is called **good** if it contains only lowercase English characters **and** it is possible to rearrange the characters of `s` such that the new string contains `"leet"` as a **substring**.
+
+For example:
+
+* The string `"lteer"` is good because we can rearrange it to form `"leetr"` .
+* `"letl"` is not good because we cannot rearrange it to contain `"leet"` as a substring.
+
+Return _the **total** number of good strings of length_ `n`.
+
+Since the answer may be large, return it **modulo** 109 + 7.
+
+A **substring** is a contiguous sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** n = 4
+
+**Output:** 12
+
+**Explanation:** The 12 strings which can be rearranged to have "leet" as a substring are: "eelt", "eetl", "elet", "elte", "etel", "etle", "leet", "lete", "ltee", "teel", "tele", and "tlee".
+
+**Example 2:**
+
+**Input:** n = 10
+
+**Output:** 83943898
+
+**Explanation:** The number of strings with length 10 which can be rearranged to have "leet" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.
+
+**Constraints:**
+
+* 1 <= n <= 105
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/Solution.java b/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/Solution.java
new file mode 100644
index 000000000..3809247f7
--- /dev/null
+++ b/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/Solution.java
@@ -0,0 +1,49 @@
+package g2901_3000.s2931_maximum_spending_after_buying_items;
+
+// #Hard #Array #Sorting #Greedy #Matrix #Heap_Priority_Queue
+// #2024_01_02_Time_18_ms_(79.00%)_Space_55.4_MB_(78.52%)
+
+public class Solution {
+ private static class Node {
+ int val = -1;
+ Node next = null;
+
+ public Node(int val) {
+ this.val = val;
+ }
+
+ public Node() {}
+ }
+
+ public long maxSpending(int[][] values) {
+ int m = values.length;
+ int n = values[0].length;
+ Node head = new Node();
+ Node node = head;
+ for (int j = n - 1; j >= 0; j--) {
+ node.next = new Node(values[0][j]);
+ node = node.next;
+ }
+ for (int i = 1; i < m; i++) {
+ node = head;
+ for (int j = n - 1; j >= 0; j--) {
+ while (node.next != null && node.next.val <= values[i][j]) {
+ node = node.next;
+ }
+ Node next = node.next;
+ node.next = new Node(values[i][j]);
+ node = node.next;
+ node.next = next;
+ }
+ }
+ long res = 0;
+ long day = 1;
+ node = head.next;
+ while (node != null) {
+ res += day * node.val;
+ node = node.next;
+ day++;
+ }
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/readme.md b/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/readme.md
new file mode 100644
index 000000000..364997077
--- /dev/null
+++ b/src/main/java/g2901_3000/s2931_maximum_spending_after_buying_items/readme.md
@@ -0,0 +1,79 @@
+2931\. Maximum Spending After Buying Items
+
+Hard
+
+You are given a **0-indexed** `m * n` integer matrix `values`, representing the values of `m * n` different items in `m` different shops. Each shop has `n` items where the jth item in the ith shop has a value of `values[i][j]`. Additionally, the items in the ith shop are sorted in non-increasing order of value. That is, `values[i][j] >= values[i][j + 1]` for all `0 <= j < n - 1`.
+
+On each day, you would like to buy a single item from one of the shops. Specifically, On the dth day you can:
+
+* Pick any shop `i`.
+* Buy the rightmost available item `j` for the price of `values[i][j] * d`. That is, find the greatest index `j` such that item `j` was never bought before, and buy it for the price of `values[i][j] * d`.
+
+**Note** that all items are pairwise different. For example, if you have bought item `0` from shop `1`, you can still buy item `0` from any other shop.
+
+Return _the **maximum amount of money that can be spent** on buying all_ `m * n` _products_.
+
+**Example 1:**
+
+**Input:** values = [[8,5,2],[6,4,1],[9,7,3]]
+
+**Output:** 285
+
+**Explanation:** On the first day, we buy product 2 from shop 1 for a price of values[1][2] \* 1 = 1.
+
+On the second day, we buy product 2 from shop 0 for a price of values[0][2] \* 2 = 4.
+
+On the third day, we buy product 2 from shop 2 for a price of values[2][2] \* 3 = 9.
+
+On the fourth day, we buy product 1 from shop 1 for a price of values[1][1] \* 4 = 16.
+
+On the fifth day, we buy product 1 from shop 0 for a price of values[0][1] \* 5 = 25.
+
+On the sixth day, we buy product 0 from shop 1 for a price of values[1][0] \* 6 = 36.
+
+On the seventh day, we buy product 1 from shop 2 for a price of values[2][1] \* 7 = 49.
+
+On the eighth day, we buy product 0 from shop 0 for a price of values[0][0] \* 8 = 64.
+
+On the ninth day, we buy product 0 from shop 2 for a price of values[2][0] \* 9 = 81.
+
+Hence, our total spending is equal to 285.
+
+It can be shown that 285 is the maximum amount of money that can be spent buying all m \* n products.
+
+**Example 2:**
+
+**Input:** values = [[10,8,6,4,2],[9,7,5,3,2]]
+
+**Output:** 386
+
+**Explanation:** On the first day, we buy product 4 from shop 0 for a price of values[0][4] \* 1 = 2.
+
+On the second day, we buy product 4 from shop 1 for a price of values[1][4] \* 2 = 4.
+
+On the third day, we buy product 3 from shop 1 for a price of values[1][3] \* 3 = 9.
+
+On the fourth day, we buy product 3 from shop 0 for a price of values[0][3] \* 4 = 16.
+
+On the fifth day, we buy product 2 from shop 1 for a price of values[1][2] \* 5 = 25.
+
+On the sixth day, we buy product 2 from shop 0 for a price of values[0][2] \* 6 = 36.
+
+On the seventh day, we buy product 1 from shop 1 for a price of values[1][1] \* 7 = 49.
+
+On the eighth day, we buy product 1 from shop 0 for a price of values[0][1] \* 8 = 64
+
+On the ninth day, we buy product 0 from shop 1 for a price of values[1][0] \* 9 = 81.
+
+On the tenth day, we buy product 0 from shop 0 for a price of values[0][0] \* 10 = 100.
+
+Hence, our total spending is equal to 386.
+
+It can be shown that 386 is the maximum amount of money that can be spent buying all m \* n products.
+
+**Constraints:**
+
+* `1 <= m == values.length <= 10`
+* 1 <= n == values[i].length <= 104
+* 1 <= values[i][j] <= 106
+* `values[i]` are sorted in non-increasing order.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/Solution.java b/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/Solution.java
new file mode 100644
index 000000000..ca5f6b521
--- /dev/null
+++ b/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/Solution.java
@@ -0,0 +1,20 @@
+package g2901_3000.s2932_maximum_strong_pair_xor_i;
+
+// #Easy #Array #Hash_Table #Bit_Manipulation #Sliding_Window #Trie
+// #2024_01_02_Time_2_ms_(98.64%)_Space_43.1_MB_(59.18%)
+
+public class Solution {
+ public int maximumStrongPairXor(int[] nums) {
+ int max = 0;
+ int pair;
+ for (int i = 0; i < nums.length; i++) {
+ for (int j = i; j < nums.length; j++) {
+ if (Math.abs(nums[i] - nums[j]) <= Math.min(nums[i], nums[j])) {
+ pair = nums[i] ^ nums[j];
+ max = Math.max(max, pair);
+ }
+ }
+ }
+ return max;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/readme.md b/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/readme.md
new file mode 100644
index 000000000..91b9b78ae
--- /dev/null
+++ b/src/main/java/g2901_3000/s2932_maximum_strong_pair_xor_i/readme.md
@@ -0,0 +1,42 @@
+2932\. Maximum Strong Pair XOR I
+
+Easy
+
+You are given a **0-indexed** integer array `nums`. A pair of integers `x` and `y` is called a **strong** pair if it satisfies the condition:
+
+* `|x - y| <= min(x, y)`
+
+You need to select two integers from `nums` such that they form a strong pair and their bitwise `XOR` is the **maximum** among all strong pairs in the array.
+
+Return _the **maximum**_ `XOR` _value out of all possible strong pairs in the array_ `nums`.
+
+**Note** that you can pick the same integer twice to form a pair.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 7
+
+**Explanation:** There are 11 strong pairs in the array `nums`: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5). The maximum XOR possible from these pairs is 3 XOR 4 = 7.
+
+**Example 2:**
+
+**Input:** nums = [10,100]
+
+**Output:** 0
+
+**Explanation:** There are 2 strong pairs in the array `nums`: (10, 10) and (100, 100). The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.
+
+**Example 3:**
+
+**Input:** nums = [5,6,25,30]
+
+**Output:** 7
+
+**Explanation:** There are 6 strong pairs in the array `nums`: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30). The maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.
+
+**Constraints:**
+
+* `1 <= nums.length <= 50`
+* `1 <= nums[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2933_high_access_employees/Solution.java b/src/main/java/g2901_3000/s2933_high_access_employees/Solution.java
new file mode 100644
index 000000000..18b21b602
--- /dev/null
+++ b/src/main/java/g2901_3000/s2933_high_access_employees/Solution.java
@@ -0,0 +1,76 @@
+package g2901_3000.s2933_high_access_employees;
+
+// #Medium #Array #String #Hash_Table #Sorting #2024_01_02_Time_9_ms_(87.94%)_Space_45.6_MB_(5.79%)
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Solution {
+ private boolean isPossible(int a, int b) {
+ int hb = b / 100;
+ int ha = a / 100;
+ int mind = b % 100;
+ int mina = a % 100;
+ if (hb == 23 && ha == 0) {
+ return false;
+ }
+ if (hb - ha > 1) {
+ return false;
+ }
+ if (hb - ha == 1) {
+ mind += 60;
+ }
+ return mind - mina < 60;
+ }
+
+ private boolean isHighAccess(List list) {
+ if (list.size() < 3) {
+ return false;
+ }
+ int i = 0;
+ int j = 1;
+ int k = 2;
+ while (k < list.size()) {
+ int a = list.get(i++);
+ int b = list.get(j++);
+ int c = list.get(k++);
+ if (isPossible(a, c) && isPossible(b, c) && isPossible(a, b)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private int stringToInt(String str) {
+ int i = 1000;
+ int val = 0;
+ for (char ch : str.toCharArray()) {
+ int n = ch - '0';
+ val += i * n;
+ i = i / 10;
+ }
+ return val;
+ }
+
+ public List findHighAccessEmployees(List> accessTimes) {
+ HashMap> map = new HashMap<>();
+ for (List list : accessTimes) {
+ List temp = map.getOrDefault(list.get(0), new ArrayList<>());
+ int val = stringToInt(list.get(1));
+ temp.add(val);
+ map.put(list.get(0), temp);
+ }
+ List ans = new ArrayList<>();
+ for (Map.Entry> entry : map.entrySet()) {
+ List temp = entry.getValue();
+ Collections.sort(temp);
+ if (isHighAccess(temp)) {
+ ans.add(entry.getKey());
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2933_high_access_employees/readme.md b/src/main/java/g2901_3000/s2933_high_access_employees/readme.md
new file mode 100644
index 000000000..9f501fb30
--- /dev/null
+++ b/src/main/java/g2901_3000/s2933_high_access_employees/readme.md
@@ -0,0 +1,49 @@
+2933\. High-Access Employees
+
+Medium
+
+You are given a 2D **0-indexed** array of strings, `access_times`, with size `n`. For each `i` where `0 <= i <= n - 1`, `access_times[i][0]` represents the name of an employee, and `access_times[i][1]` represents the access time of that employee. All entries in `access_times` are within the same day.
+
+The access time is represented as **four digits** using a **24-hour** time format, for example, `"0800"` or `"2250"`.
+
+An employee is said to be **high-access** if he has accessed the system **three or more** times within a **one-hour period**.
+
+Times with exactly one hour of difference are **not** considered part of the same one-hour period. For example, `"0815"` and `"0915"` are not part of the same one-hour period.
+
+Access times at the start and end of the day are **not** counted within the same one-hour period. For example, `"0005"` and `"2350"` are not part of the same one-hour period.
+
+Return _a list that contains the names of **high-access** employees with any order you want._
+
+**Example 1:**
+
+**Input:** access\_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]
+
+**Output:** ["a"]
+
+**Explanation:** "a" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21. But "b" does not have more than two access times at all. So the answer is ["a"].
+
+**Example 2:**
+
+**Input:** access\_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]]
+
+**Output:** ["c","d"]
+
+**Explanation:** "c" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29. "d" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08. However, "e" has just one access time, so it can not be in the answer and the final answer is ["c","d"].
+
+**Example 3:**
+
+**Input:** access\_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]]
+
+**Output:** ["ab","cd"]
+
+**Explanation:** "ab" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24. "cd" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55. So the answer is ["ab","cd"].
+
+**Constraints:**
+
+* `1 <= access_times.length <= 100`
+* `access_times[i].length == 2`
+* `1 <= access_times[i][0].length <= 10`
+* `access_times[i][0]` consists only of English small letters.
+* `access_times[i][1].length == 4`
+* `access_times[i][1]` is in 24-hour time format.
+* `access_times[i][1]` consists only of `'0'` to `'9'`.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/Solution.java b/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/Solution.java
new file mode 100644
index 000000000..06a11856e
--- /dev/null
+++ b/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/Solution.java
@@ -0,0 +1,29 @@
+package g2901_3000.s2934_minimum_operations_to_maximize_last_elements_in_arrays;
+
+// #Medium #Array #Greedy #2024_01_02_Time_1_ms_(100.00%)_Space_45.2_MB_(5.34%)
+
+public class Solution {
+ public int minOperations(int[] nums1, int[] nums2) {
+ int n = nums1.length;
+ int max1;
+ int max2;
+ int count1 = 0;
+ int count2 = 0;
+ max1 = Math.min(nums1[n - 1], nums2[n - 1]);
+ max2 = Math.max(nums1[n - 1], nums2[n - 1]);
+ for (int i = 0; i < n; i++) {
+ int min = Math.min(nums1[i], nums2[i]);
+ int max = Math.max(nums1[i], nums2[i]);
+ if (max > max2 || min > max1) {
+ return -1;
+ }
+ if (max == nums1[i] && max != min && max > max1) {
+ count1++;
+ }
+ if (max == nums2[i] && max != min && max > max1) {
+ count2++;
+ }
+ }
+ return Math.min(count1, count2);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/readme.md b/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/readme.md
new file mode 100644
index 000000000..ee7ff858f
--- /dev/null
+++ b/src/main/java/g2901_3000/s2934_minimum_operations_to_maximize_last_elements_in_arrays/readme.md
@@ -0,0 +1,70 @@
+2934\. Minimum Operations to Maximize Last Elements in Arrays
+
+Medium
+
+You are given two **0-indexed** integer arrays, `nums1` and `nums2`, both having length `n`.
+
+You are allowed to perform a series of **operations** (**possibly none**).
+
+In an operation, you select an index `i` in the range `[0, n - 1]` and **swap** the values of `nums1[i]` and `nums2[i]`.
+
+Your task is to find the **minimum** number of operations required to satisfy the following conditions:
+
+* `nums1[n - 1]` is equal to the **maximum value** among all elements of `nums1`, i.e., `nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1])`.
+* `nums2[n - 1]` is equal to the **maximum** **value** among all elements of `nums2`, i.e., `nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1])`.
+
+Return _an integer denoting the **minimum** number of operations needed to meet **both** conditions_, _or_ `-1` _if it is **impossible** to satisfy both conditions._
+
+**Example 1:**
+
+**Input:** nums1 = [1,2,7], nums2 = [4,5,3]
+
+**Output:** 1
+
+**Explanation:** In this example, an operation can be performed using index i = 2.
+
+When nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].
+
+Both conditions are now satisfied.
+
+It can be shown that the minimum number of operations needed to be performed is 1.
+
+So, the answer is 1.
+
+**Example 2:**
+
+**Input:** nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]
+
+**Output:** 2
+
+**Explanation:** In this example, the following operations can be performed:
+
+First operation using index i = 4.
+
+When nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].
+
+Another operation using index i = 3.
+
+When nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].
+
+Both conditions are now satisfied.
+
+It can be shown that the minimum number of operations needed to be performed is 2.
+
+So, the answer is 2.
+
+**Example 3:**
+
+**Input:** nums1 = [1,5,4], nums2 = [2,5,3]
+
+**Output:** -1
+
+**Explanation:** In this example, it is not possible to satisfy both conditions.
+
+So, the answer is -1.
+
+**Constraints:**
+
+* `1 <= n == nums1.length == nums2.length <= 1000`
+* 1 <= nums1[i] <= 109
+* 1 <= nums2[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/Solution.java b/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/Solution.java
new file mode 100644
index 000000000..f80a129a5
--- /dev/null
+++ b/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/Solution.java
@@ -0,0 +1,49 @@
+package g2901_3000.s2935_maximum_strong_pair_xor_ii;
+
+// #Hard #Array #Hash_Table #Bit_Manipulation #Sliding_Window #Trie
+// #2024_01_03_Time_126_ms_(76.94%)_Space_60.1_MB_(73.25%)
+
+import java.util.Arrays;
+import java.util.BitSet;
+
+public class Solution {
+ private final int[] map = new int[1 << 20];
+
+ public int maximumStrongPairXor(int[] nums) {
+ Arrays.sort(nums);
+ int n = nums.length;
+ int max = nums[n - 1];
+ int ans = 0;
+ int mask;
+ int masks = 0;
+ int highBit = 20;
+ while (--highBit >= 0) {
+ if (((max >> highBit) & 1) == 1) {
+ break;
+ }
+ }
+ int m = 1 << highBit + 1;
+ BitSet seen = new BitSet(m);
+ for (int i = highBit; i >= 0; i--) {
+ mask = 1 << i;
+ masks |= mask;
+ if (check(nums, masks, ans | mask, seen)) {
+ ans |= mask;
+ }
+ seen = new BitSet(m);
+ }
+ return ans;
+ }
+
+ private boolean check(int[] nums, int masks, int ans, BitSet seen) {
+ for (int x : nums) {
+ int mask = x & masks;
+ if (seen.get(mask ^ ans) && x <= 2 * map[mask ^ ans]) {
+ return true;
+ }
+ seen.set(mask);
+ map[mask] = x;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/readme.md b/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/readme.md
new file mode 100644
index 000000000..728d73f23
--- /dev/null
+++ b/src/main/java/g2901_3000/s2935_maximum_strong_pair_xor_ii/readme.md
@@ -0,0 +1,42 @@
+2935\. Maximum Strong Pair XOR II
+
+Hard
+
+You are given a **0-indexed** integer array `nums`. A pair of integers `x` and `y` is called a **strong** pair if it satisfies the condition:
+
+* `|x - y| <= min(x, y)`
+
+You need to select two integers from `nums` such that they form a strong pair and their bitwise `XOR` is the **maximum** among all strong pairs in the array.
+
+Return _the **maximum**_ `XOR` _value out of all possible strong pairs in the array_ `nums`.
+
+**Note** that you can pick the same integer twice to form a pair.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 7
+
+**Explanation:** There are 11 strong pairs in the array `nums`: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5). The maximum XOR possible from these pairs is 3 XOR 4 = 7.
+
+**Example 2:**
+
+**Input:** nums = [10,100]
+
+**Output:** 0
+
+**Explanation:** There are 2 strong pairs in the array nums: (10, 10) and (100, 100). The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.
+
+**Example 3:**
+
+**Input:** nums = [500,520,2500,3000]
+
+**Output:** 1020
+
+**Explanation:** There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000). The maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.
+
+**Constraints:**
+
+* 1 <= nums.length <= 5 * 104
+* 1 <= nums[i] <= 220 - 1
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2937_make_three_strings_equal/Solution.java b/src/main/java/g2901_3000/s2937_make_three_strings_equal/Solution.java
new file mode 100644
index 000000000..2f3c9306e
--- /dev/null
+++ b/src/main/java/g2901_3000/s2937_make_three_strings_equal/Solution.java
@@ -0,0 +1,19 @@
+package g2901_3000.s2937_make_three_strings_equal;
+
+// #Easy #String #2024_01_03_Time_1_ms_(100.00%)_Space_44.7_MB_(5.99%)
+
+public class Solution {
+ public int findMinimumOperations(String s1, String s2, String s3) {
+ boolean pos = true;
+ int n = Math.min(s1.length(), Math.min(s2.length(), s3.length()));
+ int ans = 0;
+ for (int i = 0; i < n && pos; i++) {
+ if (s1.charAt(i) == s2.charAt(i) && s1.charAt(i) == s3.charAt(i)) {
+ ans++;
+ } else {
+ pos = false;
+ }
+ }
+ return ans == 0 ? -1 : s1.length() + s2.length() + s3.length() - (3 * ans);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2937_make_three_strings_equal/readme.md b/src/main/java/g2901_3000/s2937_make_three_strings_equal/readme.md
new file mode 100644
index 000000000..803236c43
--- /dev/null
+++ b/src/main/java/g2901_3000/s2937_make_three_strings_equal/readme.md
@@ -0,0 +1,30 @@
+2937\. Make Three Strings Equal
+
+Easy
+
+You are given three strings `s1`, `s2`, and `s3`. You have to perform the following operation on these three strings **as many times** as you want.
+
+In one operation you can choose one of these three strings such that its length is at least `2` and delete the **rightmost** character of it.
+
+Return _the **minimum** number of operations you need to perform to make the three strings equal if there is a way to make them equal, otherwise, return_ `-1`_._
+
+**Example 1:**
+
+**Input:** s1 = "abc", s2 = "abb", s3 = "ab"
+
+**Output:** 2
+
+**Explanation:** Performing operations on s1 and s2 once will lead to three equal strings. It can be shown that there is no way to make them equal with less than two operations.
+
+**Example 2:**
+
+**Input:** s1 = "dac", s2 = "bac", s3 = "cac"
+
+**Output:** -1
+
+**Explanation:** Because the leftmost letters of s1 and s2 are not equal, they could not be equal after any number of operations. So the answer is -1.
+
+**Constraints:**
+
+* `1 <= s1.length, s2.length, s3.length <= 100`
+* `s1`, `s2` and `s3` consist only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/Solution.java b/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/Solution.java
new file mode 100644
index 000000000..bf60e9428
--- /dev/null
+++ b/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/Solution.java
@@ -0,0 +1,25 @@
+package g2901_3000.s2938_separate_black_and_white_balls;
+
+// #Medium #String #Greedy #Two_Pointers #2024_01_03_Time_7_ms_(99.65%)_Space_45.1_MB_(16.43%)
+
+public class Solution {
+ public long minimumSteps(String s) {
+ int left = 0;
+ int right = s.length() - 1;
+ long total = 0;
+ while (left < right) {
+ while (left < right && s.charAt(left) == '0') {
+ left++;
+ }
+ while (left < right && s.charAt(right) == '1') {
+ right--;
+ }
+ if (left < right) {
+ total += (right - left);
+ left++;
+ right--;
+ }
+ }
+ return total;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/readme.md b/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/readme.md
new file mode 100644
index 000000000..443df0696
--- /dev/null
+++ b/src/main/java/g2901_3000/s2938_separate_black_and_white_balls/readme.md
@@ -0,0 +1,47 @@
+2938\. Separate Black and White Balls
+
+Medium
+
+There are `n` balls on a table, each ball has a color black or white.
+
+You are given a **0-indexed** binary string `s` of length `n`, where `1` and `0` represent black and white balls, respectively.
+
+In each step, you can choose two adjacent balls and swap them.
+
+Return _the **minimum** number of steps to group all the black balls to the right and all the white balls to the left_.
+
+**Example 1:**
+
+**Input:** s = "101"
+
+**Output:** 1
+
+**Explanation:** We can group all the black balls to the right in the following way:
+- Swap s[0] and s[1], s = "011".
+
+Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.
+
+**Example 2:**
+
+**Input:** s = "100"
+
+**Output:** 2
+
+**Explanation:** We can group all the black balls to the right in the following way:
+- Swap s[0] and s[1], s = "010".
+- Swap s[1] and s[2], s = "001".
+
+It can be proven that the minimum number of steps needed is 2.
+
+**Example 3:**
+
+**Input:** s = "0111"
+
+**Output:** 0
+
+**Explanation:** All the black balls are already grouped to the right.
+
+**Constraints:**
+
+* 1 <= n == s.length <= 105
+* `s[i]` is either `'0'` or `'1'`.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2939_maximum_xor_product/Solution.java b/src/main/java/g2901_3000/s2939_maximum_xor_product/Solution.java
new file mode 100644
index 000000000..93bf95b94
--- /dev/null
+++ b/src/main/java/g2901_3000/s2939_maximum_xor_product/Solution.java
@@ -0,0 +1,31 @@
+package g2901_3000.s2939_maximum_xor_product;
+
+// #Medium #Math #Greedy #Bit_Manipulation #2024_01_03_Time_1_ms_(100.00%)_Space_41.4_MB_(14.19%)
+
+public class Solution {
+ public int maximumXorProduct(long a, long b, int n) {
+ for (int i = n - 1; i >= 0; i--) {
+ long mask = (1L << i);
+ boolean bitA = (a & mask) != 0;
+ boolean bitB = (b & mask) != 0;
+ if (bitA) {
+ if (a > b) {
+ a ^= mask;
+ b |= mask;
+ }
+ } else if (bitB) {
+ if (b > a) {
+ b ^= mask;
+ a |= mask;
+ }
+ } else {
+ b |= mask;
+ a |= mask;
+ }
+ }
+ int mod = 1000000007;
+ a = a % mod;
+ b = b % mod;
+ return (int) ((a * b) % mod);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2939_maximum_xor_product/readme.md b/src/main/java/g2901_3000/s2939_maximum_xor_product/readme.md
new file mode 100644
index 000000000..def4fa5f2
--- /dev/null
+++ b/src/main/java/g2901_3000/s2939_maximum_xor_product/readme.md
@@ -0,0 +1,38 @@
+2939\. Maximum Xor Product
+
+Medium
+
+Given three integers `a`, `b`, and `n`, return _the **maximum value** of_ `(a XOR x) * (b XOR x)` _where_ 0 <= x < 2n.
+
+Since the answer may be too large, return it **modulo** 109 + 7.
+
+**Note** that `XOR` is the bitwise XOR operation.
+
+**Example 1:**
+
+**Input:** a = 12, b = 5, n = 4
+
+**Output:** 98
+
+**Explanation:** For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) \* (b XOR x) = 98. It can be shown that 98 is the maximum value of (a XOR x) \* (b XOR x) for all 0 <= x < 2n.
+
+**Example 2:**
+
+**Input:** a = 6, b = 7 , n = 5
+
+**Output:** 930
+
+**Explanation:** For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) \* (b XOR x) = 930. It can be shown that 930 is the maximum value of (a XOR x) \* (b XOR x) for all 0 <= x < 2n.
+
+**Example 3:**
+
+**Input:** a = 1, b = 6, n = 3
+
+**Output:** 12
+
+**Explanation:** For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) \* (b XOR x) = 12. It can be shown that 12 is the maximum value of (a XOR x) \* (b XOR x) for all 0 <= x < 2n.
+
+**Constraints:**
+
+* 0 <= a, b < 250
+* `0 <= n <= 50`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/Solution.java b/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/Solution.java
new file mode 100644
index 000000000..e3a641b5b
--- /dev/null
+++ b/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/Solution.java
@@ -0,0 +1,55 @@
+package g2901_3000.s2940_find_building_where_alice_and_bob_can_meet;
+
+// #Hard #Array #Binary_Search #Stack #Heap_Priority_Queue #Monotonic_Stack #Segment_Tree
+// #Binary_Indexed_Tree #2024_01_03_Time_19_ms_(94.91%)_Space_65.5_MB_(62.16%)
+
+import java.util.LinkedList;
+
+public class Solution {
+ public int[] leftmostBuildingQueries(int[] heights, int[][] queries) {
+ int n = heights.length;
+ int[] gr = new int[n];
+ LinkedList l = new LinkedList<>();
+ l.offer(n - 1);
+ gr[n - 1] = -1;
+ for (int i = n - 2; i >= 0; i--) {
+ while (!l.isEmpty() && heights[i] > heights[l.peek()]) {
+ l.pop();
+ }
+ if (!l.isEmpty()) {
+ gr[i] = l.peek();
+ } else {
+ gr[i] = -1;
+ }
+ l.push(i);
+ }
+ int[] ans = new int[queries.length];
+ int i = 0;
+ for (int[] a : queries) {
+ int x = gr[a[0]];
+ int y = gr[a[1]];
+ if (a[0] == a[1]) {
+ ans[i++] = a[0];
+ } else if (a[0] < a[1] && heights[a[0]] < heights[a[1]]) {
+ ans[i++] = a[1];
+ } else if (a[1] < a[0] && heights[a[1]] < heights[a[0]]) {
+ ans[i++] = a[0];
+ } else if (x == -1 || y == -1) {
+ ans[i++] = -1;
+ } else {
+ int m = Math.max(a[0], a[1]);
+ while (m < heights.length
+ && m != -1
+ && (heights[m] <= heights[a[0]] || heights[m] <= heights[a[1]])) {
+ m = gr[m];
+ }
+ if (m >= heights.length || m == -1) {
+ ans[i++] = -1;
+ } else {
+ ans[i++] = m;
+ }
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/readme.md b/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/readme.md
new file mode 100644
index 000000000..92d4369c1
--- /dev/null
+++ b/src/main/java/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/readme.md
@@ -0,0 +1,59 @@
+2940\. Find Building Where Alice and Bob Can Meet
+
+Hard
+
+You are given a **0-indexed** array `heights` of positive integers, where `heights[i]` represents the height of the ith building.
+
+If a person is in building `i`, they can move to any other building `j` if and only if `i < j` and `heights[i] < heights[j]`.
+
+You are also given another array `queries` where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.
+
+Return _an array_ `ans` _where_ `ans[i]` _is **the index of the leftmost building** where Alice and Bob can meet on the_ ith _query_. _If Alice and Bob cannot move to a common building on query_ `i`, _set_ `ans[i]` _to_ `-1`.
+
+**Example 1:**
+
+**Input:** heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
+
+**Output:** [2,5,-1,5,2]
+
+**Explanation:** In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2].
+
+In the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5].
+
+In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
+
+In the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].
+
+In the fifth query, Alice and Bob are already in the same building.
+
+For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
+
+For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
+
+**Example 2:**
+
+**Input:** heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
+
+**Output:** [7,6,-1,4,6]
+
+**Explanation:** In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].
+
+In the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].
+
+In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
+
+In the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].
+
+In the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].
+
+For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
+
+For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
+
+**Constraints:**
+
+* 1 <= heights.length <= 5 * 104
+* 1 <= heights[i] <= 109
+* 1 <= queries.length <= 5 * 104
+* queries[i] = [ai, bi]
+* 0 <= ai, bi <= heights.length - 1
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2942_find_words_containing_character/Solution.java b/src/main/java/g2901_3000/s2942_find_words_containing_character/Solution.java
new file mode 100644
index 000000000..6f9311d31
--- /dev/null
+++ b/src/main/java/g2901_3000/s2942_find_words_containing_character/Solution.java
@@ -0,0 +1,21 @@
+package g2901_3000.s2942_find_words_containing_character;
+
+// #Easy #Array #String #2024_01_04_Time_2_ms_(72.65%)_Space_44.8_MB_(14.23%)
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Solution {
+ public List findWordsContaining(String[] words, char x) {
+ List ans = new ArrayList<>();
+ for (int i = 0; i < words.length; i++) {
+ for (int j = 0; j < words[i].length(); j++) {
+ if (words[i].charAt(j) == x) {
+ ans.add(i);
+ break;
+ }
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2942_find_words_containing_character/readme.md b/src/main/java/g2901_3000/s2942_find_words_containing_character/readme.md
new file mode 100644
index 000000000..731b5c96d
--- /dev/null
+++ b/src/main/java/g2901_3000/s2942_find_words_containing_character/readme.md
@@ -0,0 +1,40 @@
+2942\. Find Words Containing Character
+
+Easy
+
+You are given a **0-indexed** array of strings `words` and a character `x`.
+
+Return _an **array of indices** representing the words that contain the character_ `x`.
+
+**Note** that the returned array may be in **any** order.
+
+**Example 1:**
+
+**Input:** words = ["leet","code"], x = "e"
+
+**Output:** [0,1]
+
+**Explanation:** "e" occurs in both words: "l**ee**t", and "cod**e**". Hence, we return indices 0 and 1.
+
+**Example 2:**
+
+**Input:** words = ["abc","bcd","aaaa","cbc"], x = "a"
+
+**Output:** [0,2]
+
+**Explanation:** "a" occurs in "**a**bc", and "**aaaa**". Hence, we return indices 0 and 2.
+
+**Example 3:**
+
+**Input:** words = ["abc","bcd","aaaa","cbc"], x = "z"
+
+**Output:** []
+
+**Explanation:** "z" does not occur in any of the words. Hence, we return an empty array.
+
+**Constraints:**
+
+* `1 <= words.length <= 50`
+* `1 <= words[i].length <= 50`
+* `x` is a lowercase English letter.
+* `words[i]` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/Solution.java b/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/Solution.java
new file mode 100644
index 000000000..869f389d0
--- /dev/null
+++ b/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/Solution.java
@@ -0,0 +1,32 @@
+package g2901_3000.s2943_maximize_area_of_square_hole_in_grid;
+
+// #Medium #Array #Sorting #2024_01_04_Time_2_ms_(100.00%)_Space_43.2_MB_(70.48%)
+
+import java.util.Arrays;
+
+@SuppressWarnings("java:S1172")
+public class Solution {
+ public int maximizeSquareHoleArea(int n, int m, int[] hBars, int[] vBars) {
+ int x = find(hBars);
+ int y = find(vBars);
+ int res = Math.min(x, y) + 1;
+ return res * res;
+ }
+
+ private int find(int[] arr) {
+ Arrays.sort(arr);
+ int res = 1;
+ int i = 0;
+ int n = arr.length;
+ while (i < n) {
+ int count = 1;
+ while (i + 1 < n && arr[i] + 1 == arr[i + 1]) {
+ i++;
+ count++;
+ }
+ i++;
+ res = Math.max(res, count);
+ }
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/readme.md b/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/readme.md
new file mode 100644
index 000000000..5159a3fa9
--- /dev/null
+++ b/src/main/java/g2901_3000/s2943_maximize_area_of_square_hole_in_grid/readme.md
@@ -0,0 +1,100 @@
+2943\. Maximize Area of Square Hole in Grid
+
+Medium
+
+There is a grid with `n + 2` **horizontal** bars and `m + 2` **vertical** bars, and initially containing `1 x 1` unit cells.
+
+The bars are **1-indexed**.
+
+You are given the two integers, `n` and `m`.
+
+You are also given two integer arrays: `hBars` and `vBars`.
+
+* `hBars` contains **distinct** horizontal bars in the range `[2, n + 1]`.
+* `vBars` contains **distinct** vertical bars in the range `[2, m + 1]`.
+
+You are allowed to **remove** bars that satisfy any of the following conditions:
+
+* If it is a horizontal bar, it must correspond to a value in `hBars`.
+* If it is a vertical bar, it must correspond to a value in `vBars`.
+
+Return _an integer denoting the **maximum** area of a **square-shaped** hole in the grid after removing some bars (**possibly none**)._
+
+**Example 1:**
+
+
+
+**Input:** n = 2, m = 1, hBars = [2,3], vBars = [2]
+
+**Output:** 4
+
+**Explanation:** The left image shows the initial grid formed by the bars.
+
+The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].
+
+It is allowed to remove horizontal bars [2,3] and the vertical bar [2].
+
+One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.
+
+The resulting grid is shown on the right.
+
+The hole has an area of 4.
+
+It can be shown that it is not possible to get a square hole with an area more than 4.
+
+Hence, the answer is 4.
+
+**Example 2:**
+
+
+
+**Input:** n = 1, m = 1, hBars = [2], vBars = [2]
+
+**Output:** 4
+
+**Explanation:** The left image shows the initial grid formed by the bars.
+
+The horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].
+
+It is allowed to remove the horizontal bar [2] and the vertical bar [2].
+
+To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.
+
+The resulting grid is shown on the right.
+
+The hole has an area of 4.
+
+Hence, the answer is 4, and it is the maximum possible.
+
+**Example 3:**
+
+
+
+**Input:** n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
+
+**Output:** 9
+
+**Explanation:** The left image shows the initial grid formed by the bars.
+
+The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].
+
+It is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].
+
+One way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.
+
+The resulting grid is shown on the right.
+
+The hole has an area of 9.
+
+It can be shown that it is not possible to get a square hole with an area more than 9. Hence, the answer is 9.
+
+**Constraints:**
+
+* 1 <= n <= 109
+* 1 <= m <= 109
+* `1 <= hBars.length <= 100`
+* `2 <= hBars[i] <= n + 1`
+* `1 <= vBars.length <= 100`
+* `2 <= vBars[i] <= m + 1`
+* All values in `hBars` are distinct.
+* All values in `vBars` are distinct.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.java b/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.java
new file mode 100644
index 000000000..51c65e333
--- /dev/null
+++ b/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.java
@@ -0,0 +1,26 @@
+package g2901_3000.s2944_minimum_number_of_coins_for_fruits;
+
+// #Medium #Array #Dynamic_Programming #Heap_Priority_Queue #Queue #Monotonic_Queue
+// #2024_01_04_Time_2_ms_(99.43%)_Space_43.9_MB_(56.19%)
+
+public class Solution {
+ public int minimumCoins(int[] prices) {
+ int n = prices.length;
+ int[] dp = new int[n];
+ dp[n - 1] = prices[n - 1];
+ for (int i = n - 2; i >= 0; i--) {
+ int pos = i + 1;
+ int acquired = i + pos;
+ if (acquired + 1 < n) {
+ int min = Integer.MAX_VALUE;
+ for (int j = acquired + 1; j >= i + 1; j--) {
+ min = Math.min(min, dp[j]);
+ }
+ dp[i] = prices[i] + min;
+ } else {
+ dp[i] = prices[i];
+ }
+ }
+ return dp[0];
+ }
+}
diff --git a/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/readme.md b/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/readme.md
new file mode 100644
index 000000000..1d53a8045
--- /dev/null
+++ b/src/main/java/g2901_3000/s2944_minimum_number_of_coins_for_fruits/readme.md
@@ -0,0 +1,56 @@
+2944\. Minimum Number of Coins for Fruits
+
+Medium
+
+You are at a fruit market with different types of exotic fruits on display.
+
+You are given a **1-indexed** array `prices`, where `prices[i]` denotes the number of coins needed to purchase the ith fruit.
+
+The fruit market has the following offer:
+
+* If you purchase the ith fruit at `prices[i]` coins, you can get the next `i` fruits for free.
+
+**Note** that even if you **can** take fruit `j` for free, you can still purchase it for `prices[j]` coins to receive a new offer.
+
+Return _the **minimum** number of coins needed to acquire all the fruits_.
+
+**Example 1:**
+
+**Input:** prices = [3,1,2]
+
+**Output:** 4
+
+**Explanation:** You can acquire the fruits as follows:
+
+- Purchase the 1st fruit with 3 coins, you are allowed to take the 2nd fruit for free.
+
+- Purchase the 2nd fruit with 1 coin, you are allowed to take the 3rd fruit for free.
+
+- Take the 3rd fruit for free.
+
+Note that even though you were allowed to take the 2nd fruit for free, you purchased it because it is more optimal.
+
+It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.
+
+**Example 2:**
+
+**Input:** prices = [1,10,1,1]
+
+**Output:** 2
+
+**Explanation:** You can acquire the fruits as follows:
+
+- Purchase the 1st fruit with 1 coin, you are allowed to take the 2nd fruit for free.
+
+- Take the 2nd fruit for free.
+
+- Purchase the 3rd fruit for 1 coin, you are allowed to take the 4th fruit for free.
+
+- Take the 4th fruit for free.
+
+It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
+
+**Constraints:**
+
+* `1 <= prices.length <= 1000`
+* 1 <= prices[i] <= 105
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2951_find_the_peaks/Solution.java b/src/main/java/g2901_3000/s2951_find_the_peaks/Solution.java
new file mode 100644
index 000000000..883f41780
--- /dev/null
+++ b/src/main/java/g2901_3000/s2951_find_the_peaks/Solution.java
@@ -0,0 +1,18 @@
+package g2901_3000.s2951_find_the_peaks;
+
+// #Easy #Array #Enumeration #2024_01_15_Time_1_ms_(100.00%)_Space_43.8_MB_(79.61%)
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Solution {
+ public List findPeaks(int[] mountain) {
+ List list = new ArrayList<>();
+ for (int i = 1; i < mountain.length - 1; i++) {
+ if ((mountain[i - 1] < mountain[i]) && (mountain[i] > mountain[i + 1])) {
+ list.add(i);
+ }
+ }
+ return list;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2951_find_the_peaks/readme.md b/src/main/java/g2901_3000/s2951_find_the_peaks/readme.md
new file mode 100644
index 000000000..0a275095e
--- /dev/null
+++ b/src/main/java/g2901_3000/s2951_find_the_peaks/readme.md
@@ -0,0 +1,41 @@
+2951\. Find the Peaks
+
+Easy
+
+You are given a **0-indexed** array `mountain`. Your task is to find all the **peaks** in the `mountain` array.
+
+Return _an array that consists of_ indices _of **peaks** in the given array in **any order**._
+
+**Notes:**
+
+* A **peak** is defined as an element that is **strictly greater** than its neighboring elements.
+* The first and last elements of the array are **not** a peak.
+
+**Example 1:**
+
+**Input:** mountain = [2,4,4]
+
+**Output:** []
+
+**Explanation:** mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
+
+mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
+
+So the answer is [].
+
+**Example 2:**
+
+**Input:** mountain = [1,4,3,8,5]
+
+**Output:** [1,3]
+
+**Explanation:** mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
+
+mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
+
+But mountain [1] and mountain[3] are strictly greater than their neighboring elements. So the answer is [1,3].
+
+**Constraints:**
+
+* `3 <= mountain.length <= 100`
+* `1 <= mountain[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/Solution.java b/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/Solution.java
new file mode 100644
index 000000000..de8b8cfad
--- /dev/null
+++ b/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/Solution.java
@@ -0,0 +1,24 @@
+package g2901_3000.s2952_minimum_number_of_coins_to_be_added;
+
+// #Medium #Array #Sorting #Greedy #2024_01_15_Time_21_ms_(98.49%)_Space_61.9_MB_(5.41%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int minimumAddedCoins(int[] coins, int target) {
+ int res = 0;
+ int num = 0;
+ int i = 0;
+ Arrays.sort(coins);
+ while (num < target) {
+ if (i < coins.length && coins[i] <= num + 1) {
+ num += coins[i];
+ i++;
+ } else {
+ res += 1;
+ num += num + 1;
+ }
+ }
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/readme.md b/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/readme.md
new file mode 100644
index 000000000..c4f8507f0
--- /dev/null
+++ b/src/main/java/g2901_3000/s2952_minimum_number_of_coins_to_be_added/readme.md
@@ -0,0 +1,47 @@
+2952\. Minimum Number of Coins to be Added
+
+Medium
+
+You are given a **0-indexed** integer array `coins`, representing the values of the coins available, and an integer `target`.
+
+An integer `x` is **obtainable** if there exists a subsequence of `coins` that sums to `x`.
+
+Return _the **minimum** number of coins **of any value** that need to be added to the array so that every integer in the range_ `[1, target]` _is **obtainable**_.
+
+A **subsequence** of an array is a new **non-empty** array that is formed from the original array by deleting some (**possibly none**) of the elements without disturbing the relative positions of the remaining elements.
+
+**Example 1:**
+
+**Input:** coins = [1,4,10], target = 19
+
+**Output:** 2
+
+**Explanation:** We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].
+
+It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.
+
+**Example 2:**
+
+**Input:** coins = [1,4,10,5,7,19], target = 19
+
+**Output:** 1
+
+**Explanation:** We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].
+
+It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.
+
+**Example 3:**
+
+**Input:** coins = [1,1,1], target = 20
+
+**Output:** 3
+
+**Explanation:** We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].
+
+It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.
+
+**Constraints:**
+
+* 1 <= target <= 105
+* 1 <= coins.length <= 105
+* `1 <= coins[i] <= target`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2953_count_complete_substrings/Solution.java b/src/main/java/g2901_3000/s2953_count_complete_substrings/Solution.java
new file mode 100644
index 000000000..a03b23f40
--- /dev/null
+++ b/src/main/java/g2901_3000/s2953_count_complete_substrings/Solution.java
@@ -0,0 +1,51 @@
+package g2901_3000.s2953_count_complete_substrings;
+
+// #Hard #String #Hash_Table #Sliding_Window #2024_01_15_Time_107_ms_(89.47%)_Space_47_MB_(42.61%)
+
+public class Solution {
+ public int countCompleteSubstrings(String word, int k) {
+ char[] arr = word.toCharArray();
+ int n = arr.length;
+ int result = 0;
+ int last = 0;
+ for (int i = 1; i <= n; i++) {
+ if (i == n || Math.abs(arr[i] - arr[i - 1]) > 2) {
+ result += getCount(arr, k, last, i - 1);
+ last = i;
+ }
+ }
+ return result;
+ }
+
+ private int getCount(char[] arr, int k, int start, int end) {
+ int result = 0;
+ for (int i = 1; i <= 26 && i * k <= end - start + 1; i++) {
+ int[] cnt = new int[26];
+ int good = 0;
+ for (int j = start; j <= end; j++) {
+ char cR = arr[j];
+ cnt[cR - 'a']++;
+ if (cnt[cR - 'a'] == k) {
+ good++;
+ }
+ if (cnt[cR - 'a'] == k + 1) {
+ good--;
+ }
+ if (j >= start + i * k) {
+ char cL = arr[j - i * k];
+ if (cnt[cL - 'a'] == k) {
+ good--;
+ }
+ if (cnt[cL - 'a'] == k + 1) {
+ good++;
+ }
+ cnt[cL - 'a']--;
+ }
+ if (good == i) {
+ result++;
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2953_count_complete_substrings/readme.md b/src/main/java/g2901_3000/s2953_count_complete_substrings/readme.md
new file mode 100644
index 000000000..d27538b83
--- /dev/null
+++ b/src/main/java/g2901_3000/s2953_count_complete_substrings/readme.md
@@ -0,0 +1,36 @@
+2953\. Count Complete Substrings
+
+Hard
+
+You are given a string `word` and an integer `k`.
+
+A substring `s` of `word` is **complete** if:
+
+* Each character in `s` occurs **exactly** `k` times.
+* The difference between two adjacent characters is **at most** `2`. That is, for any two adjacent characters `c1` and `c2` in `s`, the absolute difference in their positions in the alphabet is **at most** `2`.
+
+Return _the number of **complete** substrings of_ `word`.
+
+A **substring** is a **non-empty** contiguous sequence of characters in a string.
+
+**Example 1:**
+
+**Input:** word = "igigee", k = 2
+
+**Output:** 3
+
+**Explanation:** The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: **igig**ee, igig**ee**, **igigee**.
+
+**Example 2:**
+
+**Input:** word = "aaabbbccc", k = 3
+
+**Output:** 6
+
+**Explanation:** The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: **aaa**bbbccc, aaa**bbb**ccc, aaabbb**ccc**, **aaabbb**ccc, aaa**bbbccc**, **aaabbbccc**.
+
+**Constraints:**
+
+* 1 <= word.length <= 105
+* `word` consists only of lowercase English letters.
+* `1 <= k <= word.length`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.java b/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.java
new file mode 100644
index 000000000..0235dd0a4
--- /dev/null
+++ b/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.java
@@ -0,0 +1,45 @@
+package g2901_3000.s2954_count_the_number_of_infection_sequences;
+
+// #Hard #Array #Math #Combinatorics #2024_01_15_Time_11_ms_(99.61%)_Space_46.3_MB_(29.46%)
+
+public class Solution {
+ private static final int M = 100000;
+ private final long[] fact = new long[M + 1];
+ private final long[] invFact = new long[M + 1];
+ private static final int MOD = 1000000007;
+ private long init = 0;
+
+ private int modPow(int x, int y, int mod) {
+ if (y == 0) {
+ return 1;
+ }
+ long p = modPow(x, y / 2, mod) % mod;
+ p = (p * p) % mod;
+ return y % 2 == 1 ? (int) (p * x % mod) : (int) p;
+ }
+
+ private long binomCoeff(int n, int k) {
+ return Math.max(1L, fact[n] * invFact[k] % MOD * invFact[n - k] % MOD);
+ }
+
+ public int numberOfSequence(int n, int[] sick) {
+ if (init == 0) {
+ init = 1;
+ fact[0] = 1;
+ for (int i = 1; i <= M; ++i) {
+ fact[i] = fact[i - 1] * i % MOD;
+ }
+ invFact[M] = modPow((int) fact[M], MOD - 2, MOD);
+ for (int i = M - 1; i > 0; --i) {
+ invFact[i] = invFact[i + 1] * (i + 1) % MOD;
+ }
+ }
+ long res = 1;
+ for (int i = 1; i < sick.length; ++i) {
+ int group = sick[i] - sick[i - 1] - 1;
+ res = res * modPow(2, Math.max(0, group - 1), MOD) % MOD;
+ res = res * binomCoeff(sick[i] - i, group) % MOD;
+ }
+ return (int) (res * binomCoeff(n - sick.length, n - sick[sick.length - 1] - 1) % MOD);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/readme.md b/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/readme.md
new file mode 100644
index 000000000..fd6ce044a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2954_count_the_number_of_infection_sequences/readme.md
@@ -0,0 +1,49 @@
+2954\. Count the Number of Infection Sequences
+
+Hard
+
+You are given an integer `n` and a **0-indexed** integer array `sick` which is **sorted** in **increasing** order.
+
+There are `n` children standing in a queue with positions `0` to `n - 1` assigned to them. The array `sick` contains the positions of the children who are infected with an infectious disease. An infected child at position `i` can spread the disease to either of its immediate neighboring children at positions `i - 1` and `i + 1` **if** they exist and are currently not infected. **At most one** child who was previously not infected can get infected with the disease in one second.
+
+It can be shown that after a finite number of seconds, all the children in the queue will get infected with the disease. An **infection sequence** is the sequential order of positions in which **all** of the non-infected children get infected with the disease. Return _the total number of possible infection sequences_.
+
+Since the answer may be large, return it modulo 109 + 7.
+
+**Note** that an infection sequence **does not** contain positions of children who were already infected with the disease in the beginning.
+
+**Example 1:**
+
+**Input:** n = 5, sick = [0,4]
+
+**Output:** 4
+
+**Explanation:** Children at positions 1, 2, and 3 are not infected in the beginning. There are 4 possible infection sequences:
+- The children at positions 1 and 3 can get infected since their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
+
+Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 2 gets infected. Finally, the child at position 3 gets infected because it is adjacent to children at positions 2 and 4 who are infected. The infection sequence is [1,2,3].
+- The children at positions 1 and 3 can get infected because their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
+
+Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 3 gets infected.
+
+Finally, the child at position 2 gets infected because it is adjacent to children at positions 1 and 3 who are infected. The infection sequence is [1,3,2].
+- The infection sequence is [3,1,2]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].
+- The infection sequence is [3,2,1]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].
+
+**Example 2:**
+
+**Input:** n = 4, sick = [1]
+
+**Output:** 3
+
+**Explanation:** Children at positions 0, 2, and 3 are not infected in the beginning. There are 3 possible infection sequences:
+- The infection sequence is [0,2,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].
+- The infection sequence is [2,0,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].
+- The infection sequence is [2,3,0]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].
+
+**Constraints:**
+
+* 2 <= n <= 105
+* `1 <= sick.length <= n - 1`
+* `0 <= sick[i] <= n - 1`
+* `sick` is sorted in increasing order.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/Solution.java b/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/Solution.java
new file mode 100644
index 000000000..6fe95c34f
--- /dev/null
+++ b/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/Solution.java
@@ -0,0 +1,22 @@
+package g2901_3000.s2956_find_common_elements_between_two_arrays;
+
+// #Easy #Array #Hash_Table #2024_01_15_Time_1_ms_(100.00%)_Space_45.6_MB_(11.23%)
+
+public class Solution {
+ public int[] findIntersectionValues(int[] nums1, int[] nums2) {
+ int[] freq2 = new int[101];
+ int[] freq1 = new int[101];
+ int[] ans = new int[2];
+ for (int j : nums2) {
+ freq2[j] = 1;
+ }
+ for (int j : nums1) {
+ freq1[j] = 1;
+ ans[0] = ans[0] + freq2[j];
+ }
+ for (int j : nums2) {
+ ans[1] = ans[1] + freq1[j];
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/readme.md b/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/readme.md
new file mode 100644
index 000000000..fa0abb2d1
--- /dev/null
+++ b/src/main/java/g2901_3000/s2956_find_common_elements_between_two_arrays/readme.md
@@ -0,0 +1,37 @@
+2956\. Find Common Elements Between Two Arrays
+
+Easy
+
+You are given two **0-indexed** integer arrays `nums1` and `nums2` of sizes `n` and `m`, respectively.
+
+Consider calculating the following values:
+
+* The number of indices `i` such that `0 <= i < n` and `nums1[i]` occurs **at least** once in `nums2`.
+* The number of indices `i` such that `0 <= i < m` and `nums2[i]` occurs **at least** once in `nums1`.
+
+Return _an integer array_ `answer` _of size_ `2` _containing the two values **in the above order**_.
+
+**Example 1:**
+
+**Input:** nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
+
+**Output:** [3,4]
+
+**Explanation:** We calculate the values as follows:
+- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.
+- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.
+
+**Example 2:**
+
+**Input:** nums1 = [3,4,2,3], nums2 = [1,5]
+
+**Output:** [0,0]
+
+**Explanation:** There are no common elements between the two arrays, so the two values will be 0.
+
+**Constraints:**
+
+* `n == nums1.length`
+* `m == nums2.length`
+* `1 <= n, m <= 100`
+* `1 <= nums1[i], nums2[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/Solution.java b/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/Solution.java
new file mode 100644
index 000000000..18ec1c4c5
--- /dev/null
+++ b/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/Solution.java
@@ -0,0 +1,22 @@
+package g2901_3000.s2957_remove_adjacent_almost_equal_characters;
+
+// #Medium #String #Dynamic_Programming #Greedy
+// #2024_01_15_Time_1_ms_(100.00%)_Space_42.1_MB_(15.57%)
+
+public class Solution {
+ public int removeAlmostEqualCharacters(String word) {
+ int count = 0;
+ char[] wordArray = word.toCharArray();
+ for (int i = 1; i < wordArray.length; i++) {
+ if (Math.abs(wordArray[i] - wordArray[i - 1]) <= 1) {
+ count++;
+ wordArray[i] =
+ (i + 1 < wordArray.length
+ && (wordArray[i + 1] != 'a' && wordArray[i + 1] != 'b'))
+ ? 'a'
+ : 'z';
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/readme.md b/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/readme.md
new file mode 100644
index 000000000..6894b891c
--- /dev/null
+++ b/src/main/java/g2901_3000/s2957_remove_adjacent_almost_equal_characters/readme.md
@@ -0,0 +1,46 @@
+2957\. Remove Adjacent Almost-Equal Characters
+
+Medium
+
+You are given a **0-indexed** string `word`.
+
+In one operation, you can pick any index `i` of `word` and change `word[i]` to any lowercase English letter.
+
+Return _the **minimum** number of operations needed to remove all adjacent **almost-equal** characters from_ `word`.
+
+Two characters `a` and `b` are **almost-equal** if `a == b` or `a` and `b` are adjacent in the alphabet.
+
+**Example 1:**
+
+**Input:** word = "aaaaa"
+
+**Output:** 2
+
+**Explanation:** We can change word into "a**c**a**c**a" which does not have any adjacent almost-equal characters.
+
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
+
+**Example 2:**
+
+**Input:** word = "abddez"
+
+**Output:** 2
+
+**Explanation:** We can change word into "**y**bd**o**ez" which does not have any adjacent almost-equal characters.
+
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
+
+**Example 3:**
+
+**Input:** word = "zyxyxyz"
+
+**Output:** 3
+
+**Explanation:** We can change word into "z**a**x**a**x**a**z" which does not have any adjacent almost-equal characters.
+
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
+
+**Constraints:**
+
+* `1 <= word.length <= 100`
+* `word` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.java b/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.java
new file mode 100644
index 000000000..9782ac6c4
--- /dev/null
+++ b/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.java
@@ -0,0 +1,33 @@
+package g2901_3000.s2958_length_of_longest_subarray_with_at_most_k_frequency;
+
+// #Medium #Array #Hash_Table #Sliding_Window
+// #2024_01_15_Time_28_ms_(100.00%)_Space_168.1_MB_(5.02%)
+
+public class Solution {
+ public int maxSubarrayLength(int[] nums, int k) {
+ int m1 = Integer.MIN_VALUE;
+ int m2 = Integer.MAX_VALUE;
+ for (int num : nums) {
+ m1 = Math.max(m1, num);
+ m2 = Math.min(m2, num);
+ }
+ int max = 0;
+ int[] f = new int[m1 - m2 + 1];
+ int l = 0;
+ int r = 0;
+ while (r < nums.length) {
+ f[nums[r] - m2]++;
+ while (count(f, nums[r] - m2) > k) {
+ f[nums[l] - m2]--;
+ l++;
+ }
+ max = Math.max(max, r - l + 1);
+ r++;
+ }
+ return max;
+ }
+
+ private int count(int[] f, int n) {
+ return f[n];
+ }
+}
diff --git a/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/readme.md b/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/readme.md
new file mode 100644
index 000000000..9dfab51d9
--- /dev/null
+++ b/src/main/java/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/readme.md
@@ -0,0 +1,43 @@
+2958\. Length of Longest Subarray With at Most K Frequency
+
+Medium
+
+You are given an integer array `nums` and an integer `k`.
+
+The **frequency** of an element `x` is the number of times it occurs in an array.
+
+An array is called **good** if the frequency of each element in this array is **less than or equal** to `k`.
+
+Return _the length of the **longest** **good** subarray of_ `nums`_._
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,1,2,3,1,2], k = 2
+
+**Output:** 6
+
+**Explanation:** The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good. It can be shown that there are no good subarrays with length more than 6.
+
+**Example 2:**
+
+**Input:** nums = [1,2,1,2,1,2,1,2], k = 1
+
+**Output:** 2
+
+**Explanation:** The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good. It can be shown that there are no good subarrays with length more than 2.
+
+**Example 3:**
+
+**Input:** nums = [5,5,5,5,5,5,5], k = 4
+
+**Output:** 4
+
+**Explanation:** The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray. It can be shown that there are no good subarrays with length more than 4.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 109
+* `1 <= k <= nums.length`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/Solution.java b/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/Solution.java
new file mode 100644
index 000000000..45dc940c3
--- /dev/null
+++ b/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/Solution.java
@@ -0,0 +1,79 @@
+package g2901_3000.s2959_number_of_possible_sets_of_closing_branches;
+
+// #Hard #Bit_Manipulation #Heap_Priority_Queue #Graph #Enumeration #Shortest_Path
+// #2024_01_15_Time_36_ms_(83.41%)_Space_44.9_MB_(14.96%)
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+public class Solution {
+ private int get(int n, int maxDis, int mask, List> al) {
+ int nodes = 0;
+ boolean[] m = new boolean[n];
+ for (int i = 0; i < n; i++) {
+ int val = mask & (1 << i);
+ if (val > 0) {
+ m[i] = true;
+ nodes++;
+ }
+ }
+ if (nodes == n) {
+ return 1;
+ }
+ for (int startVertex = 0; startVertex < n; startVertex++) {
+ if (m[startVertex]) {
+ continue;
+ }
+ Queue q = new LinkedList<>();
+ q.add(new int[] {startVertex, 0});
+ int[] dis = new int[n];
+ Arrays.fill(dis, Integer.MAX_VALUE);
+ dis[startVertex] = 0;
+ int nodeCount = 1;
+ while (!q.isEmpty()) {
+ int[] curr = q.poll();
+ for (int[] adj : al.get(curr[0])) {
+ if (!m[adj[0]] && curr[1] + adj[1] <= dis[adj[0]]) {
+ if (dis[adj[0]] == Integer.MAX_VALUE) {
+ nodeCount++;
+ }
+ dis[adj[0]] = curr[1] + adj[1];
+ q.add(new int[] {adj[0], dis[adj[0]]});
+ }
+ }
+ }
+ for (int i = 0; i < n; i++) {
+ if (!m[i] && dis[i] > maxDis) {
+ return 0;
+ }
+ }
+ if (nodes != n - nodeCount) {
+ return 0;
+ }
+ }
+ return 1;
+ }
+
+ private int solve(int n, int maxDis, List> al) {
+ int res = 0;
+ for (int i = 0; i < (1 << n); i++) {
+ res += get(n, maxDis, i, al);
+ }
+ return res;
+ }
+
+ public int numberOfSets(int n, int maxDistance, int[][] roads) {
+ List> al = new ArrayList<>();
+ for (int i = 0; i < n; i++) {
+ al.add(new ArrayList<>());
+ }
+ for (int[] edge : roads) {
+ al.get(edge[0]).add(new int[] {edge[1], edge[2]});
+ al.get(edge[1]).add(new int[] {edge[0], edge[2]});
+ }
+ return solve(n, maxDistance, al);
+ }
+}
diff --git a/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/readme.md b/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/readme.md
new file mode 100644
index 000000000..766505480
--- /dev/null
+++ b/src/main/java/g2901_3000/s2959_number_of_possible_sets_of_closing_branches/readme.md
@@ -0,0 +1,76 @@
+2959\. Number of Possible Sets of Closing Branches
+
+Hard
+
+There is a company with `n` branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.
+
+The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (**possibly none**). However, they want to ensure that the remaining branches have a distance of at most `maxDistance` from each other.
+
+The **distance** between two branches is the **minimum** total traveled length needed to reach one branch from another.
+
+You are given integers `n`, `maxDistance`, and a **0-indexed** 2D array `roads`, where roads[i] = [ui, vi, wi] represents the **undirected** road between branches ui and vi with length wi.
+
+Return _the number of possible sets of closing branches, so that any branch has a distance of at most_ `maxDistance` _from any other_.
+
+**Note** that, after closing a branch, the company will no longer have access to any roads connected to it.
+
+**Note** that, multiple roads are allowed.
+
+**Example 1:**
+
+
+
+**Input:** n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]
+
+**Output:** 5
+
+**Explanation:** The possible sets of closing branches are:
+- The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.
+- The set [0,1], after closing, the active branch is [2].
+- The set [1,2], after closing, the active branch is [0].
+- The set [0,2], after closing, the active branch is [1].
+- The set [0,1,2], after closing, there are no active branches.
+
+It can be proven, that there are only 5 possible sets of closing branches.
+
+**Example 2:**
+
+
+
+**Input:** n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]
+
+**Output:** 7
+
+**Explanation:** The possible sets of closing branches are:
+- The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.
+- The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.
+- The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.
+- The set [0,1], after closing, the active branch is [2].
+- The set [1,2], after closing, the active branch is [0].
+- The set [0,2], after closing, the active branch is [1].
+- The set [0,1,2], after closing, there are no active branches.
+
+It can be proven, that there are only 7 possible sets of closing branches.
+
+**Example 3:**
+
+**Input:** n = 1, maxDistance = 10, roads = []
+
+**Output:** 2
+
+**Explanation:** The possible sets of closing branches are:
+- The set [], after closing, the active branch is [0].
+- The set [0], after closing, there are no active branches.
+
+It can be proven, that there are only 2 possible sets of closing branches.
+
+**Constraints:**
+
+* `1 <= n <= 10`
+* 1 <= maxDistance <= 105
+* `0 <= roads.length <= 1000`
+* `roads[i].length == 3`
+* 0 <= ui, vi <= n - 1
+* ui != vi
+* 1 <= wi <= 1000
+* All branches are reachable from each other by traveling some roads.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/Solution.java b/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/Solution.java
new file mode 100644
index 000000000..6ff37d190
--- /dev/null
+++ b/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/Solution.java
@@ -0,0 +1,17 @@
+package g2901_3000.s2960_count_tested_devices_after_test_operations;
+
+// #Easy #Array #Simulation #2024_01_15_Time_0_ms_(100.00%)_Space_43.4_MB_(43.00%)
+
+public class Solution {
+ public int countTestedDevices(int[] batteryPercentages) {
+ int count = 0;
+ int diff = 0;
+ for (int n : batteryPercentages) {
+ if (n - diff > 0) {
+ count++;
+ diff++;
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/readme.md b/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/readme.md
new file mode 100644
index 000000000..6452cec22
--- /dev/null
+++ b/src/main/java/g2901_3000/s2960_count_tested_devices_after_test_operations/readme.md
@@ -0,0 +1,56 @@
+2960\. Count Tested Devices After Test Operations
+
+Easy
+
+You are given a **0-indexed** integer array `batteryPercentages` having length `n`, denoting the battery percentages of `n` **0-indexed** devices.
+
+Your task is to test each device `i` **in order** from `0` to `n - 1`, by performing the following test operations:
+
+* If `batteryPercentages[i]` is **greater** than `0`:
+ * **Increment** the count of tested devices.
+ * **Decrease** the battery percentage of all devices with indices `j` in the range `[i + 1, n - 1]` by `1`, ensuring their battery percentage **never goes below** `0`, i.e, `batteryPercentages[j] = max(0, batteryPercentages[j] - 1)`.
+ * Move to the next device.
+* Otherwise, move to the next device without performing any test.
+
+Return _an integer denoting the number of devices that will be tested after performing the test operations in order._
+
+**Example 1:**
+
+**Input:** batteryPercentages = [1,1,2,1,3]
+
+**Output:** 3
+
+**Explanation:** Performing the test operations in order starting from device 0:
+
+At device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].
+
+At device 1, batteryPercentages[1] == 0, so we move to the next device without testing.
+
+At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].
+
+At device 3, batteryPercentages[3] == 0, so we move to the next device without testing.
+
+At device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.
+
+So, the answer is 3.
+
+**Example 2:**
+
+**Input:** batteryPercentages = [0,1,2]
+
+**Output:** 2
+
+**Explanation:** Performing the test operations in order starting from device 0:
+
+At device 0, batteryPercentages[0] == 0, so we move to the next device without testing.
+
+At device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].
+
+At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.
+
+So, the answer is 2.
+
+**Constraints:**
+
+* `1 <= n == batteryPercentages.length <= 100`
+* `0 <= batteryPercentages[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2961_double_modular_exponentiation/Solution.java b/src/main/java/g2901_3000/s2961_double_modular_exponentiation/Solution.java
new file mode 100644
index 000000000..4b293ba81
--- /dev/null
+++ b/src/main/java/g2901_3000/s2961_double_modular_exponentiation/Solution.java
@@ -0,0 +1,46 @@
+package g2901_3000.s2961_double_modular_exponentiation;
+
+// #Medium #Array #Math #Simulation #2024_01_15_Time_1_ms_(100.00%)_Space_44.5_MB_(11.00%)
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Solution {
+ private long myPow(int a, int b, int mod) {
+ long ans = 1;
+ if (b == 0) {
+ return 1;
+ }
+ if (a <= 1) {
+ return a;
+ }
+ while (b > 0) {
+ if (b % 2 == 0) {
+ a = a * a % mod;
+ b = b / 2;
+ } else {
+ ans *= a;
+ b -= 1;
+ ans = ans % mod;
+ }
+ }
+ return ans;
+ }
+
+ public List getGoodIndices(int[][] variables, int target) {
+ int n = variables.length;
+ List goodIndices = new ArrayList<>();
+ for (int i = 0; i < n; i++) {
+ int ai = variables[i][0];
+ int bi = variables[i][1];
+ int ci = variables[i][2];
+ int mi = variables[i][3];
+ long ans = myPow(ai % 10, bi, 10) % 10;
+ ans = myPow((int) ans, ci, mi) % mi;
+ if (ans == target) {
+ goodIndices.add(i);
+ }
+ }
+ return goodIndices;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2961_double_modular_exponentiation/readme.md b/src/main/java/g2901_3000/s2961_double_modular_exponentiation/readme.md
new file mode 100644
index 000000000..919528c74
--- /dev/null
+++ b/src/main/java/g2901_3000/s2961_double_modular_exponentiation/readme.md
@@ -0,0 +1,43 @@
+2961\. Double Modular Exponentiation
+
+Medium
+
+You are given a **0-indexed** 2D array `variables` where variables[i] = [ai, bi, ci, mi], and an integer `target`.
+
+An index `i` is **good** if the following formula holds:
+
+* `0 <= i < variables.length`
+* ((aibi % 10)ci) % mi == target
+
+Return _an array consisting of **good** indices in **any order**_.
+
+**Example 1:**
+
+**Input:** variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2
+
+**Output:** [0,2]
+
+**Explanation:** For each index i in the variables array:
+1) For the index 0, variables[0] = [2,3,3,10], (23 % 10)3 % 10 = 2.
+2) For the index 1, variables[1] = [3,3,3,1], (33 % 10)3 % 1 = 0.
+3) For the index 2, variables[2] = [6,1,1,4], (61 % 10)1 % 4 = 2.
+
+Therefore we return [0,2] as the answer.
+
+**Example 2:**
+
+**Input:** variables = [[39,3,1000,1000]], target = 17
+
+**Output:** []
+
+**Explanation:** For each index i in the variables array:
+1) For the index 0, variables[0] = [39,3,1000,1000], (393 % 10)1000 % 1000 = 1.
+
+Therefore we return [] as the answer.
+
+**Constraints:**
+
+* `1 <= variables.length <= 100`
+* variables[i] == [ai, bi, ci, mi]
+* 1 <= ai, bi, ci, mi <= 103
+* 0 <= target <= 103
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/Solution.java b/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/Solution.java
new file mode 100644
index 000000000..9081750f1
--- /dev/null
+++ b/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/Solution.java
@@ -0,0 +1,29 @@
+package g2901_3000.s2962_count_subarrays_where_max_element_appears_at_least_k_times;
+
+// #Medium #Array #Sliding_Window #2024_01_16_Time_3_ms_(100.00%)_Space_61.6_MB_(12.43%)
+
+public class Solution {
+ public long countSubarrays(int[] n, int k) {
+ int[] st = new int[n.length + 1];
+ int si = 0;
+ int m = 0;
+ for (int i = 0; i < n.length; i++) {
+ if (m < n[i]) {
+ m = n[i];
+ si = 0;
+ }
+ if (m == n[i]) {
+ st[si++] = i;
+ }
+ }
+ if (si < k) {
+ return 0;
+ }
+ long r = 0;
+ st[si] = n.length;
+ for (int i = k; i <= si; i++) {
+ r += (long) (st[i - k] + 1) * (st[i] - st[i - 1]);
+ }
+ return r;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/readme.md b/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/readme.md
new file mode 100644
index 000000000..1be128ae8
--- /dev/null
+++ b/src/main/java/g2901_3000/s2962_count_subarrays_where_max_element_appears_at_least_k_times/readme.md
@@ -0,0 +1,31 @@
+2962\. Count Subarrays Where Max Element Appears at Least K Times
+
+Medium
+
+You are given an integer array `nums` and a **positive** integer `k`.
+
+Return _the number of subarrays where the **maximum** element of_ `nums` _appears **at least**_ `k` _times in that subarray._
+
+A **subarray** is a contiguous sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,3,2,3,3], k = 2
+
+**Output:** 6
+
+**Explanation:** The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].
+
+**Example 2:**
+
+**Input:** nums = [1,4,2,1], k = 3
+
+**Output:** 0
+
+**Explanation:** No subarray contains the element 4 at least 3 times.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 106
+* 1 <= k <= 105
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/Solution.java b/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/Solution.java
new file mode 100644
index 000000000..d056f23b0
--- /dev/null
+++ b/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/Solution.java
@@ -0,0 +1,34 @@
+package g2901_3000.s2963_count_the_number_of_good_partitions;
+
+// #Hard #Array #Hash_Table #Math #Combinatorics
+// #2024_01_16_Time_30_ms_(80.04%)_Space_64.3_MB_(30.54%)
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Solution {
+ public int numberOfGoodPartitions(int[] nums) {
+ Map mp = new HashMap<>();
+ int n = nums.length;
+ for (int i = 0; i < n; i++) {
+ mp.put(nums[i], i);
+ }
+ int i = 0;
+ int j = 0;
+ int cnt = 0;
+ while (i < n) {
+ j = Math.max(j, mp.get(nums[i]));
+ if (i == j) {
+ cnt++;
+ }
+ i++;
+ }
+ int res = 1;
+ for (int k = 1; k < cnt; k++) {
+ res = res * 2;
+ int mod = 1000000007;
+ res %= mod;
+ }
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/readme.md b/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/readme.md
new file mode 100644
index 000000000..59291ab66
--- /dev/null
+++ b/src/main/java/g2901_3000/s2963_count_the_number_of_good_partitions/readme.md
@@ -0,0 +1,40 @@
+2963\. Count the Number of Good Partitions
+
+Hard
+
+You are given a **0-indexed** array `nums` consisting of **positive** integers.
+
+A partition of an array into one or more **contiguous** subarrays is called **good** if no two subarrays contain the same number.
+
+Return _the **total number** of good partitions of_ `nums`.
+
+Since the answer may be large, return it **modulo** 109 + 7.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4]
+
+**Output:** 8
+
+**Explanation:** The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).
+
+**Example 2:**
+
+**Input:** nums = [1,1,1,1]
+
+**Output:** 1
+
+**Explanation:** The only possible good partition is: ([1,1,1,1]).
+
+**Example 3:**
+
+**Input:** nums = [1,2,1,3]
+
+**Output:** 2
+
+**Explanation:** The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/Solution.java b/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/Solution.java
new file mode 100644
index 000000000..f8a014988
--- /dev/null
+++ b/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/Solution.java
@@ -0,0 +1,22 @@
+package g2901_3000.s2965_find_missing_and_repeated_values;
+
+// #Easy #Array #Hash_Table #Math #Matrix #2024_01_16_Time_1_ms_(100.00%)_Space_45.4_MB_(17.99%)
+
+public class Solution {
+ public int[] findMissingAndRepeatedValues(int[][] grid) {
+ int nSquare = grid.length * grid.length;
+ int sum = nSquare * (nSquare + 1) / 2;
+ boolean[] found = new boolean[nSquare + 1];
+ int repeated = 1;
+ for (int[] row : grid) {
+ for (int n : row) {
+ sum -= n;
+ if (found[n]) {
+ repeated = n;
+ }
+ found[n] = true;
+ }
+ }
+ return new int[] {repeated, sum + repeated};
+ }
+}
diff --git a/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/readme.md b/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/readme.md
new file mode 100644
index 000000000..1cf45e1b3
--- /dev/null
+++ b/src/main/java/g2901_3000/s2965_find_missing_and_repeated_values/readme.md
@@ -0,0 +1,31 @@
+2965\. Find Missing and Repeated Values
+
+Easy
+
+You are given a **0-indexed** 2D integer matrix `grid` of size `n * n` with values in the range [1, n2]. Each integer appears **exactly once** except `a` which appears **twice** and `b` which is **missing**. The task is to find the repeating and missing numbers `a` and `b`.
+
+Return _a **0-indexed** integer array_ `ans` _of size_ `2` _where_ `ans[0]` _equals to_ `a` _and_ `ans[1]` _equals to_ `b`_._
+
+**Example 1:**
+
+**Input:** grid = [[1,3],[2,2]]
+
+**Output:** [2,4]
+
+**Explanation:** Number 2 is repeated and number 4 is missing so the answer is [2,4].
+
+**Example 2:**
+
+**Input:** grid = [[9,1,7],[8,9,2],[3,4,6]]
+
+**Output:** [9,5]
+
+**Explanation:** Number 9 is repeated and number 5 is missing so the answer is [9,5].
+
+**Constraints:**
+
+* `2 <= n == grid.length == grid[i].length <= 50`
+* `1 <= grid[i][j] <= n * n`
+* For all `x` that `1 <= x <= n * n` there is exactly one `x` that is not equal to any of the grid members.
+* For all `x` that `1 <= x <= n * n` there is exactly one `x` that is equal to exactly two of the grid members.
+* For all `x` that `1 <= x <= n * n` except two of them there is exatly one pair of `i, j` that `0 <= i, j <= n - 1` and `grid[i][j] == x`.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/Solution.java b/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/Solution.java
new file mode 100644
index 000000000..5c50b2530
--- /dev/null
+++ b/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/Solution.java
@@ -0,0 +1,23 @@
+package g2901_3000.s2966_divide_array_into_arrays_with_max_difference;
+
+// #Medium #Array #Sorting #Greedy #2024_01_16_Time_20_ms_(99.04%)_Space_59.4_MB_(10.50%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int[][] divideArray(int[] nums, int k) {
+ Arrays.sort(nums);
+ int n = nums.length;
+ int triplets = n / 3;
+ int[][] result = new int[triplets][];
+ for (int i = 0, j = 0; i < n; i += 3, j++) {
+ int first = nums[i];
+ int third = nums[i + 2];
+ if (third - first > k) {
+ return new int[0][];
+ }
+ result[j] = new int[] {first, nums[i + 1], third};
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/readme.md b/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/readme.md
new file mode 100644
index 000000000..08a639b6e
--- /dev/null
+++ b/src/main/java/g2901_3000/s2966_divide_array_into_arrays_with_max_difference/readme.md
@@ -0,0 +1,36 @@
+2966\. Divide Array Into Arrays With Max Difference
+
+Medium
+
+You are given an integer array `nums` of size `n` and a positive integer `k`.
+
+Divide the array into one or more arrays of size `3` satisfying the following conditions:
+
+* **Each** element of `nums` should be in **exactly** one array.
+* The difference between **any** two elements in one array is less than or equal to `k`.
+
+Return _a_ **2D** _array containing all the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return **any** of them._
+
+**Example 1:**
+
+**Input:** nums = [1,3,4,8,7,9,3,5,1], k = 2
+
+**Output:** [[1,1,3],[3,4,5],[7,8,9]]
+
+**Explanation:** We can divide the array into the following arrays: [1,1,3], [3,4,5] and [7,8,9]. The difference between any two elements in each array is less than or equal to 2. Note that the order of elements is not important.
+
+**Example 2:**
+
+**Input:** nums = [1,3,3,2,7,3], k = 3
+
+**Output:** []
+
+**Explanation:** It is not possible to divide the array satisfying all the conditions.
+
+**Constraints:**
+
+* `n == nums.length`
+* 1 <= n <= 105
+* `n` is a multiple of `3`.
+* 1 <= nums[i] <= 105
+* 1 <= k <= 105
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/Solution.java b/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/Solution.java
new file mode 100644
index 000000000..bd096655c
--- /dev/null
+++ b/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/Solution.java
@@ -0,0 +1,48 @@
+package g2901_3000.s2967_minimum_cost_to_make_array_equalindromic;
+
+// #Medium #Array #Math #Sorting #Greedy #2024_01_16_Time_15_ms_(97.78%)_Space_56.5_MB_(20.47%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public long minimumCost(int[] nums) {
+ Arrays.sort(nums);
+ int len = nums.length;
+ int m = len % 2 != 0 ? len / 2 : len / 2 - 1;
+ int previousPalindrome = getPreviousPalindrome(nums[m]);
+ int nextPalindrome = getNextPalindrome(nums[m]);
+ long ans1 = 0;
+ long ans2 = 0;
+ for (int num : nums) {
+ ans1 += Math.abs(previousPalindrome - num);
+ ans2 += Math.abs(nextPalindrome - num);
+ }
+ return Math.min(ans1, ans2);
+ }
+
+ private int getPreviousPalindrome(int num) {
+ int previousPalindrome = num;
+ while (!isPalindrome(previousPalindrome)) {
+ previousPalindrome--;
+ }
+ return previousPalindrome;
+ }
+
+ private int getNextPalindrome(int num) {
+ int nextPalindrome = num;
+ while (!isPalindrome(nextPalindrome)) {
+ nextPalindrome++;
+ }
+ return nextPalindrome;
+ }
+
+ private boolean isPalindrome(int num) {
+ int copyNum = num;
+ int reverseNum = 0;
+ while (num > 0) {
+ reverseNum = reverseNum * 10 + num % 10;
+ num /= 10;
+ }
+ return copyNum == reverseNum;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/readme.md b/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/readme.md
new file mode 100644
index 000000000..56ce139e3
--- /dev/null
+++ b/src/main/java/g2901_3000/s2967_minimum_cost_to_make_array_equalindromic/readme.md
@@ -0,0 +1,46 @@
+2967\. Minimum Cost to Make Array Equalindromic
+
+Medium
+
+You are given a **0-indexed** integer array `nums` having length `n`.
+
+You are allowed to perform a special move **any** number of times (**including zero**) on `nums`. In one **special** **move** you perform the following steps **in order**:
+
+* Choose an index `i` in the range `[0, n - 1]`, and a **positive** integer `x`.
+* Add `|nums[i] - x|` to the total cost.
+* Change the value of `nums[i]` to `x`.
+
+A **palindromic number** is a positive integer that remains the same when its digits are reversed. For example, `121`, `2552` and `65756` are palindromic numbers whereas `24`, `46`, `235` are not palindromic numbers.
+
+An array is considered **equalindromic** if all the elements in the array are equal to an integer `y`, where `y` is a **palindromic number** less than 109.
+
+Return _an integer denoting the **minimum** possible total cost to make_ `nums` _**equalindromic** by performing any number of special moves._
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 6
+
+**Explanation:** We can make the array equalindromic by changing all elements to 3 which is a palindromic number. The cost of changing the array to [3,3,3,3,3] using 4 special moves is given by |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6. It can be shown that changing all elements to any palindromic number other than 3 cannot be achieved at a lower cost.
+
+**Example 2:**
+
+**Input:** nums = [10,12,13,14,15]
+
+**Output:** 11
+
+**Explanation:** We can make the array equalindromic by changing all elements to 11 which is a palindromic number. The cost of changing the array to [11,11,11,11,11] using 5 special moves is given by |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11. It can be shown that changing all elements to any palindromic number other than 11 cannot be achieved at a lower cost.
+
+**Example 3:**
+
+**Input:** nums = [22,33,22,33,22]
+
+**Output:** 22
+
+**Explanation:** We can make the array equalindromic by changing all elements to 22 which is a palindromic number. The cost of changing the array to [22,22,22,22,22] using 2 special moves is given by |33 - 22| + |33 - 22| = 22. It can be shown that changing all elements to any palindromic number other than 22 cannot be achieved at a lower cost.
+
+**Constraints:**
+
+* 1 <= n <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/Solution.java b/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/Solution.java
new file mode 100644
index 000000000..90a28e1bf
--- /dev/null
+++ b/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/Solution.java
@@ -0,0 +1,38 @@
+package g2901_3000.s2968_apply_operations_to_maximize_frequency_score;
+
+// #Hard #Array #Sorting #Binary_Search #Prefix_Sum #Sliding_Window
+// #2024_01_16_Time_27_ms_(78.37%)_Space_55.8_MB_(53.47%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int maxFrequencyScore(int[] nums, long k) {
+ Arrays.sort(nums);
+ int n = nums.length;
+ long[] prefixSum = new long[n + 1];
+ for (int i = 0; i < n; i++) {
+ prefixSum[i + 1] = prefixSum[i] + nums[i];
+ }
+ int start = 0;
+ int end = 1;
+ int out = 1;
+ while (end < n) {
+ end++;
+ int mid = (start + end) / 2;
+ long target = nums[mid];
+ long cost =
+ (target * (mid - start) - (prefixSum[mid] - prefixSum[start]))
+ + (prefixSum[end] - prefixSum[mid] - target * (end - mid));
+ while (start < end && cost > k) {
+ start++;
+ mid = (start + end) / 2;
+ target = nums[mid];
+ cost =
+ (target * (mid - start) - (prefixSum[mid] - prefixSum[start]))
+ + (prefixSum[end] - prefixSum[mid] - target * (end - mid));
+ }
+ out = Math.max(out, end - start);
+ }
+ return out;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/readme.md b/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/readme.md
new file mode 100644
index 000000000..4efd15029
--- /dev/null
+++ b/src/main/java/g2901_3000/s2968_apply_operations_to_maximize_frequency_score/readme.md
@@ -0,0 +1,42 @@
+2968\. Apply Operations to Maximize Frequency Score
+
+Hard
+
+You are given a **0-indexed** integer array `nums` and an integer `k`.
+
+You can perform the following operation on the array **at most** `k` times:
+
+* Choose any index `i` from the array and **increase** or **decrease** `nums[i]` by `1`.
+
+The score of the final array is the **frequency** of the most frequent element in the array.
+
+Return _the **maximum** score you can achieve_.
+
+The frequency of an element is the number of occurences of that element in the array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,6,4], k = 3
+
+**Output:** 3
+
+**Explanation:** We can do the following operations on the array:
+- Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].
+- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].
+- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].
+
+The element 2 is the most frequent in the final array so our score is 3. It can be shown that we cannot achieve a better score.
+
+**Example 2:**
+
+**Input:** nums = [1,4,4,2,4], k = 0
+
+**Output:** 3
+
+**Explanation:** We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 109
+* 0 <= k <= 1014
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/Solution.java b/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/Solution.java
new file mode 100644
index 000000000..02363bb00
--- /dev/null
+++ b/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/Solution.java
@@ -0,0 +1,27 @@
+package g2901_3000.s2970_count_the_number_of_incremovable_subarrays_i;
+
+// #Easy #Array #Binary_Search #Two_Pointers #Enumeration
+// #2024_01_16_Time_0_ms_(100.00%)_Space_42.9_MB_(87.73%)
+
+public class Solution {
+ public int incremovableSubarrayCount(int[] nums) {
+ int n = nums.length;
+ int res = 0;
+ int left = Integer.MIN_VALUE;
+ for (int i = 0; i < n; i++) {
+ int right = Integer.MAX_VALUE;
+ for (int j = n - 1; i <= j; j--) {
+ res++;
+ if (left >= nums[j] || nums[j] >= right) {
+ break;
+ }
+ right = nums[j];
+ }
+ if (left >= nums[i]) {
+ break;
+ }
+ left = nums[i];
+ }
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/readme.md b/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/readme.md
new file mode 100644
index 000000000..b245f85cc
--- /dev/null
+++ b/src/main/java/g2901_3000/s2970_count_the_number_of_incremovable_subarrays_i/readme.md
@@ -0,0 +1,42 @@
+2970\. Count the Number of Incremovable Subarrays I
+
+Easy
+
+You are given a **0-indexed** array of **positive** integers `nums`.
+
+A subarray of `nums` is called **incremovable** if `nums` becomes **strictly increasing** on removing the subarray. For example, the subarray `[3, 4]` is an incremovable subarray of `[5, 3, 4, 6, 7]` because removing this subarray changes the array `[5, 3, 4, 6, 7]` to `[5, 6, 7]` which is strictly increasing.
+
+Return _the total number of **incremovable** subarrays of_ `nums`.
+
+**Note** that an empty array is considered strictly increasing.
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4]
+
+**Output:** 10
+
+**Explanation:** The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
+
+**Example 2:**
+
+**Input:** nums = [6,5,7,8]
+
+**Output:** 7
+
+**Explanation:** The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8]. It can be shown that there are only 7 incremovable subarrays in nums.
+
+**Example 3:**
+
+**Input:** nums = [8,7,6,6]
+
+**Output:** 3
+
+**Explanation:** The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
+
+**Constraints:**
+
+* `1 <= nums.length <= 50`
+* `1 <= nums[i] <= 50`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/Solution.java b/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/Solution.java
new file mode 100644
index 000000000..3580722be
--- /dev/null
+++ b/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/Solution.java
@@ -0,0 +1,27 @@
+package g2901_3000.s2971_find_polygon_with_the_largest_perimeter;
+
+// #Medium #Array #Sorting #Greedy #Prefix_Sum
+// #2024_01_16_Time_21_ms_(98.77%)_Space_60.9_MB_(34.24%)
+
+import java.util.Collections;
+import java.util.PriorityQueue;
+
+public class Solution {
+ public long largestPerimeter(int[] nums) {
+ long sum = 0L;
+ PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder());
+ for (int i : nums) {
+ pq.add((long) i);
+ sum = (sum + i);
+ }
+ while (pq.size() >= 3) {
+ long curr = pq.poll();
+ if (sum - curr > curr) {
+ return sum;
+ } else {
+ sum = sum - curr;
+ }
+ }
+ return -1;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/readme.md b/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/readme.md
new file mode 100644
index 000000000..8ca22f275
--- /dev/null
+++ b/src/main/java/g2901_3000/s2971_find_polygon_with_the_largest_perimeter/readme.md
@@ -0,0 +1,42 @@
+2971\. Find Polygon With the Largest Perimeter
+
+Medium
+
+You are given an array of **positive** integers `nums` of length `n`.
+
+A **polygon** is a closed plane figure that has at least `3` sides. The **longest side** of a polygon is **smaller** than the sum of its other sides.
+
+Conversely, if you have `k` (`k >= 3`) **positive** real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak **and** a1 + a2 + a3 + ... + ak-1 > ak, then there **always** exists a polygon with `k` sides whose lengths are a1, a2, a3, ..., ak.
+
+The **perimeter** of a polygon is the sum of lengths of its sides.
+
+Return _the **largest** possible **perimeter** of a **polygon** whose sides can be formed from_ `nums`, _or_ `-1` _if it is not possible to create a polygon_.
+
+**Example 1:**
+
+**Input:** nums = [5,5,5]
+
+**Output:** 15
+
+**Explanation:** The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.
+
+**Example 2:**
+
+**Input:** nums = [1,12,1,2,5,50,3]
+
+**Output:** 12
+
+**Explanation:** The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12. We cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them. It can be shown that the largest possible perimeter is 12.
+
+**Example 3:**
+
+**Input:** nums = [5,5,50]
+
+**Output:** -1
+
+**Explanation:** There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.
+
+**Constraints:**
+
+* 3 <= n <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/Solution.java b/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/Solution.java
new file mode 100644
index 000000000..4e2ae83b6
--- /dev/null
+++ b/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/Solution.java
@@ -0,0 +1,26 @@
+package g2901_3000.s2972_count_the_number_of_incremovable_subarrays_ii;
+
+// #Hard #Array #Binary_Search #Two_Pointers #2024_01_16_Time_1_ms_(100.00%)_Space_57.8_MB_(66.47%)
+
+public class Solution {
+ public long incremovableSubarrayCount(int[] nums) {
+ long ans;
+ int n = nums.length;
+ int l = 0;
+ int r = n - 1;
+ while (l + 1 < n && nums[l] < nums[l + 1]) {
+ l++;
+ }
+ while (r > 0 && nums[r - 1] < nums[r]) {
+ r--;
+ }
+ ans = (l == n - 1) ? 0 : 1 + (n - r);
+ for (int i = 0; i <= l; i++) {
+ while (r < n && nums[r] <= nums[i]) {
+ r++;
+ }
+ ans += n - r + 1;
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/readme.md b/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/readme.md
new file mode 100644
index 000000000..488cb0c46
--- /dev/null
+++ b/src/main/java/g2901_3000/s2972_count_the_number_of_incremovable_subarrays_ii/readme.md
@@ -0,0 +1,42 @@
+2972\. Count the Number of Incremovable Subarrays II
+
+Hard
+
+You are given a **0-indexed** array of **positive** integers `nums`.
+
+A subarray of `nums` is called **incremovable** if `nums` becomes **strictly increasing** on removing the subarray. For example, the subarray `[3, 4]` is an incremovable subarray of `[5, 3, 4, 6, 7]` because removing this subarray changes the array `[5, 3, 4, 6, 7]` to `[5, 6, 7]` which is strictly increasing.
+
+Return _the total number of **incremovable** subarrays of_ `nums`.
+
+**Note** that an empty array is considered strictly increasing.
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4]
+
+**Output:** 10
+
+**Explanation:** The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
+
+**Example 2:**
+
+**Input:** nums = [6,5,7,8]
+
+**Output:** 7
+
+**Explanation:** The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8]. It can be shown that there are only 7 incremovable subarrays in nums.
+
+**Example 3:**
+
+**Input:** nums = [8,7,6,6]
+
+**Output:** 3
+
+**Explanation:** The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/Solution.java b/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/Solution.java
new file mode 100644
index 000000000..d122e3b14
--- /dev/null
+++ b/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/Solution.java
@@ -0,0 +1,85 @@
+package g2901_3000.s2973_find_number_of_coins_to_place_in_tree_nodes;
+
+// #Hard #Dynamic_Programming #Sorting #Depth_First_Search #Tree #Heap_Priority_Queue
+// #2024_01_16_Time_93_ms_(72.11%)_Space_63.4_MB_(33.51%)
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.PriorityQueue;
+
+public class Solution {
+ private long[] result;
+
+ public long[] placedCoins(int[][] edges, int[] cost) {
+ int n = cost.length;
+ List> g = new ArrayList<>();
+ for (int i = 0; i < n; i++) {
+ g.add(new ArrayList<>());
+ }
+ for (int[] e : edges) {
+ g.get(e[0]).add(e[1]);
+ g.get(e[1]).add(e[0]);
+ }
+ result = new long[n];
+ dp(g, cost, 0, -1);
+ return result;
+ }
+
+ private static class PQX {
+ PriorityQueue min;
+ PriorityQueue max;
+ }
+
+ private PQX dp(List> g, int[] cost, int i, int p) {
+ if (i >= g.size()) {
+ PQX pqx = new PQX();
+ pqx.max = new PriorityQueue<>((a, b) -> b - a);
+ pqx.min = new PriorityQueue<>(Comparator.comparingInt(a -> a));
+ return pqx;
+ }
+ List next = g.get(i);
+ PriorityQueue pq = new PriorityQueue<>((a, b) -> b - a);
+ PriorityQueue pq2 = new PriorityQueue<>(Comparator.comparingInt(a -> a));
+ if (cost[i] > 0) {
+ pq.add(cost[i]);
+ } else {
+ pq2.add(cost[i]);
+ }
+ for (int ne : next) {
+ if (ne != p) {
+ PQX r = dp(g, cost, ne, i);
+ while (!r.min.isEmpty()) {
+ int a = r.min.poll();
+ pq2.add(a);
+ }
+ while (!r.max.isEmpty()) {
+ int a = r.max.poll();
+ pq.add(a);
+ }
+ }
+ }
+ if (pq.size() + pq2.size() < 3) {
+ result[i] = 1;
+ } else {
+ int a = !pq.isEmpty() ? pq.poll() : 0;
+ int b = !pq.isEmpty() ? pq.poll() : 0;
+ int c = !pq.isEmpty() ? pq.poll() : 0;
+ int aa = !pq2.isEmpty() ? pq2.poll() : 0;
+ int bb = !pq2.isEmpty() ? pq2.poll() : 0;
+ result[i] = Math.max(0, (long) a * b * c);
+ result[i] = Math.max(result[i], Math.max(0, (long) a * aa * bb));
+ pq = new PriorityQueue<>((x, y) -> y - x);
+ pq.add(a);
+ pq.add(b);
+ pq.add(c);
+ pq2 = new PriorityQueue<>(Comparator.comparingInt(x -> x));
+ pq2.add(aa);
+ pq2.add(bb);
+ }
+ PQX pqx = new PQX();
+ pqx.min = pq2;
+ pqx.max = pq;
+ return pqx;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/readme.md b/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/readme.md
new file mode 100644
index 000000000..383039b26
--- /dev/null
+++ b/src/main/java/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/readme.md
@@ -0,0 +1,54 @@
+2973\. Find Number of Coins to Place in Tree Nodes
+
+Hard
+
+You are given an **undirected** tree with `n` nodes labeled from `0` to `n - 1`, and rooted at node `0`. You are given a 2D integer array `edges` of length `n - 1`, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
+
+You are also given a **0-indexed** integer array `cost` of length `n`, where `cost[i]` is the **cost** assigned to the ith node.
+
+You need to place some coins on every node of the tree. The number of coins to be placed at node `i` can be calculated as:
+
+* If size of the subtree of node `i` is less than `3`, place `1` coin.
+* Otherwise, place an amount of coins equal to the **maximum** product of cost values assigned to `3` distinct nodes in the subtree of node `i`. If this product is **negative**, place `0` coins.
+
+Return _an array_ `coin` _of size_ `n` _such that_ `coin[i]` _is the number of coins placed at node_ `i`_._
+
+**Example 1:**
+
+
+
+**Input:** edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]
+
+**Output:** [120,1,1,1,1,1]
+
+**Explanation:** For node 0 place 6 \* 5 \* 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.
+
+**Example 2:**
+
+
+
+**Input:** edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]
+
+**Output:** [280,140,32,1,1,1,1,1,1]
+
+**Explanation:** The coins placed on each node are: - Place 8 \* 7 \* 5 = 280 coins on node 0. - Place 7 \* 5 \* 4 = 140 coins on node 1. - Place 8 \* 2 \* 2 = 32 coins on node 2. - All other nodes are leaves with subtree of size 1, place 1 coin on each of them.
+
+**Example 3:**
+
+
+
+**Input:** edges = [[0,1],[0,2]], cost = [1,2,-2]
+
+**Output:** [0,1,1]
+
+**Explanation:** Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 \* 1 \* -2 = -4. Hence place 0 coins on node 0.
+
+**Constraints:**
+
+* 2 <= n <= 2 * 104
+* `edges.length == n - 1`
+* `edges[i].length == 2`
+* 0 <= ai, bi < n
+* `cost.length == n`
+* 1 <= |cost[i]| <= 104
+* The input is generated such that `edges` represents a valid tree.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2974_minimum_number_game/Solution.java b/src/main/java/g2901_3000/s2974_minimum_number_game/Solution.java
new file mode 100644
index 000000000..024cffaff
--- /dev/null
+++ b/src/main/java/g2901_3000/s2974_minimum_number_game/Solution.java
@@ -0,0 +1,18 @@
+package g2901_3000.s2974_minimum_number_game;
+
+// #Easy #Array #Sorting #Heap_Priority_Queue #Simulation
+// #2024_01_18_Time_2_ms_(98.98%)_Space_45.1_MB_(23.84%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int[] numberGame(int[] nums) {
+ Arrays.sort(nums);
+ int[] n = new int[nums.length];
+ for (int i = 0, j = 1; i < nums.length; i += 2, j += 2) {
+ n[i] = nums[j];
+ n[j] = nums[i];
+ }
+ return n;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2974_minimum_number_game/readme.md b/src/main/java/g2901_3000/s2974_minimum_number_game/readme.md
new file mode 100644
index 000000000..680ed76dc
--- /dev/null
+++ b/src/main/java/g2901_3000/s2974_minimum_number_game/readme.md
@@ -0,0 +1,33 @@
+2974\. Minimum Number Game
+
+Easy
+
+You are given a **0-indexed** integer array `nums` of **even** length and there is also an empty array `arr`. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:
+
+* Every round, first Alice will remove the **minimum** element from `nums`, and then Bob does the same.
+* Now, first Bob will append the removed element in the array `arr`, and then Alice does the same.
+* The game continues until `nums` becomes empty.
+
+Return _the resulting array_ `arr`.
+
+**Example 1:**
+
+**Input:** nums = [5,4,2,3]
+
+**Output:** [3,2,5,4]
+
+**Explanation:** In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2]. At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].
+
+**Example 2:**
+
+**Input:** nums = [2,5]
+
+**Output:** [5,2]
+
+**Explanation:** In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].
+
+**Constraints:**
+
+* `1 <= nums.length <= 100`
+* `1 <= nums[i] <= 100`
+* `nums.length % 2 == 0`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/Solution.java b/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/Solution.java
new file mode 100644
index 000000000..a747c397a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/Solution.java
@@ -0,0 +1,40 @@
+package g2901_3000.s2975_maximum_square_area_by_removing_fences_from_a_field;
+
+// #Medium #Array #Hash_Table #Enumeration #2024_01_18_Time_413_ms_(78.25%)_Space_60.2_MB_(79.94%)
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Solution {
+ public int maximizeSquareArea(
+ final int m, final int n, final int[] hFences, final int[] vFences) {
+ int[] hFencesWithBorder = new int[hFences.length + 2];
+ System.arraycopy(hFences, 0, hFencesWithBorder, 0, hFences.length);
+ hFencesWithBorder[hFences.length] = 1;
+ hFencesWithBorder[hFences.length + 1] = m;
+ Arrays.sort(hFencesWithBorder);
+ Set edgeSet = new HashSet<>();
+ for (int i = 0; i < hFencesWithBorder.length; i += 1) {
+ for (int j = i + 1; j < hFencesWithBorder.length; j += 1) {
+ edgeSet.add(hFencesWithBorder[j] - hFencesWithBorder[i]);
+ }
+ }
+ int maxEdge = -1;
+ int[] vFencesWithBorder = new int[vFences.length + 2];
+ System.arraycopy(vFences, 0, vFencesWithBorder, 0, vFences.length);
+ vFencesWithBorder[vFences.length] = 1;
+ vFencesWithBorder[vFences.length + 1] = n;
+ Arrays.sort(vFencesWithBorder);
+ for (int i = 0; i < vFencesWithBorder.length; i += 1) {
+ for (int j = i + 1; j < vFencesWithBorder.length; j += 1) {
+ int curEdge = vFencesWithBorder[j] - vFencesWithBorder[i];
+ if (edgeSet.contains(curEdge) && curEdge > maxEdge) {
+ maxEdge = curEdge;
+ }
+ }
+ }
+ int mod = (int) 1e9 + 7;
+ return (maxEdge != -1) ? (int) ((long) maxEdge * maxEdge % mod) : -1;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/readme.md b/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/readme.md
new file mode 100644
index 000000000..afa8aa2af
--- /dev/null
+++ b/src/main/java/g2901_3000/s2975_maximum_square_area_by_removing_fences_from_a_field/readme.md
@@ -0,0 +1,41 @@
+2975\. Maximum Square Area by Removing Fences From a Field
+
+Medium
+
+There is a large `(m - 1) x (n - 1)` rectangular field with corners at `(1, 1)` and `(m, n)` containing some horizontal and vertical fences given in arrays `hFences` and `vFences` respectively.
+
+Horizontal fences are from the coordinates `(hFences[i], 1)` to `(hFences[i], n)` and vertical fences are from the coordinates `(1, vFences[i])` to `(m, vFences[i])`.
+
+Return _the **maximum** area of a **square** field that can be formed by **removing** some fences (**possibly none**) or_ `-1` _if it is impossible to make a square field_.
+
+Since the answer may be large, return it **modulo** 109 + 7.
+
+**Note:** The field is surrounded by two horizontal fences from the coordinates `(1, 1)` to `(1, n)` and `(m, 1)` to `(m, n)` and two vertical fences from the coordinates `(1, 1)` to `(m, 1)` and `(1, n)` to `(m, n)`. These fences **cannot** be removed.
+
+**Example 1:**
+
+
+
+**Input:** m = 4, n = 3, hFences = [2,3], vFences = [2]
+
+**Output:** 4
+
+**Explanation:** Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.
+
+**Example 2:**
+
+
+
+**Input:** m = 6, n = 7, hFences = [2], vFences = [4]
+
+**Output:** -1
+
+**Explanation:** It can be proved that there is no way to create a square field by removing fences.
+
+**Constraints:**
+
+* 3 <= m, n <= 109
+* `1 <= hFences.length, vFences.length <= 600`
+* `1 < hFences[i] < m`
+* `1 < vFences[i] < n`
+* `hFences` and `vFences` are unique.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/Solution.java b/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/Solution.java
new file mode 100644
index 000000000..4f2aa5f11
--- /dev/null
+++ b/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/Solution.java
@@ -0,0 +1,61 @@
+package g2901_3000.s2976_minimum_cost_to_convert_string_i;
+
+// #Medium #Array #String #Graph #Shortest_Path
+// #2024_01_18_Time_18_ms_(92.47%)_Space_45.9_MB_(31.83%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public long minimumCost(
+ String inputText,
+ String desiredText,
+ char[] fromLetters,
+ char[] toLetters,
+ int[] transformationCost) {
+ int alphabetSize = 26;
+ int[][] transformationMatrix = new int[alphabetSize][alphabetSize];
+ for (int idx = 0; idx < alphabetSize; idx++) {
+ Arrays.fill(transformationMatrix[idx], Integer.MAX_VALUE);
+ transformationMatrix[idx][idx] = 0;
+ }
+ int i = 0;
+ while (i < fromLetters.length) {
+ int origChar = fromLetters[i] - 'a';
+ int newChar = toLetters[i] - 'a';
+ int changeCost = transformationCost[i];
+ transformationMatrix[origChar][newChar] =
+ Math.min(transformationMatrix[origChar][newChar], changeCost);
+ i++;
+ }
+ int k = 0;
+ do {
+ for (int row = 0; row < alphabetSize; row++) {
+ for (int col = 0; col < alphabetSize; col++) {
+ if (transformationMatrix[row][k] != Integer.MAX_VALUE
+ && transformationMatrix[k][col] != Integer.MAX_VALUE) {
+ transformationMatrix[row][col] =
+ Math.min(
+ transformationMatrix[row][col],
+ transformationMatrix[row][k]
+ + transformationMatrix[k][col]);
+ }
+ }
+ }
+ k++;
+ } while (k < alphabetSize);
+ long totalCost = 0;
+ for (int pos = 0; pos < inputText.length(); pos++) {
+ int startChar = inputText.charAt(pos) - 'a';
+ int endChar = desiredText.charAt(pos) - 'a';
+ if (startChar == endChar) {
+ continue;
+ }
+ if (transformationMatrix[startChar][endChar] == Integer.MAX_VALUE) {
+ return -1;
+ } else {
+ totalCost += transformationMatrix[startChar][endChar];
+ }
+ }
+ return totalCost;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/readme.md b/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/readme.md
new file mode 100644
index 000000000..14733dc48
--- /dev/null
+++ b/src/main/java/g2901_3000/s2976_minimum_cost_to_convert_string_i/readme.md
@@ -0,0 +1,52 @@
+2976\. Minimum Cost to Convert String I
+
+Medium
+
+You are given two **0-indexed** strings `source` and `target`, both of length `n` and consisting of **lowercase** English letters. You are also given two **0-indexed** character arrays `original` and `changed`, and an integer array `cost`, where `cost[i]` represents the cost of changing the character `original[i]` to the character `changed[i]`.
+
+You start with the string `source`. In one operation, you can pick a character `x` from the string and change it to the character `y` at a cost of `z` **if** there exists **any** index `j` such that `cost[j] == z`, `original[j] == x`, and `changed[j] == y`.
+
+Return _the **minimum** cost to convert the string_ `source` _to the string_ `target` _using **any** number of operations. If it is impossible to convert_ `source` _to_ `target`, _return_ `-1`.
+
+**Note** that there may exist indices `i`, `j` such that `original[j] == original[i]` and `changed[j] == changed[i]`.
+
+**Example 1:**
+
+**Input:** source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+
+**Output:** 28
+
+**Explanation:** To convert the string "abcd" to string "acbe":
+- Change value at index 1 from 'b' to 'c' at a cost of 5.
+- Change value at index 2 from 'c' to 'e' at a cost of 1.
+- Change value at index 2 from 'e' to 'b' at a cost of 2.
+- Change value at index 3 from 'd' to 'e' at a cost of 20.
+
+The total cost incurred is 5 + 1 + 2 + 20 = 28.
+
+It can be shown that this is the minimum possible cost.
+
+**Example 2:**
+
+**Input:** source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2]
+
+**Output:** 12
+
+**Explanation:** To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.
+
+**Example 3:**
+
+**Input:** source = "abcd", target = "abce", original = ["a"], changed = ["e"], cost = [10000]
+
+**Output:** -1
+
+**Explanation:** It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.
+
+**Constraints:**
+
+* 1 <= source.length == target.length <= 105
+* `source`, `target` consist of lowercase English letters.
+* `1 <= cost.length == original.length == changed.length <= 2000`
+* `original[i]`, `changed[i]` are lowercase English letters.
+* 1 <= cost[i] <= 106
+* `original[i] != changed[i]`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/Solution.java b/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/Solution.java
new file mode 100644
index 000000000..fece22c8a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/Solution.java
@@ -0,0 +1,71 @@
+package g2901_3000.s2977_minimum_cost_to_convert_string_ii;
+
+// #Hard #Array #String #Dynamic_Programming #Graph #Trie #Shortest_Path
+// #2024_01_18_Time_167_ms_(62.13%)_Space_45.8_MB_(48.88%)
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+
+public class Solution {
+ public long minimumCost(
+ String source, String target, String[] original, String[] changed, int[] cost) {
+ HashMap index = new HashMap<>();
+ for (String o : original) {
+ if (!index.containsKey(o)) {
+ index.put(o, index.size());
+ }
+ }
+ for (String c : changed) {
+ if (!index.containsKey(c)) {
+ index.put(c, index.size());
+ }
+ }
+ long[][] dis = new long[index.size()][index.size()];
+ for (int i = 0; i < dis.length; i++) {
+ Arrays.fill(dis[i], Long.MAX_VALUE);
+ dis[i][i] = 0;
+ }
+ for (int i = 0; i < cost.length; i++) {
+ dis[index.get(original[i])][index.get(changed[i])] =
+ Math.min(dis[index.get(original[i])][index.get(changed[i])], cost[i]);
+ }
+ for (int k = 0; k < dis.length; k++) {
+ for (int i = 0; i < dis.length; i++) {
+ if (dis[i][k] < Long.MAX_VALUE) {
+ for (int j = 0; j < dis.length; j++) {
+ if (dis[k][j] < Long.MAX_VALUE) {
+ dis[i][j] = Math.min(dis[i][j], dis[i][k] + dis[k][j]);
+ }
+ }
+ }
+ }
+ }
+ HashSet set = new HashSet<>();
+ for (String o : original) {
+ set.add(o.length());
+ }
+ long[] dp = new long[target.length() + 1];
+ Arrays.fill(dp, Long.MAX_VALUE);
+ dp[0] = 0L;
+ for (int i = 0; i < target.length(); i++) {
+ if (dp[i] == Long.MAX_VALUE) {
+ continue;
+ }
+ if (target.charAt(i) == source.charAt(i)) {
+ dp[i + 1] = Math.min(dp[i + 1], dp[i]);
+ }
+ for (int t : set) {
+ if (i + t >= dp.length) {
+ continue;
+ }
+ int c1 = index.getOrDefault(source.substring(i, i + t), -1);
+ int c2 = index.getOrDefault(target.substring(i, i + t), -1);
+ if (c1 >= 0 && c2 >= 0 && dis[c1][c2] < Long.MAX_VALUE) {
+ dp[i + t] = Math.min(dp[i + t], dp[i] + dis[c1][c2]);
+ }
+ }
+ }
+ return dp[dp.length - 1] == Long.MAX_VALUE ? -1L : dp[dp.length - 1];
+ }
+}
diff --git a/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/readme.md b/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/readme.md
new file mode 100644
index 000000000..3036363e2
--- /dev/null
+++ b/src/main/java/g2901_3000/s2977_minimum_cost_to_convert_string_ii/readme.md
@@ -0,0 +1,67 @@
+2977\. Minimum Cost to Convert String II
+
+Hard
+
+You are given two **0-indexed** strings `source` and `target`, both of length `n` and consisting of **lowercase** English characters. You are also given two **0-indexed** string arrays `original` and `changed`, and an integer array `cost`, where `cost[i]` represents the cost of converting the string `original[i]` to the string `changed[i]`.
+
+You start with the string `source`. In one operation, you can pick a **substring** `x` from the string, and change it to `y` at a cost of `z` **if** there exists **any** index `j` such that `cost[j] == z`, `original[j] == x`, and `changed[j] == y`. You are allowed to do **any** number of operations, but any pair of operations must satisfy **either** of these two conditions:
+
+* The substrings picked in the operations are `source[a..b]` and `source[c..d]` with either `b < c` **or** `d < a`. In other words, the indices picked in both operations are **disjoint**.
+* The substrings picked in the operations are `source[a..b]` and `source[c..d]` with `a == c` **and** `b == d`. In other words, the indices picked in both operations are **identical**.
+
+Return _the **minimum** cost to convert the string_ `source` _to the string_ `target` _using **any** number of operations_. _If it is impossible to convert_ `source` _to_ `target`, _return_ `-1`.
+
+**Note** that there may exist indices `i`, `j` such that `original[j] == original[i]` and `changed[j] == changed[i]`.
+
+**Example 1:**
+
+**Input:** source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+
+**Output:** 28
+
+**Explanation:** To convert "abcd" to "acbe", do the following operations:
+- Change substring source[1..1] from "b" to "c" at a cost of 5.
+- Change substring source[2..2] from "c" to "e" at a cost of 1.
+- Change substring source[2..2] from "e" to "b" at a cost of 2.
+- Change substring source[3..3] from "d" to "e" at a cost of 20.
+
+The total cost incurred is 5 + 1 + 2 + 20 = 28.
+
+It can be shown that this is the minimum possible cost.
+
+**Example 2:**
+
+**Input:** source = "abcdefgh", target = "acdeeghh", original = ["bcd","fgh","thh"], changed = ["cde","thh","ghh"], cost = [1,3,5]
+
+**Output:** 9
+
+**Explanation:** To convert "abcdefgh" to "acdeeghh", do the following operations:
+- Change substring source[1..3] from "bcd" to "cde" at a cost of 1.
+- Change substring source[5..7] from "fgh" to "thh" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.
+- Change substring source[5..7] from "thh" to "ghh" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.
+
+The total cost incurred is 1 + 3 + 5 = 9.
+
+It can be shown that this is the minimum possible cost.
+
+**Example 3:**
+
+**Input:** source = "abcdefgh", target = "addddddd", original = ["bcd","defgh"], changed = ["ddd","ddddd"], cost = [100,1578]
+
+**Output:** -1
+
+**Explanation:** It is impossible to convert "abcdefgh" to "addddddd".
+
+If you select substring source[1..3] as the first operation to change "abcdefgh" to "adddefgh", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.
+
+If you select substring source[3..7] as the first operation to change "abcdefgh" to "abcddddd", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.
+
+**Constraints:**
+
+* `1 <= source.length == target.length <= 1000`
+* `source`, `target` consist only of lowercase English characters.
+* `1 <= cost.length == original.length == changed.length <= 100`
+* `1 <= original[i].length == changed[i].length <= source.length`
+* `original[i]`, `changed[i]` consist only of lowercase English characters.
+* `original[i] != changed[i]`
+* 1 <= cost[i] <= 106
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/Solution.java b/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/Solution.java
new file mode 100644
index 000000000..62a3be85d
--- /dev/null
+++ b/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/Solution.java
@@ -0,0 +1,18 @@
+package g2901_3000.s2980_check_if_bitwise_or_has_trailing_zeros;
+
+// #Easy #Array #Bit_Manipulation #2024_01_18_Time_1_ms_(88.11%)_Space_44.2_MB_(64.58%)
+
+public class Solution {
+ public boolean hasTrailingZeros(int[] nums) {
+ int hasTrailingZero = 0;
+ for (int num : nums) {
+ if ((num & 1) == 0) {
+ hasTrailingZero++;
+ if (hasTrailingZero > 1) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/readme.md b/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/readme.md
new file mode 100644
index 000000000..16b088649
--- /dev/null
+++ b/src/main/java/g2901_3000/s2980_check_if_bitwise_or_has_trailing_zeros/readme.md
@@ -0,0 +1,40 @@
+2980\. Check if Bitwise OR Has Trailing Zeros
+
+Easy
+
+You are given an array of **positive** integers `nums`.
+
+You have to check if it is possible to select **two or more** elements in the array such that the bitwise `OR` of the selected elements has **at least** one trailing zero in its binary representation.
+
+For example, the binary representation of `5`, which is `"101"`, does not have any trailing zeros, whereas the binary representation of `4`, which is `"100"`, has two trailing zeros.
+
+Return `true` _if it is possible to select two or more elements whose bitwise_ `OR` _has trailing zeros, return_ `false` _otherwise_.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** true
+
+**Explanation:** If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero.
+
+**Example 2:**
+
+**Input:** nums = [2,4,8,16]
+
+**Output:** true
+
+**Explanation:** If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero. Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).
+
+**Example 3:**
+
+**Input:** nums = [1,3,5,7,9]
+
+**Output:** false
+
+**Explanation:** There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.
+
+**Constraints:**
+
+* `2 <= nums.length <= 100`
+* `1 <= nums[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/Solution.java b/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/Solution.java
new file mode 100644
index 000000000..6bc2e498a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/Solution.java
@@ -0,0 +1,60 @@
+package g2901_3000.s2981_find_longest_special_substring_that_occurs_thrice_i;
+
+// #Medium #String #Hash_Table #Binary_Search #Counting #Sliding_Window
+// #2024_01_18_Time_6_ms_(89.21%)_Space_44.5_MB_(72.61%)
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class Solution {
+ public int maximumLength(String s) {
+ List> buckets = new ArrayList<>();
+ for (int i = 0; i < 26; i++) {
+ buckets.add(new ArrayList<>());
+ }
+ int cur = 1;
+ for (int i = 1; i < s.length(); i++) {
+ if (s.charAt(i) != s.charAt(i - 1)) {
+ int index = s.charAt(i - 1) - 'a';
+ buckets.get(index).add(cur);
+ cur = 1;
+ } else {
+ cur++;
+ }
+ }
+ int endIndex = s.charAt(s.length() - 1) - 'a';
+ buckets.get(endIndex).add(cur);
+ int result = -1;
+ for (List bucket : buckets) {
+ result = Math.max(result, generate(bucket));
+ }
+ return result;
+ }
+
+ private int generate(List list) {
+ Collections.sort(list, Collections.reverseOrder());
+ TreeMap map = new TreeMap<>(Collections.reverseOrder());
+ for (int i = 0; i < list.size() && i < 3; i++) {
+ int cur = list.get(i);
+ int num = map.getOrDefault(cur, 0);
+ map.put(cur, num + 1);
+ if (cur >= 2) {
+ num = map.getOrDefault(cur - 1, 0);
+ map.put(cur - 1, num + 2);
+ }
+ if (cur >= 3) {
+ num = map.getOrDefault(cur - 2, 0);
+ map.put(cur - 2, num + 3);
+ }
+ }
+ for (Map.Entry entry : map.entrySet()) {
+ if (entry.getValue() >= 3) {
+ return entry.getKey();
+ }
+ }
+ return -1;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/readme.md b/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/readme.md
new file mode 100644
index 000000000..fbd45d08e
--- /dev/null
+++ b/src/main/java/g2901_3000/s2981_find_longest_special_substring_that_occurs_thrice_i/readme.md
@@ -0,0 +1,44 @@
+2981\. Find Longest Special Substring That Occurs Thrice I
+
+Medium
+
+You are given a string `s` that consists of lowercase English letters.
+
+A string is called **special** if it is made up of only a single character. For example, the string `"abc"` is not special, whereas the strings `"ddd"`, `"zz"`, and `"f"` are special.
+
+Return _the length of the **longest special substring** of_ `s` _which occurs **at least thrice**_, _or_ `-1` _if no special substring occurs at least thrice_.
+
+A **substring** is a contiguous **non-empty** sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "aaaa"
+
+**Output:** 2
+
+**Explanation:** The longest special substring which occurs thrice is "aa": substrings "**aa**aa", "a**aa**a", and "aa**aa**".
+
+It can be shown that the maximum length achievable is 2.
+
+**Example 2:**
+
+**Input:** s = "abcdef"
+
+**Output:** -1
+
+**Explanation:** There exists no special substring which occurs at least thrice. Hence return -1.
+
+**Example 3:**
+
+**Input:** s = "abcaba"
+
+**Output:** 1
+
+**Explanation:** The longest special substring which occurs thrice is "a": substrings "**a**bcaba", "abc**a**ba", and "abcab**a**".
+
+It can be shown that the maximum length achievable is 1.
+
+**Constraints:**
+
+* `3 <= s.length <= 50`
+* `s` consists of only lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/Solution.java b/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/Solution.java
new file mode 100644
index 000000000..436a2b6cd
--- /dev/null
+++ b/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/Solution.java
@@ -0,0 +1,50 @@
+package g2901_3000.s2982_find_longest_special_substring_that_occurs_thrice_ii;
+
+// #Medium #String #Hash_Table #Binary_Search #Counting #Sliding_Window
+// #2024_01_18_Time_18_ms_(99.35%)_Space_48.9_MB_(42.38%)
+
+public class Solution {
+ public int maximumLength(String s) {
+ int[][] arr = new int[26][4];
+ char prev = s.charAt(0);
+ int count = 1;
+ int max = 0;
+ for (int index = 1; index < s.length(); index++) {
+ if (s.charAt(index) != prev) {
+ int[] ints = arr[prev - 'a'];
+ updateArr(count, ints);
+ prev = s.charAt(index);
+ count = 1;
+ } else {
+ count++;
+ }
+ }
+ updateArr(count, arr[prev - 'a']);
+ for (int[] values : arr) {
+ if (values[0] != 0) {
+ if (values[1] >= 3) {
+ max = Math.max(max, values[0]);
+ } else if (values[1] == 2 || values[2] == values[0] - 1) {
+ max = Math.max(max, values[0] - 1);
+ } else {
+ max = Math.max(max, values[0] - 2);
+ }
+ }
+ }
+ return max == 0 ? -1 : max;
+ }
+
+ private void updateArr(int count, int[] ints) {
+ if (ints[0] == count) {
+ ints[1]++;
+ } else if (ints[0] < count) {
+ ints[3] = ints[1];
+ ints[2] = ints[0];
+ ints[0] = count;
+ ints[1] = 1;
+ } else if (ints[2] < count) {
+ ints[2] = count;
+ ints[3] = 1;
+ }
+ }
+}
diff --git a/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/readme.md b/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/readme.md
new file mode 100644
index 000000000..5ec8bbf4d
--- /dev/null
+++ b/src/main/java/g2901_3000/s2982_find_longest_special_substring_that_occurs_thrice_ii/readme.md
@@ -0,0 +1,44 @@
+2982\. Find Longest Special Substring That Occurs Thrice II
+
+Medium
+
+You are given a string `s` that consists of lowercase English letters.
+
+A string is called **special** if it is made up of only a single character. For example, the string `"abc"` is not special, whereas the strings `"ddd"`, `"zz"`, and `"f"` are special.
+
+Return _the length of the **longest special substring** of_ `s` _which occurs **at least thrice**_, _or_ `-1` _if no special substring occurs at least thrice_.
+
+A **substring** is a contiguous **non-empty** sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "aaaa"
+
+**Output:** 2
+
+**Explanation:** The longest special substring which occurs thrice is "aa": substrings "**aa**aa", "a**aa**a", and "aa**aa**".
+
+It can be shown that the maximum length achievable is 2.
+
+**Example 2:**
+
+**Input:** s = "abcdef"
+
+**Output:** -1
+
+**Explanation:** There exists no special substring which occurs at least thrice. Hence return -1.
+
+**Example 3:**
+
+**Input:** s = "abcaba"
+
+**Output:** 1
+
+**Explanation:** The longest special substring which occurs thrice is "a": substrings "**a**bcaba", "abc**a**ba", and "abcab**a**".
+
+It can be shown that the maximum length achievable is 1.
+
+**Constraints:**
+
+* 3 <= s.length <= 5 * 105
+* `s` consists of only lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/Solution.java b/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/Solution.java
new file mode 100644
index 000000000..28972313c
--- /dev/null
+++ b/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/Solution.java
@@ -0,0 +1,123 @@
+package g2901_3000.s2983_palindrome_rearrangement_queries;
+
+// #Hard #String #Hash_Table #Prefix_Sum #2024_01_18_Time_14_ms_(88.19%)_Space_96.6_MB_(78.74%)
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+@SuppressWarnings("java:S6541")
+public class Solution {
+ private int n;
+
+ // get associated index in the other half
+ private int opp(int i) {
+ return n - 1 - i;
+ }
+
+ public boolean[] canMakePalindromeQueries(String s, int[][] queries) {
+ int[] fq = new int[26];
+ int m = queries.length;
+ boolean[] ret = new boolean[m];
+ n = s.length();
+ // check that both halves contain the same letters
+ for (int i = 0; i < n / 2; i++) {
+ fq[s.charAt(i) - 'a']++;
+ }
+ for (int i = n / 2; i < n; i++) {
+ fq[s.charAt(i) - 'a']--;
+ }
+ for (int em : fq) {
+ if (em != 0) {
+ return ret;
+ }
+ }
+ // find the first and the last characters in the first half
+ // that do not match with their associated character in
+ // the second half
+ int problemPoint = -1;
+ int lastProblem = -1;
+ for (int i = 0; i < n / 2; i++) {
+ if (s.charAt(i) != s.charAt(opp(i))) {
+ if (problemPoint == -1) {
+ problemPoint = i;
+ }
+ lastProblem = i;
+ }
+ }
+ // if already a palindrome
+ if (problemPoint == -1) {
+ Arrays.fill(ret, true);
+ return ret;
+ }
+ // the idea is that at least one of the intervals in the
+ // query has to cover the first pair of different characters.
+ // But depending on how far the other end of that interval
+ // goes, the requirements for the other interval are lessened
+ int[] dpFirst = new int[n / 2 + 1];
+ int[] dpSecond = new int[n + 1];
+ Arrays.fill(dpFirst, -1);
+ Arrays.fill(dpSecond, -1);
+ // assuming the first interval covers the first problem,
+ // and then extends to the right
+ int rptr = opp(problemPoint);
+ Map mp = new HashMap<>();
+ for (int i = problemPoint; i < n / 2; i++) {
+ mp.compute(s.charAt(i), (k, v) -> v == null ? 1 : v + 1);
+ // the burden for the left end of the second interval does not change;
+ // it needs to go at least until the last problematic match. But the
+ // requirements for the right end do. If we can rearrange the characters
+ // in the left half to match the right end of the right interval, this
+ // means we do not need the right end of the right interval to go too far
+ while (mp.containsKey(s.charAt(rptr))
+ || (rptr >= n / 2 && s.charAt(rptr) == s.charAt(opp(rptr)) && mp.size() == 0)) {
+ mp.computeIfPresent(s.charAt(rptr), (k, v) -> v == 1 ? null : v - 1);
+ rptr--;
+ }
+ dpFirst[i] = rptr;
+ }
+ // mirrored discussion assuming it is the right interval that takes
+ // care of the first problematic pair
+ int lptr = problemPoint;
+ mp.clear();
+ for (int i = opp(problemPoint); i >= n / 2; i--) {
+ mp.compute(s.charAt(i), (k, v) -> v == null ? 1 : v + 1);
+ while (mp.containsKey(s.charAt(lptr))
+ || (lptr < n / 2 && s.charAt(lptr) == s.charAt(opp(lptr)) && mp.size() == 0)) {
+ mp.computeIfPresent(s.charAt(lptr), (k, v) -> v == 1 ? null : v - 1);
+ lptr++;
+ }
+ dpSecond[i] = lptr;
+ }
+ for (int i = 0; i < m; i++) {
+ int a = queries[i][0];
+ int b = queries[i][1];
+ int c = queries[i][2];
+ int d = queries[i][3];
+ // if either interval the problematic interval on its side, it does not matter
+ // what happens with the other interval
+ if (a <= problemPoint && b >= lastProblem
+ || c <= opp(lastProblem) && d >= opp(problemPoint)) {
+ ret[i] = true;
+ continue;
+ }
+ // if the left interval covers the first problem, we use
+ // dp to figure out if the right one is large enough
+ if (a <= problemPoint
+ && b >= problemPoint
+ && d >= dpFirst[b]
+ && c <= opp(lastProblem)) {
+ ret[i] = true;
+ }
+ // similarly for the case where the right interval covers
+ // the first problem
+ if (d >= opp(problemPoint)
+ && c <= opp(problemPoint)
+ && a <= dpSecond[c]
+ && b >= lastProblem) {
+ ret[i] = true;
+ }
+ }
+ return ret;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/readme.md b/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/readme.md
new file mode 100644
index 000000000..1380ed730
--- /dev/null
+++ b/src/main/java/g2901_3000/s2983_palindrome_rearrangement_queries/readme.md
@@ -0,0 +1,95 @@
+2983\. Palindrome Rearrangement Queries
+
+Hard
+
+You are given a **0-indexed** string `s` having an **even** length `n`.
+
+You are also given a **0-indexed** 2D integer array, `queries`, where queries[i] = [ai, bi, ci, di].
+
+For each query `i`, you are allowed to perform the following operations:
+
+* Rearrange the characters within the **substring** s[ai:bi], where 0 <= ai <= bi < n / 2.
+* Rearrange the characters within the **substring** s[ci:di], where n / 2 <= ci <= di < n.
+
+For each query, your task is to determine whether it is possible to make `s` a **palindrome** by performing the operations.
+
+Each query is answered **independently** of the others.
+
+Return _a **0-indexed** array_ `answer`_, where_ `answer[i] == true` _if it is possible to make_ `s` _a palindrome by performing operations specified by the_ ith _query, and_ `false` _otherwise._
+
+* A **substring** is a contiguous sequence of characters within a string.
+* `s[x:y]` represents the substring consisting of characters from the index `x` to index `y` in `s`, **both inclusive**.
+
+**Example 1:**
+
+**Input:** s = "abcabc", queries = [[1,1,3,5],[0,2,5,5]]
+
+**Output:** [true,true]
+
+**Explanation:** In this example, there are two queries:
+
+In the first query:
+
+- a0 = 1, b0 = 1, c0 = 3, d0 = 5.
+
+- So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.
+
+- To make s a palindrome, s[3:5] can be rearranged to become => abccba.
+
+- Now, s is a palindrome. So, answer[0] = true.
+
+In the second query:
+
+- a1 = 0, b1 = 2, c1 = 5, d1 = 5.
+
+- So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.
+
+- To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.
+
+- Now, s is a palindrome. So, answer[1] = true.
+
+**Example 2:**
+
+**Input:** s = "abbcdecbba", queries = [[0,2,7,9]]
+
+**Output:** [false]
+
+**Explanation:** In this example, there is only one query.
+
+a0 = 0, b0 = 2, c0 = 7, d0 = 9.
+
+So, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.
+
+It is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.
+
+So, answer[0] = false.
+
+**Example 3:**
+
+**Input:** s = "acbcab", queries = [[1,2,4,5]]
+
+**Output:** [true]
+
+**Explanation:** In this example, there is only one query.
+
+a0 = 1, b0 = 2, c0 = 4, d0 = 5.
+
+So, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.
+
+To make s a palindrome s[1:2] can be rearranged to become abccab.
+
+Then, s[4:5] can be rearranged to become abccba.
+
+Now, s is a palindrome. So, answer[0] = true.
+
+**Constraints:**
+
+* 2 <= n == s.length <= 105
+* 1 <= queries.length <= 105
+* `queries[i].length == 4`
+* ai == queries[i][0], bi == queries[i][1]
+* ci == queries[i][2], di == queries[i][3]
+* 0 <= ai <= bi < n / 2
+* n / 2 <= ci <= di < n
+* `n` is even.
+* `s` consists of only lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/Solution.java b/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/Solution.java
new file mode 100644
index 000000000..89fae04e2
--- /dev/null
+++ b/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/Solution.java
@@ -0,0 +1,26 @@
+package g2901_3000.s2996_smallest_missing_integer_greater_than_sequential_prefix_sum;
+
+// #Easy #Array #Hash_Table #Sorting #2024_01_17_Time_1_ms_(93.13%)_Space_42.2_MB_(58.31%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int missingInteger(int[] nums) {
+ int n = nums.length;
+ int sum = nums[0];
+ for (int i = 1; i < n; i++) {
+ if (nums[i] == nums[i - 1] + 1) {
+ sum = sum + nums[i];
+ } else {
+ break;
+ }
+ }
+ Arrays.sort(nums);
+ for (int no : nums) {
+ if (no == sum) {
+ sum++;
+ }
+ }
+ return sum;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/readme.md b/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/readme.md
new file mode 100644
index 000000000..8d30d3c12
--- /dev/null
+++ b/src/main/java/g2901_3000/s2996_smallest_missing_integer_greater_than_sequential_prefix_sum/readme.md
@@ -0,0 +1,30 @@
+2996\. Smallest Missing Integer Greater Than Sequential Prefix Sum
+
+Easy
+
+You are given a **0-indexed** array of integers `nums`.
+
+A prefix `nums[0..i]` is **sequential** if, for all `1 <= j <= i`, `nums[j] = nums[j - 1] + 1`. In particular, the prefix consisting only of `nums[0]` is **sequential**.
+
+Return _the **smallest** integer_ `x` _missing from_ `nums` _such that_ `x` _is greater than or equal to the sum of the **longest** sequential prefix._
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,2,5]
+
+**Output:** 6
+
+**Explanation:** The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
+
+**Example 2:**
+
+**Input:** nums = [3,4,5,1,12,14,13]
+
+**Output:** 15
+
+**Explanation:** The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
+
+**Constraints:**
+
+* `1 <= nums.length <= 50`
+* `1 <= nums[i] <= 50`
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/Solution.java b/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/Solution.java
new file mode 100644
index 000000000..32c1c4ab7
--- /dev/null
+++ b/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/Solution.java
@@ -0,0 +1,21 @@
+package g2901_3000.s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k;
+
+// #Medium #Array #Bit_Manipulation #2024_01_17_Time_1_ms_(100.00%)_Space_58.7_MB_(15.31%)
+
+public class Solution {
+ public int minOperations(int[] nums, int k) {
+ int count = 0;
+ int xor = 0;
+ for (int num : nums) {
+ xor = xor ^ num;
+ }
+ while (xor > 0 || k > 0) {
+ if (xor % 2 != k % 2) {
+ count++;
+ }
+ xor /= 2;
+ k /= 2;
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/readme.md b/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/readme.md
new file mode 100644
index 000000000..e84b4d41d
--- /dev/null
+++ b/src/main/java/g2901_3000/s2997_minimum_number_of_operations_to_make_array_xor_equal_to_k/readme.md
@@ -0,0 +1,43 @@
+2997\. Minimum Number of Operations to Make Array XOR Equal to K
+
+Medium
+
+You are given a **0-indexed** integer array `nums` and a positive integer `k`.
+
+You can apply the following operation on the array **any** number of times:
+
+* Choose **any** element of the array and **flip** a bit in its **binary** representation. Flipping a bit means changing a `0` to `1` or vice versa.
+
+Return _the **minimum** number of operations required to make the bitwise_ `XOR` _of **all** elements of the final array equal to_ `k`.
+
+**Note** that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)2 you can flip the fourth bit and obtain (1101)2.
+
+**Example 1:**
+
+**Input:** nums = [2,1,3,4], k = 1
+
+**Output:** 2
+
+**Explanation:** We can do the following operations:
+
+- Choose element 2 which is 3 == (011)2, we flip the first bit and we obtain (010)2 == 2. nums becomes [2,1,2,4].
+
+- Choose element 0 which is 2 == (010)2, we flip the third bit and we obtain (110)2 = 6. nums becomes [6,1,2,4].
+
+The XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.
+
+It can be shown that we cannot make the XOR equal to k in less than 2 operations.
+
+**Example 2:**
+
+**Input:** nums = [2,0,2,0], k = 0
+
+**Output:** 0
+
+**Explanation:** The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 0 <= nums[i] <= 106
+* 0 <= k <= 106
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/Solution.java b/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/Solution.java
new file mode 100644
index 000000000..eff77f59a
--- /dev/null
+++ b/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/Solution.java
@@ -0,0 +1,18 @@
+package g2901_3000.s2998_minimum_number_of_operations_to_make_x_and_y_equal;
+
+// #Medium #Dynamic_Programming #Breadth_First_Search #Memoization
+// #2024_01_17_Time_0_ms_(100.00%)_Space_41.2_MB_(92.39%)
+
+public class Solution {
+ public int minimumOperationsToMakeEqual(int x, int y) {
+ if (x <= y) {
+ return y - x;
+ }
+ int res = x - y;
+ res = Math.min(res, 1 + minimumOperationsToMakeEqual(x / 5, y) + x % 5);
+ res = Math.min(res, 1 + minimumOperationsToMakeEqual(x / 5 + 1, y) + 5 - x % 5);
+ res = Math.min(res, 1 + minimumOperationsToMakeEqual(x / 11, y) + x % 11);
+ res = Math.min(res, 1 + minimumOperationsToMakeEqual(x / 11 + 1, y) + 11 - x % 11);
+ return res;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/readme.md b/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/readme.md
new file mode 100644
index 000000000..850b89f67
--- /dev/null
+++ b/src/main/java/g2901_3000/s2998_minimum_number_of_operations_to_make_x_and_y_equal/readme.md
@@ -0,0 +1,72 @@
+2998\. Minimum Number of Operations to Make X and Y Equal
+
+Medium
+
+You are given two positive integers `x` and `y`.
+
+In one operation, you can do one of the four following operations:
+
+1. Divide `x` by `11` if `x` is a multiple of `11`.
+2. Divide `x` by `5` if `x` is a multiple of `5`.
+3. Decrement `x` by `1`.
+4. Increment `x` by `1`.
+
+Return _the **minimum** number of operations required to make_ `x` _and_ `y` equal.
+
+**Example 1:**
+
+**Input:** x = 26, y = 1
+
+**Output:** 3
+
+**Explanation:** We can make 26 equal to 1 by applying the following operations:
+
+1. Decrement x by 1
+
+2. Divide x by 5
+
+3. Divide x by 5
+
+It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.
+
+**Example 2:**
+
+**Input:** x = 54, y = 2
+
+**Output:** 4
+
+**Explanation:** We can make 54 equal to 2 by applying the following operations:
+
+1. Increment x by 1
+
+2. Divide x by 11
+
+3. Divide x by 5
+
+4. Increment x by 1
+
+It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.
+
+**Example 3:**
+
+**Input:** x = 25, y = 30
+
+**Output:** 5
+
+**Explanation:** We can make 25 equal to 30 by applying the following operations:
+
+1. Increment x by 1
+
+2. Increment x by 1
+
+3. Increment x by 1
+
+4. Increment x by 1
+
+5. Increment x by 1
+
+It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
+
+**Constraints:**
+
+* 1 <= x, y <= 104
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/Solution.java b/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/Solution.java
new file mode 100644
index 000000000..4a4d82eb4
--- /dev/null
+++ b/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/Solution.java
@@ -0,0 +1,45 @@
+package g2901_3000.s2999_count_the_number_of_powerful_integers;
+
+// #Hard #String #Dynamic_Programming #Math #2024_01_17_Time_1_ms_(100.00%)_Space_42.6_MB_(83.99%)
+
+public class Solution {
+ public long numberOfPowerfulInt(long start, long finish, int limit, String s) {
+ long sn = Long.parseLong(s);
+ if (finish < sn) {
+ return 0;
+ }
+ start = Math.max(start, sn);
+ long originalL = s.length();
+ long factor = 1;
+ for (long i = 1; i <= originalL; i++) {
+ factor *= 10;
+ }
+ long sx = (start - sn) % factor == 0 ? (start - sn) / factor : (start - sn) / factor + 1;
+ long lx = (finish - sn) / factor;
+
+ return sx == 0
+ ? indexOfLimitIntSmallerThanOrEqual(lx, limit) + 1
+ : indexOfLimitIntSmallerThanOrEqual(lx, limit)
+ - indexOfLimitIntSmallerThanOrEqual(sx - 1, limit);
+ }
+
+ private long indexOfLimitIntSmallerThanOrEqual(long target, int limit) {
+ String s = Long.toString(target);
+ long index = 0;
+ boolean limitViolated = false;
+ for (int i = 0; i < s.length(); i++) {
+ index *= limit + 1;
+ if (!limitViolated) {
+ if (s.charAt(i) - '0' > limit) {
+ limitViolated = true;
+ index += limit;
+ } else {
+ index += (s.charAt(i) - '0');
+ }
+ } else {
+ index += limit;
+ }
+ }
+ return index;
+ }
+}
diff --git a/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/readme.md b/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/readme.md
new file mode 100644
index 000000000..816271da5
--- /dev/null
+++ b/src/main/java/g2901_3000/s2999_count_the_number_of_powerful_integers/readme.md
@@ -0,0 +1,47 @@
+2999\. Count the Number of Powerful Integers
+
+Hard
+
+You are given three integers `start`, `finish`, and `limit`. You are also given a **0-indexed** string `s` representing a **positive** integer.
+
+A **positive** integer `x` is called **powerful** if it ends with `s` (in other words, `s` is a **suffix** of `x`) and each digit in `x` is at most `limit`.
+
+Return _the **total** number of powerful integers in the range_ `[start..finish]`.
+
+A string `x` is a suffix of a string `y` if and only if `x` is a substring of `y` that starts from some index (**including** `0`) in `y` and extends to the index `y.length - 1`. For example, `25` is a suffix of `5125` whereas `512` is not.
+
+**Example 1:**
+
+**Input:** start = 1, finish = 6000, limit = 4, s = "124"
+
+**Output:** 5
+
+**Explanation:** The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and "124" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.
+
+It can be shown that there are only 5 powerful integers in this range.
+
+**Example 2:**
+
+**Input:** start = 15, finish = 215, limit = 6, s = "10"
+
+**Output:** 2
+
+**Explanation:** The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and "10" as a suffix.
+
+It can be shown that there are only 2 powerful integers in this range.
+
+**Example 3:**
+
+**Input:** start = 1000, finish = 2000, limit = 4, s = "3000"
+
+**Output:** 0
+
+**Explanation:** All integers in the range [1000..2000] are smaller than 3000, hence "3000" cannot be a suffix of any integer in this range.
+
+**Constraints:**
+
+* 1 <= start <= finish <= 1015
+* `1 <= limit <= 9`
+* 1 <= s.length <= floor(log10(finish)) + 1
+* `s` only consists of numeric digits which are at most `limit`.
+* `s` does not have leading zeros.
\ No newline at end of file
diff --git a/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/Solution.java b/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/Solution.java
new file mode 100644
index 000000000..acf713640
--- /dev/null
+++ b/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/Solution.java
@@ -0,0 +1,21 @@
+package g2901_3000.s3000_maximum_area_of_longest_diagonal_rectangle;
+
+// #Easy #Array #2024_01_17_Time_1_ms_(99.67%)_Space_44.1_MB_(93.21%)
+
+public class Solution {
+ public int areaOfMaxDiagonal(int[][] dimensions) {
+ int mx = 0;
+ for (int[] t : dimensions) {
+ if (t[0] * t[0] + t[1] * t[1] > mx) {
+ mx = t[0] * t[0] + t[1] * t[1];
+ }
+ }
+ int area = 0;
+ for (int[] t : dimensions) {
+ if (t[0] * t[0] + t[1] * t[1] == mx && t[0] * t[1] > area) {
+ area = t[0] * t[1];
+ }
+ }
+ return area;
+ }
+}
diff --git a/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/readme.md b/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/readme.md
new file mode 100644
index 000000000..b3b4152a5
--- /dev/null
+++ b/src/main/java/g2901_3000/s3000_maximum_area_of_longest_diagonal_rectangle/readme.md
@@ -0,0 +1,37 @@
+3000\. Maximum Area of Longest Diagonal Rectangle
+
+Easy
+
+You are given a 2D **0-indexed** integer array `dimensions`.
+
+For all indices `i`, `0 <= i < dimensions.length`, `dimensions[i][0]` represents the length and `dimensions[i][1]` represents the width of the rectangle `i`.
+
+Return _the **area** of the rectangle having the **longest** diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the **maximum** area._
+
+**Example 1:**
+
+**Input:** dimensions = [[9,3],[8,6]]
+
+**Output:** 48
+
+**Explanation:**
+
+For index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 \* 9 + 3 \* 3) = sqrt(90) â 9.487.
+
+For index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 \* 8 + 6 \* 6) = sqrt(100) = 10.
+
+So, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 \* 6 = 48.
+
+**Example 2:**
+
+**Input:** dimensions = [[3,4],[4,3]]
+
+**Output:** 12
+
+**Explanation:** Length of diagonal is the same for both which is 5, so maximum area = 12.
+
+**Constraints:**
+
+* `1 <= dimensions.length <= 100`
+* `dimensions[i].length == 2`
+* `1 <= dimensions[i][0], dimensions[i][1] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java
new file mode 100644
index 000000000..95e2ae26b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java
@@ -0,0 +1,24 @@
+package g3001_3100.s3001_minimum_moves_to_capture_the_queen;
+
+// #Medium #Array #Enumeration #2024_11_08_Time_0_ms_(100.00%)_Space_41_MB_(27.27%)
+
+public class Solution {
+ public int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) {
+ if (a == e || b == f) {
+ if (a == e && a == c && (d - b) * (d - f) < 0) {
+ return 2;
+ }
+ if (b == f && b == d && (c - a) * (c - e) < 0) {
+ return 2;
+ }
+ return 1;
+ }
+ if (Math.abs(c - e) == Math.abs(d - f)) {
+ if (Math.abs(c - a) == Math.abs(d - b) && (b - f) * (b - d) < 0) {
+ return 2;
+ }
+ return 1;
+ }
+ return 2;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/readme.md b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/readme.md
new file mode 100644
index 000000000..4978cdba0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/readme.md
@@ -0,0 +1,51 @@
+3001\. Minimum Moves to Capture The Queen
+
+Medium
+
+There is a **1-indexed** `8 x 8` chessboard containing `3` pieces.
+
+You are given `6` integers `a`, `b`, `c`, `d`, `e`, and `f` where:
+
+* `(a, b)` denotes the position of the white rook.
+* `(c, d)` denotes the position of the white bishop.
+* `(e, f)` denotes the position of the black queen.
+
+Given that you can only move the white pieces, return _the **minimum** number of moves required to capture the black queen_.
+
+**Note** that:
+
+* Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.
+* Bishops can move any number of squares diagonally, but cannot jump over other pieces.
+* A rook or a bishop can capture the queen if it is located in a square that they can move to.
+* The queen does not move.
+
+**Example 1:**
+
+
+
+**Input:** a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
+
+**Output:** 2
+
+**Explanation:** We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).
+
+It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.
+
+**Example 2:**
+
+
+
+**Input:** a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
+
+**Output:** 1
+
+**Explanation:** We can capture the black queen in a single move by doing one of the following:
+
+- Move the white rook to (5, 2).
+
+- Move the white bishop to (5, 2).
+
+**Constraints:**
+
+* `1 <= a, b, c, d, e, f <= 8`
+* No two pieces are on the same square.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/Solution.java b/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/Solution.java
new file mode 100644
index 000000000..e09fd4ccb
--- /dev/null
+++ b/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/Solution.java
@@ -0,0 +1,36 @@
+package g3001_3100.s3002_maximum_size_of_a_set_after_removals;
+
+// #Medium #Array #Hash_Table #Greedy #2024_02_26_Time_26_ms_(94.01%)_Space_53.3_MB_(80.90%)
+
+import java.util.HashSet;
+
+public class Solution {
+ public int maximumSetSize(int[] nums1, int[] nums2) {
+ HashSet uniq1 = new HashSet<>();
+ HashSet uniq2 = new HashSet<>();
+ for (int i = 0; i < nums1.length; i++) {
+ uniq1.add(nums1[i]);
+ uniq2.add(nums2[i]);
+ }
+ int common = 0;
+ if (uniq1.size() <= uniq2.size()) {
+ for (int u : uniq1) {
+ if (uniq2.contains(u)) {
+ common++;
+ }
+ }
+ } else {
+ for (int u : uniq2) {
+ if (uniq1.contains(u)) {
+ common++;
+ }
+ }
+ }
+ int half = nums1.length / 2;
+ int from1 = Math.min(uniq1.size() - common, half);
+ int from2 = Math.min(uniq2.size() - common, half);
+ int takeFromCommon1 = half - from1;
+ int takeFromCommon2 = half - from2;
+ return from1 + from2 + Math.min(takeFromCommon1 + takeFromCommon2, common);
+ }
+}
diff --git a/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/readme.md b/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/readme.md
new file mode 100644
index 000000000..4a04aaf24
--- /dev/null
+++ b/src/main/java/g3001_3100/s3002_maximum_size_of_a_set_after_removals/readme.md
@@ -0,0 +1,46 @@
+3002\. Maximum Size of a Set After Removals
+
+Medium
+
+You are given two **0-indexed** integer arrays `nums1` and `nums2` of even length `n`.
+
+You must remove `n / 2` elements from `nums1` and `n / 2` elements from `nums2`. After the removals, you insert the remaining elements of `nums1` and `nums2` into a set `s`.
+
+Return _the **maximum** possible size of the set_ `s`.
+
+**Example 1:**
+
+**Input:** nums1 = [1,2,1,2], nums2 = [1,1,1,1]
+
+**Output:** 2
+
+**Explanation:** We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.
+
+It can be shown that 2 is the maximum possible size of the set s after the removals.
+
+**Example 2:**
+
+**Input:** nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]
+
+**Output:** 5
+
+**Explanation:** We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.
+
+It can be shown that 5 is the maximum possible size of the set s after the removals.
+
+**Example 3:**
+
+**Input:** nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]
+
+**Output:** 6
+
+**Explanation:** We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.
+
+It can be shown that 6 is the maximum possible size of the set s after the removals.
+
+**Constraints:**
+
+* `n == nums1.length == nums2.length`
+* 1 <= n <= 2 * 104
+* `n` is even.
+* 1 <= nums1[i], nums2[i] <= 109
diff --git a/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/Solution.java b/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/Solution.java
new file mode 100644
index 000000000..d77b1a644
--- /dev/null
+++ b/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/Solution.java
@@ -0,0 +1,89 @@
+package g3001_3100.s3003_maximize_the_number_of_partitions_after_operations;
+
+// #Hard #String #Dynamic_Programming #Bit_Manipulation #Bitmask
+// #2024_02_26_Time_1_ms_(100.00%)_Space_42.1_MB_(99.44%)
+
+@SuppressWarnings("java:S6541")
+public class Solution {
+ private static final int ALPHABET_SIZE = 'z' - 'a' + 1;
+
+ public int maxPartitionsAfterOperations(String s, int k) {
+ if (k == ALPHABET_SIZE) {
+ return 1;
+ }
+ int n = s.length();
+ int[] ansr = new int[n];
+ int[] usedr = new int[n];
+ int used = 0;
+ int cntUsed = 0;
+ int ans = 1;
+ for (int i = n - 1; i >= 0; --i) {
+ int ch = s.charAt(i) - 'a';
+ if ((used & (1 << ch)) == 0) {
+ if (cntUsed == k) {
+ cntUsed = 0;
+ used = 0;
+ ans++;
+ }
+ used |= (1 << ch);
+ cntUsed++;
+ }
+ ansr[i] = ans;
+ usedr[i] = used;
+ }
+ int ansl = 0;
+ ans = ansr[0];
+ int l = 0;
+ while (l < n) {
+ used = 0;
+ cntUsed = 0;
+ int usedBeforeLast = 0;
+ int usedTwiceBeforeLast = 0;
+ int last = -1;
+ int r = l;
+ while (r < n) {
+ int ch = s.charAt(r) - 'a';
+ if ((used & (1 << ch)) == 0) {
+ if (cntUsed == k) {
+ break;
+ }
+ usedBeforeLast = used;
+ last = r;
+ used |= (1 << ch);
+ cntUsed++;
+ } else if (cntUsed < k) {
+ usedTwiceBeforeLast |= (1 << ch);
+ }
+ r++;
+ }
+ if (cntUsed == k) {
+ if (last - l > Integer.bitCount(usedBeforeLast)) {
+ ans = Math.max(ans, ansl + 1 + ansr[last]);
+ }
+ if (last + 1 < r) {
+ if (last + 2 >= n) {
+ ans = Math.max(ans, ansl + 1 + 1);
+ } else {
+ if (Integer.bitCount(usedr[last + 2]) == k) {
+ int canUse = ((1 << ALPHABET_SIZE) - 1) & ~used & ~usedr[last + 2];
+ if (canUse > 0) {
+ ans = Math.max(ans, ansl + 1 + 1 + ansr[last + 2]);
+ } else {
+ ans = Math.max(ans, ansl + 1 + ansr[last + 2]);
+ }
+ int l1 = s.charAt(last + 1) - 'a';
+ if ((usedTwiceBeforeLast & (1 << l1)) == 0) {
+ ans = Math.max(ans, ansl + 1 + ansr[last + 1]);
+ }
+ } else {
+ ans = Math.max(ans, ansl + 1 + ansr[last + 2]);
+ }
+ }
+ }
+ }
+ l = r;
+ ansl++;
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/readme.md b/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/readme.md
new file mode 100644
index 000000000..8c9fec781
--- /dev/null
+++ b/src/main/java/g3001_3100/s3003_maximize_the_number_of_partitions_after_operations/readme.md
@@ -0,0 +1,66 @@
+3003\. Maximize the Number of Partitions After Operations
+
+Hard
+
+You are given a **0-indexed** string `s` and an integer `k`.
+
+You are to perform the following partitioning operations until `s` is **empty**:
+
+* Choose the **longest** **prefix** of `s` containing at most `k` **distinct** characters.
+* **Delete** the prefix from `s` and increase the number of partitions by one. The remaining characters (if any) in `s` maintain their initial order.
+
+**Before** the operations, you are allowed to change **at most** **one** index in `s` to another lowercase English letter.
+
+Return _an integer denoting the **maximum** number of resulting partitions after the operations by optimally choosing at most one index to change._
+
+**Example 1:**
+
+**Input:** s = "accca", k = 2
+
+**Output:** 3
+
+**Explanation:** In this example, to maximize the number of resulting partitions, s[2] can be changed to 'b'. s becomes "acbca". The operations can now be performed as follows until s becomes empty:
+- Choose the longest prefix containing at most 2 distinct characters, "acbca".
+- Delete the prefix, and s becomes "bca". The number of partitions is now 1.
+- Choose the longest prefix containing at most 2 distinct characters, "bca".
+- Delete the prefix, and s becomes "a". The number of partitions is now 2.
+- Choose the longest prefix containing at most 2 distinct characters, "a".
+- Delete the prefix, and s becomes empty. The number of partitions is now 3.
+
+Hence, the answer is 3. It can be shown that it is not possible to obtain more than 3 partitions.
+
+**Example 2:**
+
+**Input:** s = "aabaab", k = 3
+
+**Output:** 1
+
+**Explanation:** In this example, to maximize the number of resulting partitions we can leave s as it is. The operations can now be performed as follows until s becomes empty:
+- Choose the longest prefix containing at most 3 distinct characters, "aabaab".
+- Delete the prefix, and s becomes empty. The number of partitions becomes 1.
+
+Hence, the answer is 1. It can be shown that it is not possible to obtain more than 1 partition.
+
+**Example 3:**
+
+**Input:** s = "xxyz", k = 1
+
+**Output:** 4
+
+**Explanation:** In this example, to maximize the number of resulting partitions, s[1] can be changed to 'a'. s becomes "xayz". The operations can now be performed as follows until s becomes empty:
+- Choose the longest prefix containing at most 1 distinct character, "xayz".
+- Delete the prefix, and s becomes "ayz". The number of partitions is now 1.
+- Choose the longest prefix containing at most 1 distinct character, "ayz".
+- Delete the prefix, and s becomes "yz". The number of partitions is now 2.
+- Choose the longest prefix containing at most 1 distinct character, "yz".
+- Delete the prefix, and s becomes "z". The number of partitions is now 3.
+- Choose the longest prefix containing at most 1 distinct character, "z".
+- Delete the prefix, and s becomes empty. The number of partitions is now 4.
+
+Hence, the answer is 4. It can be shown that it is not possible to obtain more than 4 partitions.
+
+**Constraints:**
+
+* 1 <= s.length <= 104
+* `s` consists only of lowercase English letters.
+* `1 <= k <= 26`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/Solution.java b/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/Solution.java
new file mode 100644
index 000000000..a1e356bd0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/Solution.java
@@ -0,0 +1,45 @@
+package g3001_3100.s3005_count_elements_with_maximum_frequency;
+
+// #Easy #Array #Hash_Table #Counting #2024_02_26_Time_1_ms_(99.76%)_Space_41.6_MB_(98.97%)
+
+import java.util.ArrayList;
+import java.util.List;
+
+@SuppressWarnings("java:S135")
+public class Solution {
+ public int maxFrequencyElements(int[] nums) {
+ if (nums.length == 1) {
+ return 1;
+ }
+ List list = new ArrayList<>();
+ int co = 0;
+ int prev = 0;
+ for (int num : nums) {
+ if (list.contains(num)) {
+ continue;
+ }
+ list.add(num);
+ if (list.size() == nums.length) {
+ break;
+ }
+ int c = 0;
+ for (int i : nums) {
+ if (num == i) {
+ c++;
+ }
+ }
+ if (c > 1) {
+ if (c > prev) {
+ co = c;
+ prev = c;
+ } else if (c == prev) {
+ co = c + co;
+ }
+ }
+ }
+ if (co == 0) {
+ return nums.length;
+ }
+ return co;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/readme.md b/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/readme.md
new file mode 100644
index 000000000..1d7e14492
--- /dev/null
+++ b/src/main/java/g3001_3100/s3005_count_elements_with_maximum_frequency/readme.md
@@ -0,0 +1,30 @@
+3005\. Count Elements With Maximum Frequency
+
+Easy
+
+You are given an array `nums` consisting of **positive** integers.
+
+Return _the **total frequencies** of elements in_ `nums` _such that those elements all have the **maximum** frequency_.
+
+The **frequency** of an element is the number of occurrences of that element in the array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,2,3,1,4]
+
+**Output:** 4
+
+**Explanation:** The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array. So the number of elements in the array with maximum frequency is 4.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 5
+
+**Explanation:** All elements of the array have a frequency of 1 which is the maximum. So the number of elements in the array with maximum frequency is 5.
+
+**Constraints:**
+
+* `1 <= nums.length <= 100`
+* `1 <= nums[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/Solution.java b/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/Solution.java
new file mode 100644
index 000000000..78e32db7f
--- /dev/null
+++ b/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/Solution.java
@@ -0,0 +1,114 @@
+package g3001_3100.s3006_find_beautiful_indices_in_the_given_array_i;
+
+// #Medium #String #Binary_Search #Two_Pointers #Hash_Function #String_Matching #Rolling_Hash
+// #2024_02_26_Time_8_ms_(95.86%)_Space_45.8_MB_(80.19%)
+
+import java.util.ArrayList;
+import java.util.List;
+
+@SuppressWarnings("java:S6541")
+public class Solution {
+ public List beautifulIndices(String s, String a, String b, int q) {
+ char[] sc = s.toCharArray();
+ char[] ac = a.toCharArray();
+ char[] bc = b.toCharArray();
+ int[] lpsa = getLps(ac);
+ int[] lpsb = getLps(bc);
+ int mo;
+ int[] comp = new int[sc.length];
+ int[] st = new int[sc.length];
+ int si = 0;
+ int k;
+ mo = -bc.length + 1;
+ if (bc[0] == sc[0]) {
+ comp[0] = 1;
+ if (bc.length == 1) {
+ st[si++] = mo;
+ }
+ }
+ for (int i = 1; i < comp.length; i++) {
+ mo++;
+ if (sc[i] == bc[0]) {
+ comp[i] = 1;
+ }
+ k = comp[i - 1];
+ if (k == bc.length) {
+ k = lpsb[k - 1];
+ }
+ while (k > 0) {
+ if (bc[k] == sc[i]) {
+ comp[i] = k + 1;
+ break;
+ }
+ k = lpsb[k - 1];
+ }
+ if (comp[i] == bc.length) {
+ st[si++] = mo;
+ }
+ }
+ int sia = 0;
+ mo = -ac.length + 1;
+ List ret = new ArrayList<>();
+ if (si == 0) {
+ return ret;
+ }
+ if (sc[0] == ac[0]) {
+ comp[0] = 1;
+ if (ac.length == 1 && st[0] <= q) {
+ ret.add(0);
+ }
+ } else {
+ comp[0] = 0;
+ }
+ for (int i = 1; i < comp.length; i++) {
+ mo++;
+ if (sc[i] == ac[0]) {
+ comp[i] = 1;
+ } else {
+ comp[i] = 0;
+ }
+ k = comp[i - 1];
+ if (k == ac.length) {
+ k = lpsa[k - 1];
+ }
+ while (k > 0) {
+ if (ac[k] == sc[i]) {
+ comp[i] = k + 1;
+ break;
+ }
+ k = lpsa[k - 1];
+ }
+ if (comp[i] == ac.length) {
+ while (sia < si && st[sia] + q < mo) {
+ sia++;
+ }
+ if (sia == si) {
+ break;
+ }
+ if (mo >= st[sia] - q && mo <= st[sia] + q) {
+ ret.add(mo);
+ }
+ }
+ }
+ return ret;
+ }
+
+ private int[] getLps(char[] xc) {
+ int[] r = new int[xc.length];
+ int k;
+ for (int i = 1; i < xc.length; i++) {
+ if (xc[i] == xc[0]) {
+ r[i] = 1;
+ }
+ k = r[i - 1];
+ while (k > 0) {
+ if (xc[k] == xc[i]) {
+ r[i] = k + 1;
+ break;
+ }
+ k = r[k - 1];
+ }
+ }
+ return r;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/readme.md b/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/readme.md
new file mode 100644
index 000000000..007313fbe
--- /dev/null
+++ b/src/main/java/g3001_3100/s3006_find_beautiful_indices_in_the_given_array_i/readme.md
@@ -0,0 +1,41 @@
+3006\. Find Beautiful Indices in the Given Array I
+
+Medium
+
+You are given a **0-indexed** string `s`, a string `a`, a string `b`, and an integer `k`.
+
+An index `i` is **beautiful** if:
+
+* `0 <= i <= s.length - a.length`
+* `s[i..(i + a.length - 1)] == a`
+* There exists an index `j` such that:
+ * `0 <= j <= s.length - b.length`
+ * `s[j..(j + b.length - 1)] == b`
+ * `|j - i| <= k`
+
+Return _the array that contains beautiful indices in **sorted order from smallest to largest**_.
+
+**Example 1:**
+
+**Input:** s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
+
+**Output:** [16,33]
+
+**Explanation:** There are 2 beautiful indices: [16,33].
+- The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
+- The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15. Thus we return [16,33] as the result.
+
+**Example 2:**
+
+**Input:** s = "abcd", a = "a", b = "a", k = 4
+
+**Output:** [0]
+
+**Explanation:** There is 1 beautiful index: [0].
+- The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4. Thus we return [0] as the result.
+
+**Constraints:**
+
+* 1 <= k <= s.length <= 105
+* `1 <= a.length, b.length <= 10`
+* `s`, `a`, and `b` contain only lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/Solution.java b/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/Solution.java
new file mode 100644
index 000000000..e50fd6d1e
--- /dev/null
+++ b/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/Solution.java
@@ -0,0 +1,25 @@
+package g3001_3100.s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k;
+
+// #Medium #Dynamic_Programming #Binary_Search #Bit_Manipulation
+// #2024_02_26_Time_1_ms_(100.00%)_Space_41_MB_(47.71%)
+
+public class Solution {
+ private long count(long k, int bit, int x) {
+ if (k < bit) {
+ return 0;
+ }
+ long n = 1;
+ long bits = bit;
+ long p = 1;
+ while (2 * bits + (p % x == 0 ? n : 0) <= k) {
+ bits = 2 * bits + (p % x == 0 ? n : 0);
+ n *= 2;
+ ++p;
+ }
+ return n + count(k - bits, bit + (p % x == 0 ? 1 : 0), x);
+ }
+
+ public long findMaximumNumber(long k, int x) {
+ return count(k, 0, x) - 1;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/readme.md b/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/readme.md
new file mode 100644
index 000000000..8eea3fca0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k/readme.md
@@ -0,0 +1,55 @@
+3007\. Maximum Number That Sum of the Prices Is Less Than or Equal to K
+
+Medium
+
+You are given an integer `k` and an integer `x`.
+
+Consider `s` is the **1-indexed** binary representation of an integer `num`. The **price** of a number `num` is the number of `i`'s such that `i % x == 0` and `s[i]` is a **set bit**.
+
+Return _the **greatest** integer_ `num` _such that the sum of **prices** of all numbers from_ `1` _to_ `num` _is less than or equal to_ `k`_._
+
+**Note**:
+
+* In the binary representation of a number **set bit** is a bit of value `1`.
+* The binary representation of a number will be indexed from right to left. For example, if `s == 11100`, `s[4] == 1` and `s[2] == 0`.
+
+**Example 1:**
+
+**Input:** k = 9, x = 1
+
+**Output:** 6
+
+**Explanation:** The numbers 1, 2, 3, 4, 5, and 6 can be written in binary representation as "1", "10", "11", "100", "101", and "110" respectively. Since x is equal to 1, the price of each number is the number of its set bits.
+
+The number of set bits in these numbers is 9. So the sum of the prices of the first 6 numbers is 9. So the answer is 6.
+
+**Example 2:**
+
+**Input:** k = 7, x = 2
+
+**Output:** 9
+
+**Explanation:** Since x is equal to 2, we should just check eventh bits.
+
+The second bit of binary representation of numbers 2 and 3 is a set bit.
+
+So the sum of their prices is 2.
+
+The second bit of binary representation of numbers 6 and 7 is a set bit.
+
+So the sum of their prices is 2.
+
+The fourth bit of binary representation of numbers 8 and 9 is a set bit but their second bit is not. So the sum of their prices is 2.
+
+Numbers 1, 4, and 5 don't have set bits in their eventh bits in their binary representation. So the sum of their prices is 0.
+
+The second and the fourth bit of the binary representation of the number 10 are a set bit. So its price is 2.
+
+The sum of the prices of the first 9 numbers is 6.
+
+Because the sum of the prices of the first 10 numbers is 8, the answer is 9.
+
+**Constraints:**
+
+* 1 <= k <= 1015
+* `1 <= x <= 8`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/Solution.java b/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/Solution.java
new file mode 100644
index 000000000..b1ff899d7
--- /dev/null
+++ b/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/Solution.java
@@ -0,0 +1,85 @@
+package g3001_3100.s3008_find_beautiful_indices_in_the_given_array_ii;
+
+// #Hard #String #Binary_Search #Two_Pointers #Hash_Function #String_Matching #Rolling_Hash
+// #2024_02_27_Time_36_ms_(99.66%)_Space_67.9_MB_(99.32%)
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+
+public class Solution {
+ public List beautifulIndices(String s, String a, String b, int k) {
+ int[] lpsA = getLps(a);
+ int[] lpsB = getLps(b);
+ List ans = new ArrayList<>();
+ Deque matchesA = new ArrayDeque<>();
+ int n = s.length();
+ int aLen = a.length();
+ int bLen = b.length();
+ int i = 0;
+ int j = 0;
+ while (i < n) {
+ if (s.charAt(i) == a.charAt(j)) {
+ i++;
+ j++;
+ } else {
+ if (j == 0) {
+ i++;
+ } else {
+ j = lpsA[j - 1];
+ }
+ }
+ if (j == aLen) {
+ int aStart = i - aLen;
+ matchesA.offer(aStart);
+ j = lpsA[aLen - 1];
+ }
+ }
+ i = j = 0;
+ while (i < n && !matchesA.isEmpty()) {
+ if (s.charAt(i) == b.charAt(j)) {
+ i++;
+ j++;
+ } else {
+ if (j == 0) {
+ i++;
+ } else {
+ j = lpsB[j - 1];
+ }
+ }
+ if (j == bLen) {
+ int bStart = i - bLen;
+ j = lpsB[bLen - 1];
+
+ while (!matchesA.isEmpty() && bStart - matchesA.peek() > k) {
+ matchesA.poll();
+ }
+ while (!matchesA.isEmpty() && Math.abs(matchesA.peek() - bStart) <= k) {
+ ans.add(matchesA.poll());
+ }
+ }
+ }
+ return ans;
+ }
+
+ private int[] getLps(String s) {
+ int n = s.length();
+ int[] lps = new int[n];
+ int i = 1;
+ int prevLps = 0;
+ while (i < n) {
+ if (s.charAt(i) == s.charAt(prevLps)) {
+ prevLps++;
+ lps[i++] = prevLps;
+ } else {
+ if (prevLps == 0) {
+ lps[i++] = 0;
+ } else {
+ prevLps = lps[prevLps - 1];
+ }
+ }
+ }
+ return lps;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/readme.md b/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/readme.md
new file mode 100644
index 000000000..b4169a92b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3008_find_beautiful_indices_in_the_given_array_ii/readme.md
@@ -0,0 +1,41 @@
+3008\. Find Beautiful Indices in the Given Array II
+
+Hard
+
+You are given a **0-indexed** string `s`, a string `a`, a string `b`, and an integer `k`.
+
+An index `i` is **beautiful** if:
+
+* `0 <= i <= s.length - a.length`
+* `s[i..(i + a.length - 1)] == a`
+* There exists an index `j` such that:
+ * `0 <= j <= s.length - b.length`
+ * `s[j..(j + b.length - 1)] == b`
+ * `|j - i| <= k`
+
+Return _the array that contains beautiful indices in **sorted order from smallest to largest**_.
+
+**Example 1:**
+
+**Input:** s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
+
+**Output:** [16,33]
+
+**Explanation:** There are 2 beautiful indices: [16,33].
+- The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
+- The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15. Thus we return [16,33] as the result.
+
+**Example 2:**
+
+**Input:** s = "abcd", a = "a", b = "a", k = 4
+
+**Output:** [0]
+
+**Explanation:** There is 1 beautiful index: [0].
+- The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4. Thus we return [0] as the result.
+
+**Constraints:**
+
+* 1 <= k <= s.length <= 5 * 105
+* 1 <= a.length, b.length <= 5 * 105
+* `s`, `a`, and `b` contain only lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/Solution.java b/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/Solution.java
new file mode 100644
index 000000000..69fd9764f
--- /dev/null
+++ b/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/Solution.java
@@ -0,0 +1,20 @@
+package g3001_3100.s3010_divide_an_array_into_subarrays_with_minimum_cost_i;
+
+// #Easy #Array #Sorting #Enumeration #2024_02_27_Time_1_ms_(99.09%)_Space_43.6_MB_(96.36%)
+
+public class Solution {
+ public int minimumCost(int[] nums) {
+ int first = nums[0];
+ int min = 51;
+ int secMin = 52;
+ for (int i = 1; i < nums.length; i++) {
+ if (nums[i] < min) {
+ secMin = min;
+ min = nums[i];
+ } else if (nums[i] < secMin) {
+ secMin = nums[i];
+ }
+ }
+ return first + min + secMin;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/readme.md b/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/readme.md
new file mode 100644
index 000000000..1f58675ef
--- /dev/null
+++ b/src/main/java/g3001_3100/s3010_divide_an_array_into_subarrays_with_minimum_cost_i/readme.md
@@ -0,0 +1,46 @@
+3010\. Divide an Array Into Subarrays With Minimum Cost I
+
+Easy
+
+You are given an array of integers `nums` of length `n`.
+
+The **cost** of an array is the value of its **first** element. For example, the cost of `[1,2,3]` is `1` while the cost of `[3,4,1]` is `3`.
+
+You need to divide `nums` into `3` **disjoint contiguous** subarrays.
+
+Return _the **minimum** possible **sum** of the cost of these subarrays_.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,12]
+
+**Output:** 6
+
+**Explanation:** The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6. The other possible ways to form 3 subarrays are:
+- [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.
+- [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.
+
+**Example 2:**
+
+**Input:** nums = [5,4,3]
+
+**Output:** 12
+
+**Explanation:** The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.
+
+It can be shown that 12 is the minimum cost achievable.
+
+**Example 3:**
+
+**Input:** nums = [10,3,1,1]
+
+**Output:** 12
+
+**Explanation:** The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.
+
+It can be shown that 12 is the minimum cost achievable.
+
+**Constraints:**
+
+* `3 <= n <= 50`
+* `1 <= nums[i] <= 50`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/Solution.java b/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/Solution.java
new file mode 100644
index 000000000..96b019b61
--- /dev/null
+++ b/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/Solution.java
@@ -0,0 +1,25 @@
+package g3001_3100.s3011_find_if_array_can_be_sorted;
+
+// #Medium #Array #Sorting #Bit_Manipulation #2024_02_27_Time_1_ms_(100.00%)_Space_44.4_MB_(59.99%)
+
+public class Solution {
+ public boolean canSortArray(int[] nums) {
+ int lastGroupMax = Integer.MIN_VALUE;
+ int max = nums[0];
+ int lastBit = Integer.bitCount(nums[0]);
+ for (int i = 1; i < nums.length; i++) {
+ int bit = Integer.bitCount(nums[i]);
+ if (bit == lastBit) {
+ max = Math.max(max, nums[i]);
+ } else {
+ lastGroupMax = max;
+ max = nums[i];
+ lastBit = bit;
+ }
+ if (nums[i] < lastGroupMax) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/readme.md b/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/readme.md
new file mode 100644
index 000000000..d581f8a1e
--- /dev/null
+++ b/src/main/java/g3001_3100/s3011_find_if_array_can_be_sorted/readme.md
@@ -0,0 +1,44 @@
+3011\. Find if Array Can Be Sorted
+
+Medium
+
+You are given a **0-indexed** array of **positive** integers `nums`.
+
+In one **operation**, you can swap any two **adjacent** elements if they have the **same** number of set bits. You are allowed to do this operation **any** number of times (**including zero**).
+
+Return `true` _if you can sort the array, else return_ `false`.
+
+**Example 1:**
+
+**Input:** nums = [8,4,2,30,15]
+
+**Output:** true
+
+**Explanation:** Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation "10", "100", and "1000" respectively. The numbers 15 and 30 have four set bits each with binary representation "1111" and "11110". We can sort the array using 4 operations:
+- Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].
+- Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].
+- Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].
+- Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].
+
+The array has become sorted, hence we return true. Note that there may be other sequences of operations which also sort the array.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** true
+
+**Explanation:** The array is already sorted, hence we return true.
+
+**Example 3:**
+
+**Input:** nums = [3,16,8,4,2]
+
+**Output:** false
+
+**Explanation:** It can be shown that it is not possible to sort the input array using any number of operations.
+
+**Constraints:**
+
+* `1 <= nums.length <= 100`
+* 1 <= nums[i] <= 28
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/Solution.java b/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/Solution.java
new file mode 100644
index 000000000..3942498a6
--- /dev/null
+++ b/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/Solution.java
@@ -0,0 +1,35 @@
+package g3001_3100.s3012_minimize_length_of_array_using_operations;
+
+// #Medium #Array #Math #Greedy #Number_Theory #2024_02_27_Time_2_ms_(96.82%)_Space_58.5_MB_(74.97%)
+
+public class Solution {
+ public int minimumArrayLength(int[] nums) {
+ int min = nums[0];
+ int max = nums[0];
+ for (int i : nums) {
+ if (i < min) {
+ min = i;
+ }
+ if (i > max) {
+ max = i;
+ }
+ }
+ int n = nums.length;
+ if (n == 1) {
+ return 1;
+ }
+ if (max % min != 0) {
+ return 1;
+ }
+ int count = 0;
+ for (int i : nums) {
+ if (i % min != 0 && i % min < min) {
+ return 1;
+ }
+ if (i == min) {
+ count++;
+ }
+ }
+ return (count + 1) / 2;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/readme.md b/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/readme.md
new file mode 100644
index 000000000..df8f8282d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3012_minimize_length_of_array_using_operations/readme.md
@@ -0,0 +1,62 @@
+3012\. Minimize Length of Array Using Operations
+
+Medium
+
+You are given a **0-indexed** integer array `nums` containing **positive** integers.
+
+Your task is to **minimize** the length of `nums` by performing the following operations **any** number of times (including zero):
+
+* Select **two** **distinct** indices `i` and `j` from `nums`, such that `nums[i] > 0` and `nums[j] > 0`.
+* Insert the result of `nums[i] % nums[j]` at the end of `nums`.
+* Delete the elements at indices `i` and `j` from `nums`.
+
+Return _an integer denoting the **minimum** **length** of_ `nums` _after performing the operation any number of times._
+
+**Example 1:**
+
+**Input:** nums = [1,4,3,1]
+
+**Output:** 1
+
+**Explanation:** One way to minimize the length of the array is as follows:
+
+Operation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1. nums becomes [1,1,3].
+
+Operation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2. nums becomes [1,1].
+
+Operation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0. nums becomes [0].
+
+The length of nums cannot be reduced further. Hence, the answer is 1. It can be shown that 1 is the minimum achievable length.
+
+**Example 2:**
+
+**Input:** nums = [5,5,5,10,5]
+
+**Output:** 2
+
+**Explanation:** One way to minimize the length of the array is as follows:
+
+Operation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3. nums becomes [5,5,5,5].
+
+Operation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3. nums becomes [5,5,0].
+
+Operation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1. nums becomes [0,0].
+
+The length of nums cannot be reduced further. Hence, the answer is 2. It can be shown that 2 is the minimum achievable length.
+
+**Example 3:**
+
+**Input:** nums = [2,3,4]
+
+**Output:** 1
+
+**Explanation:** One way to minimize the length of the array is as follows:
+
+Operation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2. nums becomes [2,3].
+
+Operation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0. nums becomes [1]. The length of nums cannot be reduced further. Hence, the answer is 1. It can be shown that 1 is the minimum achievable length.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/Solution.java b/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/Solution.java
new file mode 100644
index 000000000..619e27c1b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/Solution.java
@@ -0,0 +1,59 @@
+package g3001_3100.s3013_divide_an_array_into_subarrays_with_minimum_cost_ii;
+
+// #Hard #Array #Hash_Table #Heap_Priority_Queue #Sliding_Window
+// #2024_02_27_Time_276_ms_(90.86%)_Space_81.5_MB_(5.19%)
+
+import java.util.Comparator;
+import java.util.TreeSet;
+
+public class Solution {
+ public long minimumCost(int[] nums, int k, int dist) {
+ Comparator comparator =
+ (i, j) ->
+ nums[i] == nums[j]
+ ? Integer.compare(i, j)
+ : Integer.compare(nums[i], nums[j]);
+ TreeSet used = new TreeSet<>(comparator);
+ TreeSet unused = new TreeSet<>(comparator);
+ k--;
+ long sum = 0;
+ long n = nums.length;
+ long answer = Long.MAX_VALUE;
+ for (int currentWindow = 1;
+ currentWindow <= Math.min((long) dist + 1, n - 1);
+ currentWindow++) {
+ sum += nums[currentWindow];
+ used.add(currentWindow);
+ }
+ while (used.size() > k) {
+ int largeValueIndex = used.pollLast();
+ sum -= nums[largeValueIndex];
+ unused.add(largeValueIndex);
+ }
+ answer = Math.min(sum, answer);
+ for (int currentWindow = dist + 2, prevWindow = 1;
+ currentWindow < n;
+ currentWindow++, prevWindow++) {
+ unused.add(currentWindow);
+ if (used.contains(prevWindow)) {
+ sum -= nums[prevWindow];
+ used.remove(prevWindow);
+ int smallValueIndex = unused.pollFirst();
+ sum += nums[smallValueIndex];
+ used.add(smallValueIndex);
+ } else {
+ unused.remove(prevWindow);
+ if (nums[used.last()] > nums[unused.first()]) {
+ int largeValueIndex = used.pollLast();
+ sum -= nums[largeValueIndex];
+ unused.add(largeValueIndex);
+ int smallValueIndex = unused.pollFirst();
+ sum += nums[smallValueIndex];
+ used.add(smallValueIndex);
+ }
+ }
+ answer = Math.min(answer, sum);
+ }
+ return nums[0] + answer;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/readme.md b/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/readme.md
new file mode 100644
index 000000000..7f6479b65
--- /dev/null
+++ b/src/main/java/g3001_3100/s3013_divide_an_array_into_subarrays_with_minimum_cost_ii/readme.md
@@ -0,0 +1,58 @@
+3013\. Divide an Array Into Subarrays With Minimum Cost II
+
+Hard
+
+You are given a **0-indexed** array of integers `nums` of length `n`, and two **positive** integers `k` and `dist`.
+
+The **cost** of an array is the value of its **first** element. For example, the cost of `[1,2,3]` is `1` while the cost of `[3,4,1]` is `3`.
+
+You need to divide `nums` into `k` **disjoint contiguous** subarrays, such that the difference between the starting index of the **second** subarray and the starting index of the `kth` subarray should be **less than or equal to** `dist`. In other words, if you divide `nums` into the subarrays nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)], then ik-1 - i1 <= dist.
+
+Return _the **minimum** possible sum of the cost of these_ _subarrays_.
+
+**Example 1:**
+
+**Input:** nums = [1,3,2,6,4,2], k = 3, dist = 3
+
+**Output:** 5
+
+**Explanation:** The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because ik-1 - i1 is 5 - 2 = 3 which is equal to dist.
+
+The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.
+
+It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.
+
+**Example 2:**
+
+**Input:** nums = [10,1,2,2,2,1], k = 4, dist = 3
+
+**Output:** 15
+
+**Explanation:** The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because ik-1 - i1 is 3 - 1 = 2 which is less than dist.
+
+The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.
+
+The division [10], [1], [2,2,2], and [1] is not valid, because the difference between ik-1 and i1 is 5 - 1 = 4, which is greater than dist.
+
+It can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.
+
+**Example 3:**
+
+**Input:** nums = [10,8,18,9], k = 3, dist = 1
+
+**Output:** 36
+
+**Explanation:** The best possible way to divide nums into 4 subarrays is: [10], [8], and [18,9]. This choice is valid because ik-1 - i1 is 2 - 1 = 1 which is equal to dist.
+
+The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.
+
+The division [10], [8,18], and [9] is not valid, because the difference between ik-1 and i1 is 3 - 1 = 2, which is greater than dist.
+
+It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.
+
+**Constraints:**
+
+* 3 <= n <= 105
+* 1 <= nums[i] <= 109
+* `3 <= k <= n`
+* `k - 2 <= dist <= n - 2`
diff --git a/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/Solution.java b/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/Solution.java
new file mode 100644
index 000000000..b03dc25b5
--- /dev/null
+++ b/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/Solution.java
@@ -0,0 +1,26 @@
+package g3001_3100.s3014_minimum_number_of_pushes_to_type_word_i;
+
+// #Easy #String #Math #Greedy #2024_02_28_Time_0_ms_(100.00%)_Space_41.5_MB_(91.88%)
+
+public class Solution {
+ public int minimumPushes(String word) {
+ if (word.length() <= 8) {
+ return word.length();
+ } else {
+ int iteration = 1;
+ int len = word.length();
+ int count = 0;
+ while (len > 0) {
+ if (len >= 8) {
+ count = count + 8 * iteration;
+ len = len - 8;
+ } else {
+ count = count + len * iteration;
+ len = 0;
+ }
+ iteration++;
+ }
+ return count;
+ }
+ }
+}
diff --git a/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/readme.md b/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/readme.md
new file mode 100644
index 000000000..954f38553
--- /dev/null
+++ b/src/main/java/g3001_3100/s3014_minimum_number_of_pushes_to_type_word_i/readme.md
@@ -0,0 +1,79 @@
+3014\. Minimum Number of Pushes to Type Word I
+
+Easy
+
+You are given a string `word` containing **distinct** lowercase English letters.
+
+Telephone keypads have keys mapped with **distinct** collections of lowercase English letters, which can be used to form words by pushing them. For example, the key `2` is mapped with `["a","b","c"]`, we need to push the key one time to type `"a"`, two times to type `"b"`, and three times to type `"c"` _._
+
+It is allowed to remap the keys numbered `2` to `9` to **distinct** collections of letters. The keys can be remapped to **any** amount of letters, but each letter **must** be mapped to **exactly** one key. You need to find the **minimum** number of times the keys will be pushed to type the string `word`.
+
+Return _the **minimum** number of pushes needed to type_ `word` _after remapping the keys_.
+
+An example mapping of letters to keys on a telephone keypad is given below. Note that `1`, `*`, `#`, and `0` do **not** map to any letters.
+
+
+
+**Example 1:**
+
+
+
+**Input:** word = "abcde"
+
+**Output:** 5
+
+**Explanation:** The remapped keypad given in the image provides the minimum cost.
+
+"a" -> one push on key 2
+
+"b" -> one push on key 3
+
+"c" -> one push on key 4
+
+"d" -> one push on key 5
+
+"e" -> one push on key 6
+
+Total cost is 1 + 1 + 1 + 1 + 1 = 5.
+
+It can be shown that no other mapping can provide a lower cost.
+
+**Example 2:**
+
+
+
+**Input:** word = "xycdefghij"
+
+**Output:** 12
+
+**Explanation:** The remapped keypad given in the image provides the minimum cost.
+
+"x" -> one push on key 2
+
+"y" -> two pushes on key 2
+
+"c" -> one push on key 3
+
+"d" -> two pushes on key 3
+
+"e" -> one push on key 4
+
+"f" -> one push on key 5
+
+"g" -> one push on key 6
+
+"h" -> one push on key 7
+
+"i" -> one push on key 8
+
+"j" -> one push on key 9
+
+Total cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.
+
+It can be shown that no other mapping can provide a lower cost.
+
+**Constraints:**
+
+* `1 <= word.length <= 26`
+* `word` consists of lowercase English letters.
+* All letters in `word` are distinct.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/Solution.java b/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/Solution.java
new file mode 100644
index 000000000..a8973d065
--- /dev/null
+++ b/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/Solution.java
@@ -0,0 +1,37 @@
+package g3001_3100.s3015_count_the_number_of_houses_at_a_certain_distance_i;
+
+// #Medium #Breadth_First_Search #Graph #Prefix_Sum
+// #2024_02_28_Time_2_ms_(98.98%)_Space_44.1_MB_(90.10%)
+
+public class Solution {
+ public int[] countOfPairs(int n, int x, int y) {
+ int[] answer = new int[n];
+ int distance = n - 1;
+ int k = distance - 1;
+ while (distance > 0) {
+ answer[k] = (n - distance) * 2;
+ distance--;
+ k--;
+ }
+ if (x > y) {
+ int tmp = x;
+ x = y;
+ y = tmp;
+ }
+ int skip = y - x;
+ if (skip < 2) {
+ return answer;
+ }
+ for (int i = 1; i < n; i++) {
+ for (int j = i + 1; j <= n; j++) {
+ int oldDistance = j - i;
+ int newDistance = Math.abs(x - i) + Math.abs(y - j) + 1;
+ if (newDistance < oldDistance) {
+ answer[oldDistance - 1] -= 2;
+ answer[newDistance - 1] += 2;
+ }
+ }
+ }
+ return answer;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/readme.md b/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/readme.md
new file mode 100644
index 000000000..f525ea6d5
--- /dev/null
+++ b/src/main/java/g3001_3100/s3015_count_the_number_of_houses_at_a_certain_distance_i/readme.md
@@ -0,0 +1,62 @@
+3015\. Count the Number of Houses at a Certain Distance I
+
+Medium
+
+You are given three **positive** integers `n`, `x`, and `y`.
+
+In a city, there exist houses numbered `1` to `n` connected by `n` streets. There is a street connecting the house numbered `i` with the house numbered `i + 1` for all `1 <= i <= n - 1` . An additional street connects the house numbered `x` with the house numbered `y`.
+
+For each `k`, such that `1 <= k <= n`, you need to find the number of **pairs of houses** (house1, house2) such that the **minimum** number of streets that need to be traveled to reach house2 from house1 is `k`.
+
+Return _a **1-indexed** array_ `result` _of length_ `n` _where_ `result[k]` _represents the **total** number of pairs of houses such that the **minimum** streets required to reach one house from the other is_ `k`.
+
+**Note** that `x` and `y` can be **equal**.
+
+**Example 1:**
+
+
+
+**Input:** n = 3, x = 1, y = 3
+
+**Output:** [6,0,0]
+
+**Explanation:** Let's look at each pair of houses:
+- For the pair (1, 2), we can go from house 1 to house 2 directly.
+- For the pair (2, 1), we can go from house 2 to house 1 directly.
+- For the pair (1, 3), we can go from house 1 to house 3 directly.
+- For the pair (3, 1), we can go from house 3 to house 1 directly.
+- For the pair (2, 3), we can go from house 2 to house 3 directly.
+- For the pair (3, 2), we can go from house 3 to house 2 directly.
+
+**Example 2:**
+
+
+
+**Input:** n = 5, x = 2, y = 4
+
+**Output:** [10,8,2,0,0]
+
+**Explanation:** For each distance k the pairs are:
+- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
+- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
+- For k == 3, the pairs are (1, 5), and (5, 1).
+- For k == 4 and k == 5, there are no pairs.
+
+**Example 3:**
+
+
+
+**Input:** n = 4, x = 1, y = 1
+
+**Output:** [6,4,2,0]
+
+**Explanation:** For each distance k the pairs are:
+- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
+- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
+- For k == 3, the pairs are (1, 4), and (4, 1).
+- For k == 4, there are no pairs.
+
+**Constraints:**
+
+* `2 <= n <= 100`
+* `1 <= x, y <= n`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/Solution.java b/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/Solution.java
new file mode 100644
index 000000000..486bca2bc
--- /dev/null
+++ b/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/Solution.java
@@ -0,0 +1,31 @@
+package g3001_3100.s3016_minimum_number_of_pushes_to_type_word_ii;
+
+// #Medium #String #Hash_Table #Sorting #Greedy #Breadth_First_Search #Graph #Prefix_Sum #Counting
+// #2024_02_28_Time_7_ms_(100.00%)_Space_45.5_MB_(91.68%)
+
+public class Solution {
+ public int minimumPushes(String word) {
+ var count = new int[26];
+ var l = word.length();
+ for (var i = 0; i < l; ++i) {
+ ++count[word.charAt(i) - 'a'];
+ }
+ int j = 8;
+ int result = 0;
+ while (true) {
+ var mi = 0;
+ for (var i = 0; i < 26; ++i) {
+ if (count[mi] < count[i]) {
+ mi = i;
+ }
+ }
+ if (count[mi] == 0) {
+ break;
+ }
+ result += (j / 8) * count[mi];
+ count[mi] = 0;
+ ++j;
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/readme.md b/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/readme.md
new file mode 100644
index 000000000..e6e3cdc02
--- /dev/null
+++ b/src/main/java/g3001_3100/s3016_minimum_number_of_pushes_to_type_word_ii/readme.md
@@ -0,0 +1,96 @@
+3016\. Minimum Number of Pushes to Type Word II
+
+Medium
+
+You are given a string `word` containing lowercase English letters.
+
+Telephone keypads have keys mapped with **distinct** collections of lowercase English letters, which can be used to form words by pushing them. For example, the key `2` is mapped with `["a","b","c"]`, we need to push the key one time to type `"a"`, two times to type `"b"`, and three times to type `"c"` _._
+
+It is allowed to remap the keys numbered `2` to `9` to **distinct** collections of letters. The keys can be remapped to **any** amount of letters, but each letter **must** be mapped to **exactly** one key. You need to find the **minimum** number of times the keys will be pushed to type the string `word`.
+
+Return _the **minimum** number of pushes needed to type_ `word` _after remapping the keys_.
+
+An example mapping of letters to keys on a telephone keypad is given below. Note that `1`, `*`, `#`, and `0` do **not** map to any letters.
+
+
+
+**Example 1:**
+
+
+
+**Input:** word = "abcde"
+
+**Output:** 5
+
+**Explanation:** The remapped keypad given in the image provides the minimum cost.
+
+"a" -> one push on key 2
+
+"b" -> one push on key 3
+
+"c" -> one push on key 4
+
+"d" -> one push on key 5
+
+"e" -> one push on key 6
+
+Total cost is 1 + 1 + 1 + 1 + 1 = 5.
+
+It can be shown that no other mapping can provide a lower cost.
+
+**Example 2:**
+
+
+
+**Input:** word = "xyzxyzxyzxyz"
+
+**Output:** 12
+
+**Explanation:** The remapped keypad given in the image provides the minimum cost.
+
+"x" -> one push on key 2
+
+"y" -> one push on key 3
+
+"z" -> one push on key 4 Total cost is 1 * 4 + 1 * 4 + 1 * 4 = 12
+
+It can be shown that no other mapping can provide a lower cost.
+
+Note that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.
+
+**Example 3:**
+
+
+
+**Input:** word = "aabbccddeeffgghhiiiiii"
+
+**Output:** 24
+
+**Explanation:** The remapped keypad given in the image provides the minimum cost.
+
+"a" -> one push on key 2
+
+"b" -> one push on key 3
+
+"c" -> one push on key 4
+
+"d" -> one push on key 5
+
+"e" -> one push on key 6
+
+"f" -> one push on key 7
+
+"g" -> one push on key 8
+
+"h" -> two pushes on key 9
+
+"i" -> one push on key 9
+
+Total cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.
+
+It can be shown that no other mapping can provide a lower cost.
+
+**Constraints:**
+
+* 1 <= word.length <= 105
+* `word` consists of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/Solution.java b/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/Solution.java
new file mode 100644
index 000000000..d2fe1e6cc
--- /dev/null
+++ b/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/Solution.java
@@ -0,0 +1,67 @@
+package g3001_3100.s3017_count_the_number_of_houses_at_a_certain_distance_ii;
+
+// #Hard #Breadth_First_Search #Graph #Prefix_Sum
+// #2024_02_28_Time_6_ms_(93.62%)_Space_60_MB_(56.71%)
+
+public class Solution {
+ public long[] countOfPairs(int n, int x, int y) {
+ long[] result = new long[n];
+ int leftCount = Math.min(x, y) - 1;
+ int rightCount = n - Math.max(x, y);
+ int circleCount = n - leftCount - rightCount;
+ circleInternal(circleCount, result);
+ lineToCircle(leftCount, circleCount, result);
+ lineToCircle(rightCount, circleCount, result);
+ lineToLine(leftCount, rightCount, x == y ? 1 : 2, result);
+ lineInternal(leftCount, result);
+ lineInternal(rightCount, result);
+ return result;
+ }
+
+ private void lineToCircle(int lineCount, int circleCount, long[] curRes) {
+ int circleLen = circleCount / 2 + 1;
+ int curModifier = 0;
+ for (int i = 1; i < circleLen + lineCount; ++i) {
+ if (i <= Math.min(lineCount, circleLen)) {
+ curModifier += 4;
+ } else if (i > Math.max(lineCount, circleLen)) {
+ curModifier -= 4;
+ }
+ curRes[i - 1] += curModifier;
+ if (i <= lineCount) {
+ curRes[i - 1] -= 2;
+ }
+ if (i >= circleLen && circleCount % 2 == 0) {
+ curRes[i - 1] -= 2;
+ }
+ }
+ }
+
+ private void lineToLine(int lineCount1, int lineCount2, int initialDis, long[] curRes) {
+ int curModifier = 0;
+ for (int i = 1; i < lineCount1 + lineCount2; ++i) {
+ if (i <= Math.min(lineCount1, lineCount2)) {
+ curModifier += 2;
+ } else if (i > Math.max(lineCount1, lineCount2)) {
+ curModifier -= 2;
+ }
+ curRes[i - 1 + initialDis] += curModifier;
+ }
+ }
+
+ private void lineInternal(int lineCount, long[] curRes) {
+ for (int i = 1; i < lineCount; ++i) {
+ curRes[i - 1] += (lineCount - i) * 2L;
+ }
+ }
+
+ private void circleInternal(int circleCount, long[] curRes) {
+ for (int i = 0; i < circleCount / 2; ++i) {
+ if (circleCount % 2 == 0 && i + 1 == circleCount / 2) {
+ curRes[i] += circleCount;
+ } else {
+ curRes[i] += circleCount * 2L;
+ }
+ }
+ }
+}
diff --git a/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/readme.md b/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/readme.md
new file mode 100644
index 000000000..1210addc0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3017_count_the_number_of_houses_at_a_certain_distance_ii/readme.md
@@ -0,0 +1,62 @@
+3017\. Count the Number of Houses at a Certain Distance II
+
+Hard
+
+You are given three **positive** integers `n`, `x`, and `y`.
+
+In a city, there exist houses numbered `1` to `n` connected by `n` streets. There is a street connecting the house numbered `i` with the house numbered `i + 1` for all `1 <= i <= n - 1` . An additional street connects the house numbered `x` with the house numbered `y`.
+
+For each `k`, such that `1 <= k <= n`, you need to find the number of **pairs of houses** (house1, house2) such that the **minimum** number of streets that need to be traveled to reach house2 from house1 is `k`.
+
+Return _a **1-indexed** array_ `result` _of length_ `n` _where_ `result[k]` _represents the **total** number of pairs of houses such that the **minimum** streets required to reach one house from the other is_ `k`.
+
+**Note** that `x` and `y` can be **equal**.
+
+**Example 1:**
+
+
+
+**Input:** n = 3, x = 1, y = 3
+
+**Output:** [6,0,0]
+
+**Explanation:** Let's look at each pair of houses:
+- For the pair (1, 2), we can go from house 1 to house 2 directly.
+- For the pair (2, 1), we can go from house 2 to house 1 directly.
+- For the pair (1, 3), we can go from house 1 to house 3 directly.
+- For the pair (3, 1), we can go from house 3 to house 1 directly.
+- For the pair (2, 3), we can go from house 2 to house 3 directly.
+- For the pair (3, 2), we can go from house 3 to house 2 directly.
+
+**Example 2:**
+
+
+
+**Input:** n = 5, x = 2, y = 4
+
+**Output:** [10,8,2,0,0]
+
+**Explanation:** For each distance k the pairs are:
+- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
+- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
+- For k == 3, the pairs are (1, 5), and (5, 1).
+- For k == 4 and k == 5, there are no pairs.
+
+**Example 3:**
+
+
+
+**Input:** n = 4, x = 1, y = 1
+
+**Output:** [6,4,2,0]
+
+**Explanation:** For each distance k the pairs are:
+- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
+- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
+- For k == 3, the pairs are (1, 4), and (4, 1).
+- For k == 4, there are no pairs.
+
+**Constraints:**
+
+* 2 <= n <= 105
+* `1 <= x, y <= n`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3019_number_of_changing_keys/Solution.java b/src/main/java/g3001_3100/s3019_number_of_changing_keys/Solution.java
new file mode 100644
index 000000000..7b69c3ff0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3019_number_of_changing_keys/Solution.java
@@ -0,0 +1,17 @@
+package g3001_3100.s3019_number_of_changing_keys;
+
+// #Easy #String #Breadth_First_Search #Graph #Prefix_Sum
+// #2024_02_28_Time_1_ms_(99.99%)_Space_42_MB_(80.19%)
+
+public class Solution {
+ public int countKeyChanges(String s) {
+ s = s.toLowerCase();
+ int count = 0;
+ for (int i = 0; i < s.length() - 1; i++) {
+ if (s.charAt(i) != s.charAt(i + 1)) {
+ count++;
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3019_number_of_changing_keys/readme.md b/src/main/java/g3001_3100/s3019_number_of_changing_keys/readme.md
new file mode 100644
index 000000000..5e903d177
--- /dev/null
+++ b/src/main/java/g3001_3100/s3019_number_of_changing_keys/readme.md
@@ -0,0 +1,40 @@
+3019\. Number of Changing Keys
+
+Easy
+
+You are given a **0-indexed** string `s` typed by a user. Changing a key is defined as using a key different from the last used key. For example, `s = "ab"` has a change of a key while `s = "bBBb"` does not have any.
+
+Return _the number of times the user had to change the key._
+
+**Note:** Modifiers like `shift` or `caps lock` won't be counted in changing the key that is if a user typed the letter `'a'` and then the letter `'A'` then it will not be considered as a changing of key.
+
+**Example 1:**
+
+**Input:** s = "aAbBcC"
+
+**Output:** 2
+
+**Explanation:**
+
+From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.
+
+From s[1] = 'A' to s[2] = 'b', there is a change of key.
+
+From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.
+
+From s[3] = 'B' to s[4] = 'c', there is a change of key.
+
+From s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.
+
+**Example 2:**
+
+**Input:** s = "AaAaAaaA"
+
+**Output:** 0
+
+**Explanation:** There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.
+
+**Constraints:**
+
+* `1 <= s.length <= 100`
+* `s` consists of only upper case and lower case English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/Solution.java b/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/Solution.java
new file mode 100644
index 000000000..cd1b6048d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/Solution.java
@@ -0,0 +1,48 @@
+package g3001_3100.s3020_find_the_maximum_number_of_elements_in_subset;
+
+// #Medium #Array #Hash_Table #Enumeration #2024_02_29_Time_51_ms_(94.80%)_Space_57_MB_(41.88%)
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Solution {
+ public int maximumLength(int[] nums) {
+ return withHashMap(nums);
+ }
+
+ private int withHashMap(int[] nums) {
+ Map map = new HashMap<>();
+ for (int i : nums) {
+ map.put(i, map.getOrDefault(i, 0) + 1);
+ }
+ int ans = 0;
+ if (map.containsKey(1)) {
+ if (map.get(1) % 2 == 0) {
+ ans = map.get(1) - 1;
+ } else {
+ ans = map.get(1);
+ }
+ }
+ for (int key : map.keySet()) {
+ if (key == 1) {
+ continue;
+ }
+ int len = findSeries(map, key);
+ ans = Math.max(ans, len);
+ }
+ return ans;
+ }
+
+ private int findSeries(Map map, int key) {
+ int sqr = key * key;
+ if (map.containsKey(sqr)) {
+ if (map.get(key) >= 2) {
+ return 2 + findSeries(map, sqr);
+ } else {
+ return 1;
+ }
+ } else {
+ return 1;
+ }
+ }
+}
diff --git a/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/readme.md b/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/readme.md
new file mode 100644
index 000000000..19fa79d6d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3020_find_the_maximum_number_of_elements_in_subset/readme.md
@@ -0,0 +1,32 @@
+3020\. Find the Maximum Number of Elements in Subset
+
+Medium
+
+You are given an array of **positive** integers `nums`.
+
+You need to select a subset of `nums` which satisfies the following condition:
+
+* You can place the selected elements in a **0-indexed** array such that it follows the pattern: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x] (**Note** that `k` can be be any **non-negative** power of `2`). For example, `[2, 4, 16, 4, 2]` and `[3, 9, 3]` follow the pattern while `[2, 4, 8, 4, 2]` does not.
+
+Return _the **maximum** number of elements in a subset that satisfies these conditions._
+
+**Example 1:**
+
+**Input:** nums = [5,4,1,2,2]
+
+**Output:** 3
+
+**Explanation:** We can select the subset {4,2,2}, which can be placed in the array as [2,4,2] which follows the pattern and 22 == 4. Hence the answer is 3.
+
+**Example 2:**
+
+**Input:** nums = [1,3,2,4]
+
+**Output:** 1
+
+**Explanation:** We can select the subset {1}, which can be placed in the array as [1] which follows the pattern. Hence the answer is 1. Note that we could have also selected the subsets {2}, {3}, or {4}, there may be multiple subsets which provide the same answer.
+
+**Constraints:**
+
+* 2 <= nums.length <= 105
+* 1 <= nums[i] <= 109
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/Solution.java b/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/Solution.java
new file mode 100644
index 000000000..aee75a982
--- /dev/null
+++ b/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/Solution.java
@@ -0,0 +1,11 @@
+package g3001_3100.s3021_alice_and_bob_playing_flower_game;
+
+// #Medium #Math #2024_02_29_Time_0_ms_(100.00%)_Space_40.8_MB_(25.85%)
+
+public class Solution {
+ public long flowerGame(long n, long m) {
+ long ans = 0;
+ ans += ((n + 1) / 2) * (m / 2) + ((m + 1) / 2) * (n / 2);
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/readme.md b/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/readme.md
new file mode 100644
index 000000000..0d13550a0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3021_alice_and_bob_playing_flower_game/readme.md
@@ -0,0 +1,39 @@
+3021\. Alice and Bob Playing Flower Game
+
+Medium
+
+Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are `x` flowers in the clockwise direction between Alice and Bob, and `y` flowers in the anti-clockwise direction between them.
+
+The game proceeds as follows:
+
+1. Alice takes the first turn.
+2. In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.
+3. At the end of the turn, if there are no flowers left at all, the **current** player captures their opponent and wins the game.
+
+Given two integers, `n` and `m`, the task is to compute the number of possible pairs `(x, y)` that satisfy the conditions:
+
+* Alice must win the game according to the described rules.
+* The number of flowers `x` in the clockwise direction must be in the range `[1,n]`.
+* The number of flowers `y` in the anti-clockwise direction must be in the range `[1,m]`.
+
+Return _the number of possible pairs_ `(x, y)` _that satisfy the conditions mentioned in the statement_.
+
+**Example 1:**
+
+**Input:** n = 3, m = 2
+
+**Output:** 3
+
+**Explanation:** The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).
+
+**Example 2:**
+
+**Input:** n = 1, m = 1
+
+**Output:** 0
+
+**Explanation:** No pairs satisfy the conditions described in the statement.
+
+**Constraints:**
+
+* 1 <= n, m <= 105
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/Solution.java b/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/Solution.java
new file mode 100644
index 000000000..de7d6454a
--- /dev/null
+++ b/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/Solution.java
@@ -0,0 +1,27 @@
+package g3001_3100.s3022_minimize_or_of_remaining_elements_using_operations;
+
+// #Hard #Array #Greedy #Bit_Manipulation #2024_02_29_Time_43_ms_(78.48%)_Space_56.6_MB_(23.73%)
+
+public class Solution {
+ public int minOrAfterOperations(int[] nums, int k) {
+ int ans = 0;
+ int mask = 0;
+ for (int j = 30; j >= 0; j--) {
+ mask = mask | (1 << j);
+ int consecutiveAnd = mask;
+ int mergeCount = 0;
+ for (int i : nums) {
+ consecutiveAnd = consecutiveAnd & i;
+ if ((consecutiveAnd | ans) != ans) {
+ mergeCount++;
+ } else {
+ consecutiveAnd = mask;
+ }
+ }
+ if (mergeCount > k) {
+ ans |= (1 << j);
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/readme.md b/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/readme.md
new file mode 100644
index 000000000..0284530c8
--- /dev/null
+++ b/src/main/java/g3001_3100/s3022_minimize_or_of_remaining_elements_using_operations/readme.md
@@ -0,0 +1,53 @@
+3022\. Minimize OR of Remaining Elements Using Operations
+
+Hard
+
+You are given a **0-indexed** integer array `nums` and an integer `k`.
+
+In one operation, you can pick any index `i` of `nums` such that `0 <= i < nums.length - 1` and replace `nums[i]` and `nums[i + 1]` with a single occurrence of `nums[i] & nums[i + 1]`, where `&` represents the bitwise `AND` operator.
+
+Return _the **minimum** possible value of the bitwise_ `OR` _of the remaining elements of_ `nums` _after applying **at most**_ `k` _operations_.
+
+**Example 1:**
+
+**Input:** nums = [3,5,3,2,7], k = 2
+
+**Output:** 3
+
+**Explanation:** Let's do the following operations:
+1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [1,3,2,7].
+2. Replace nums[2] and nums[3] with (nums[2] & nums[3]) so that nums becomes equal to [1,3,2].
+
+The bitwise-or of the final array is 3.
+
+It can be shown that 3 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.
+
+**Example 2:**
+
+**Input:** nums = [7,3,15,14,2,8], k = 4
+
+**Output:** 2
+
+**Explanation:** Let's do the following operations:
+1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,15,14,2,8].
+2. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,14,2,8].
+3. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [2,2,8].
+4. Replace nums[1] and nums[2] with (nums[1] & nums[2]) so that nums becomes equal to [2,0].
+
+The bitwise-or of the final array is 2.
+
+It can be shown that 2 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.
+
+**Example 3:**
+
+**Input:** nums = [10,7,10,3,9,14,9,4], k = 1
+
+**Output:** 15
+
+**Explanation:** Without applying any operations, the bitwise-or of nums is 15. It can be shown that 15 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 0 <= nums[i] < 230
+* `0 <= k < nums.length`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3024_type_of_triangle/Solution.java b/src/main/java/g3001_3100/s3024_type_of_triangle/Solution.java
new file mode 100644
index 000000000..a8ae177ba
--- /dev/null
+++ b/src/main/java/g3001_3100/s3024_type_of_triangle/Solution.java
@@ -0,0 +1,20 @@
+package g3001_3100.s3024_type_of_triangle;
+
+// #Easy #Array #Math #Sorting #2024_02_29_Time_0_ms_(100.00%)_Space_41.6_MB_(95.74%)
+
+public class Solution {
+ public String triangleType(int[] nums) {
+ if (nums[0] + nums[1] > nums[2]
+ && nums[1] + nums[2] > nums[0]
+ && nums[2] + nums[0] > nums[1]) {
+ if (nums[0] == nums[1] && nums[1] == nums[2]) {
+ return "equilateral";
+ } else if (nums[0] == nums[1] || nums[0] == nums[2] || nums[2] == nums[1]) {
+ return "isosceles";
+ } else {
+ return "scalene";
+ }
+ }
+ return "none";
+ }
+}
diff --git a/src/main/java/g3001_3100/s3024_type_of_triangle/readme.md b/src/main/java/g3001_3100/s3024_type_of_triangle/readme.md
new file mode 100644
index 000000000..266c81491
--- /dev/null
+++ b/src/main/java/g3001_3100/s3024_type_of_triangle/readme.md
@@ -0,0 +1,42 @@
+3024\. Type of Triangle
+
+Easy
+
+You are given a **0-indexed** integer array `nums` of size `3` which can form the sides of a triangle.
+
+* A triangle is called **equilateral** if it has all sides of equal length.
+* A triangle is called **isosceles** if it has exactly two sides of equal length.
+* A triangle is called **scalene** if all its sides are of different lengths.
+
+Return _a string representing_ _the type of triangle that can be formed_ _or_ `"none"` _if it **cannot** form a triangle._
+
+**Example 1:**
+
+**Input:** nums = [3,3,3]
+
+**Output:** "equilateral"
+
+**Explanation:** Since all the sides are of equal length, therefore, it will form an equilateral triangle.
+
+**Example 2:**
+
+**Input:** nums = [3,4,5]
+
+**Output:** "scalene"
+
+**Explanation:**
+
+nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
+
+nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
+
+nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
+
+Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
+
+As all the sides are of different lengths, it will form a scalene triangle.
+
+**Constraints:**
+
+* `nums.length == 3`
+* `1 <= nums[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/Solution.java b/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/Solution.java
new file mode 100644
index 000000000..b2acb3ceb
--- /dev/null
+++ b/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/Solution.java
@@ -0,0 +1,28 @@
+package g3001_3100.s3025_find_the_number_of_ways_to_place_people_i;
+
+// #Medium #Array #Math #Sorting #Enumeration #Geometry
+// #2024_02_29_Time_5_ms_(99.84%)_Space_44.7_MB_(30.13%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int numberOfPairs(int[][] points) {
+ Arrays.sort(points, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
+ int cnt = 0;
+ for (int i = 0; i < points.length; i++) {
+ int bot = Integer.MIN_VALUE;
+ int top = points[i][1];
+ for (int j = i + 1; j < points.length; j++) {
+ int y1 = points[j][1];
+ if (y1 <= top && y1 > bot) {
+ cnt++;
+ bot = y1;
+ if (y1 == top) {
+ top--;
+ }
+ }
+ }
+ }
+ return cnt;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/readme.md b/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/readme.md
new file mode 100644
index 000000000..72a54bff9
--- /dev/null
+++ b/src/main/java/g3001_3100/s3025_find_the_number_of_ways_to_place_people_i/readme.md
@@ -0,0 +1,69 @@
+3025\. Find the Number of Ways to Place People I
+
+Medium
+
+You are given a 2D array `points` of size `n x 2` representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
+
+We define the **right** direction as positive x-axis (**increasing x-coordinate**) and the **left** direction as negative x-axis (**decreasing x-coordinate**). Similarly, we define the **up** direction as positive y-axis (**increasing y-coordinate**) and the **down** direction as negative y-axis (**decreasing y-coordinate**)
+
+You have to place `n` people, including Alice and Bob, at these points such that there is **exactly one** person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the **upper left corner** and Bob's position as the **lower right corner** of the fence (**Note** that the fence **might not** enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either **inside** the fence or **on** the fence, Alice will be sad.
+
+Return _the number of **pairs of points** where you can place Alice and Bob, such that Alice **does not** become sad on building the fence_.
+
+**Note** that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners `(1, 1)`, `(1, 3)`, `(3, 1)`, and `(3, 3)`, because:
+
+* With Alice at `(3, 3)` and Bob at `(1, 1)`, Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.
+* With Alice at `(1, 3)` and Bob at `(1, 1)`, Bob's position is not the lower right corner of the fence.
+
+
+
+**Example 1:**
+
+
+
+**Input:** points = [[1,1],[2,2],[3,3]]
+
+**Output:** 0
+
+**Explanation:** There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.
+
+**Example 2:**
+
+
+
+**Input:** points = [[6,2],[4,4],[2,6]]
+
+**Output:** 2
+
+**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
+
+- Place Alice at (4, 4) and Bob at (6, 2).
+
+- Place Alice at (2, 6) and Bob at (4, 4).
+
+You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.
+
+**Example 3:**
+
+
+
+**Input:** points = [[3,1],[1,3],[1,1]]
+
+**Output:** 2
+
+**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
+
+- Place Alice at (1, 1) and Bob at (3, 1).
+
+- Place Alice at (1, 3) and Bob at (1, 1).
+
+You cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.
+
+Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
+
+**Constraints:**
+
+* `2 <= n <= 50`
+* `points[i].length == 2`
+* `0 <= points[i][0], points[i][1] <= 50`
+* All `points[i]` are distinct.
diff --git a/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/Solution.java b/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/Solution.java
new file mode 100644
index 000000000..91892c1f4
--- /dev/null
+++ b/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/Solution.java
@@ -0,0 +1,40 @@
+package g3001_3100.s3026_maximum_good_subarray_sum;
+
+// #Medium #Array #Hash_Table #Prefix_Sum #2024_03_01_Time_62_ms_(93.52%)_Space_56.2_MB_(95.77%)
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Solution {
+ private static final int NO_GOOD_SUBARRAYS = 0;
+
+ public long maximumSubarraySum(int[] input, int targetDifference) {
+ Map valueToMinPrefixSum = new HashMap<>();
+ long prefixSum = 0;
+ long maxSubarraySum = Long.MIN_VALUE;
+ for (int value : input) {
+ if (valueToMinPrefixSum.containsKey(value + targetDifference)) {
+ maxSubarraySum =
+ Math.max(
+ maxSubarraySum,
+ prefixSum
+ + value
+ - valueToMinPrefixSum.get(value + targetDifference));
+ }
+ if (valueToMinPrefixSum.containsKey(value - targetDifference)) {
+ maxSubarraySum =
+ Math.max(
+ maxSubarraySum,
+ prefixSum
+ + value
+ - valueToMinPrefixSum.get(value - targetDifference));
+ }
+ if (!valueToMinPrefixSum.containsKey(value)
+ || valueToMinPrefixSum.get(value) > prefixSum) {
+ valueToMinPrefixSum.put(value, prefixSum);
+ }
+ prefixSum += value;
+ }
+ return maxSubarraySum != Long.MIN_VALUE ? maxSubarraySum : NO_GOOD_SUBARRAYS;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/readme.md b/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/readme.md
new file mode 100644
index 000000000..1f2b8f711
--- /dev/null
+++ b/src/main/java/g3001_3100/s3026_maximum_good_subarray_sum/readme.md
@@ -0,0 +1,39 @@
+3026\. Maximum Good Subarray Sum
+
+Medium
+
+You are given an array `nums` of length `n` and a **positive** integer `k`.
+
+A subarray of `nums` is called **good** if the **absolute difference** between its first and last element is **exactly** `k`, in other words, the subarray `nums[i..j]` is good if `|nums[i] - nums[j]| == k`.
+
+Return _the **maximum** sum of a **good** subarray of_ `nums`. _If there are no good subarrays__, return_ `0`.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5,6], k = 1
+
+**Output:** 11
+
+**Explanation:** The absolute difference between the first and last element must be 1 for a good subarray. All the good subarrays are: [1,2], [2,3], [3,4], [4,5], and [5,6]. The maximum subarray sum is 11 for the subarray [5,6].
+
+**Example 2:**
+
+**Input:** nums = [-1,3,2,4,5], k = 3
+
+**Output:** 11
+
+**Explanation:** The absolute difference between the first and last element must be 3 for a good subarray. All the good subarrays are: [-1,3,2], and [2,4,5]. The maximum subarray sum is 11 for the subarray [2,4,5].
+
+**Example 3:**
+
+**Input:** nums = [-1,-2,-3,-4], k = 2
+
+**Output:** -6
+
+**Explanation:** The absolute difference between the first and last element must be 2 for a good subarray. All the good subarrays are: [-1,-2,-3], and [-2,-3,-4]. The maximum subarray sum is -6 for the subarray [-1,-2,-3].
+
+**Constraints:**
+
+* 2 <= nums.length <= 105
+* -109 <= nums[i] <= 109
+* 1 <= k <= 109
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/Solution.java b/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/Solution.java
new file mode 100644
index 000000000..9213c6042
--- /dev/null
+++ b/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/Solution.java
@@ -0,0 +1,30 @@
+package g3001_3100.s3027_find_the_number_of_ways_to_place_people_ii;
+
+// #Hard #Array #Math #Sorting #Enumeration #Geometry
+// #2024_03_01_Time_59_ms_(69.95%)_Space_45.3_MB_(20.75%)
+
+import java.util.Arrays;
+
+public class Solution {
+ private int customCompare(int[] p1, int[] p2) {
+ if (p1[0] != p2[0]) {
+ return Integer.signum(p1[0] - p2[0]);
+ }
+ return Integer.signum(p2[1] - p1[1]);
+ }
+
+ public int numberOfPairs(int[][] points) {
+ Arrays.sort(points, this::customCompare);
+ int count = 0;
+ for (int i = 0; i < points.length; ++i) {
+ int m = Integer.MIN_VALUE;
+ for (int j = i + 1; j < points.length; ++j) {
+ if ((points[i][1] >= points[j][1]) && (points[j][1] > m)) {
+ m = points[j][1];
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/readme.md b/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/readme.md
new file mode 100644
index 000000000..ce6fb7dfb
--- /dev/null
+++ b/src/main/java/g3001_3100/s3027_find_the_number_of_ways_to_place_people_ii/readme.md
@@ -0,0 +1,63 @@
+3027\. Find the Number of Ways to Place People II
+
+Hard
+
+You are given a 2D array `points` of size `n x 2` representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
+
+We define the **right** direction as positive x-axis (**increasing x-coordinate**) and the **left** direction as negative x-axis (**decreasing x-coordinate**). Similarly, we define the **up** direction as positive y-axis (**increasing y-coordinate**) and the **down** direction as negative y-axis (**decreasing y-coordinate**)
+
+You have to place `n` people, including Alice and Bob, at these points such that there is **exactly one** person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the **upper left corner** and Bob's position as the **lower right corner** of the fence (**Note** that the fence **might not** enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either **inside** the fence or **on** the fence, Alice will be sad.
+
+Return _the number of **pairs of points** where you can place Alice and Bob, such that Alice **does not** become sad on building the fence_.
+
+**Note** that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners `(1, 1)`, `(1, 3)`, `(3, 1)`, and `(3, 3)`, because:
+
+* With Alice at `(3, 3)` and Bob at `(1, 1)`, Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.
+* With Alice at `(1, 3)` and Bob at `(1, 1)`, Bob's position is not the lower right corner of the fence.
+
+
+
+**Example 1:**
+
+
+
+**Input:** points = [[1,1],[2,2],[3,3]]
+
+**Output:** 0
+
+**Explanation:** There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.
+
+**Example 2:**
+
+
+
+**Input:** points = [[6,2],[4,4],[2,6]]
+
+**Output:** 2
+
+**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
+- Place Alice at (4, 4) and Bob at (6, 2).
+- Place Alice at (2, 6) and Bob at (4, 4). You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.
+
+**Example 3:**
+
+
+
+**Input:** points = [[3,1],[1,3],[1,1]]
+
+**Output:** 2
+
+**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
+- Place Alice at (1, 1) and Bob at (3, 1).
+- Place Alice at (1, 3) and Bob at (1, 1).
+
+You cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.
+
+Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
+
+**Constraints:**
+
+* `2 <= n <= 1000`
+* `points[i].length == 2`
+* -109 <= points[i][0], points[i][1] <= 109
+* All `points[i]` are distinct.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3028_ant_on_the_boundary/Solution.java b/src/main/java/g3001_3100/s3028_ant_on_the_boundary/Solution.java
new file mode 100644
index 000000000..bd7d423ab
--- /dev/null
+++ b/src/main/java/g3001_3100/s3028_ant_on_the_boundary/Solution.java
@@ -0,0 +1,17 @@
+package g3001_3100.s3028_ant_on_the_boundary;
+
+// #Easy #Array #Simulation #Prefix_Sum #2024_03_01_Time_0_ms_(100.00%)_Space_42.1_MB_(53.10%)
+
+public class Solution {
+ public int returnToBoundaryCount(int[] nums) {
+ int ans = 0;
+ int num = 0;
+ for (int n : nums) {
+ num += n;
+ if (num == 0) {
+ ans++;
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3028_ant_on_the_boundary/readme.md b/src/main/java/g3001_3100/s3028_ant_on_the_boundary/readme.md
new file mode 100644
index 000000000..f29a25636
--- /dev/null
+++ b/src/main/java/g3001_3100/s3028_ant_on_the_boundary/readme.md
@@ -0,0 +1,51 @@
+3028\. Ant on the Boundary
+
+Easy
+
+An ant is on a boundary. It sometimes goes **left** and sometimes **right**.
+
+You are given an array of **non-zero** integers `nums`. The ant starts reading `nums` from the first element of it to its end. At each step, it moves according to the value of the current element:
+
+* If `nums[i] < 0`, it moves **left** by `-nums[i]` units.
+* If `nums[i] > 0`, it moves **right** by `nums[i]` units.
+
+Return _the number of times the ant **returns** to the boundary._
+
+**Notes:**
+
+* There is an infinite space on both sides of the boundary.
+* We check whether the ant is on the boundary only after it has moved `|nums[i]|` units. In other words, if the ant crosses the boundary during its movement, it does not count.
+
+**Example 1:**
+
+**Input:** nums = [2,3,-5]
+
+**Output:** 1
+
+**Explanation:** After the first step, the ant is 2 steps to the right of the boundary.
+
+After the second step, the ant is 5 steps to the right of the boundary.
+
+After the third step, the ant is on the boundary. So the answer is 1.
+
+**Example 2:**
+
+**Input:** nums = [3,2,-3,-4]
+
+**Output:** 0
+
+**Explanation:** After the first step, the ant is 3 steps to the right of the boundary.
+
+After the second step, the ant is 5 steps to the right of the boundary.
+
+After the third step, the ant is 2 steps to the right of the boundary.
+
+After the fourth step, the ant is 2 steps to the left of the boundary.
+
+The ant never returned to the boundary, so the answer is 0.
+
+**Constraints:**
+
+* `1 <= nums.length <= 100`
+* `-10 <= nums[i] <= 10`
+* `nums[i] != 0`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/Solution.java b/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/Solution.java
new file mode 100644
index 000000000..9ed854150
--- /dev/null
+++ b/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/Solution.java
@@ -0,0 +1,16 @@
+package g3001_3100.s3029_minimum_time_to_revert_word_to_initial_state_i;
+
+// #Medium #String #Hash_Function #String_Matching #Rolling_Hash
+// #2024_03_01_Time_1_ms_(99.70%)_Space_42.7_MB_(8.42%)
+
+public class Solution {
+ public int minimumTimeToInitialState(String word, int k) {
+ int n = word.length();
+ for (int i = k; i < n; i += k) {
+ if (word.substring(i, n).equals(word.substring(0, n - i))) {
+ return i / k;
+ }
+ }
+ return (n + k - 1) / k;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/readme.md b/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/readme.md
new file mode 100644
index 000000000..aa00886c9
--- /dev/null
+++ b/src/main/java/g3001_3100/s3029_minimum_time_to_revert_word_to_initial_state_i/readme.md
@@ -0,0 +1,44 @@
+3029\. Minimum Time to Revert Word to Initial State I
+
+Medium
+
+You are given a **0-indexed** string `word` and an integer `k`.
+
+At every second, you must perform the following operations:
+
+* Remove the first `k` characters of `word`.
+* Add any `k` characters to the end of `word`.
+
+**Note** that you do not necessarily need to add the same characters that you removed. However, you must perform **both** operations at every second.
+
+Return _the **minimum** time greater than zero required for_ `word` _to revert to its **initial** state_.
+
+**Example 1:**
+
+**Input:** word = "abacaba", k = 3
+
+**Output:** 2
+
+**Explanation:** At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac". At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state. It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.
+
+**Example 2:**
+
+**Input:** word = "abacaba", k = 4
+
+**Output:** 1
+
+**Explanation:** At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state. It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.
+
+**Example 3:**
+
+**Input:** word = "abcbabcd", k = 2
+
+**Output:** 4
+
+**Explanation:** At every second, we will remove the first 2 characters of word, and add the same characters to the end of word. After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state. It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.
+
+**Constraints:**
+
+* `1 <= word.length <= 50`
+* `1 <= k <= word.length`
+* `word` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/Solution.java b/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/Solution.java
new file mode 100644
index 000000000..8666e5183
--- /dev/null
+++ b/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/Solution.java
@@ -0,0 +1,65 @@
+package g3001_3100.s3030_find_the_grid_of_region_average;
+
+// #Medium #Array #Matrix #2024_03_01_Time_53_ms_(98.79%)_Space_88.4_MB_(35.20%)
+
+public class Solution {
+ public int[][] resultGrid(int[][] image, int threshold) {
+ int n = image.length;
+ int m = image[0].length;
+ int[][] intensity = new int[n][m];
+ int[][] count = new int[n][m];
+ for (int i = 1; i < n - 1; i++) {
+ for (int j = 1; j < m - 1; j++) {
+ boolean regionPossible = true;
+ int regionSum = 0;
+ int r0c0 = image[i - 1][j - 1];
+ int r0c1 = image[i - 1][j];
+ int r0c2 = image[i - 1][j + 1];
+ int r1c0 = image[i][j - 1];
+ int r1c1 = image[i][j];
+ int r1c2 = image[i][j + 1];
+ int r2c0 = image[i + 1][j - 1];
+ int r2c1 = image[i + 1][j];
+ int r2c2 = image[i + 1][j + 1];
+ regionSum += (r0c0 + r0c1 + r0c2 + r1c0 + r1c1 + r1c2 + r2c0 + r2c1 + r2c2);
+ if (Math.abs(r0c0 - r0c1) > threshold
+ || Math.abs(r0c0 - r1c0) > threshold
+ || Math.abs(r0c1 - r0c0) > threshold
+ || Math.abs(r0c1 - r1c1) > threshold
+ || Math.abs(r0c1 - r0c2) > threshold
+ || Math.abs(r0c2 - r0c1) > threshold
+ || Math.abs(r0c2 - r1c2) > threshold
+ || Math.abs(r1c0 - r1c1) > threshold
+ || Math.abs(r1c2 - r1c1) > threshold
+ || Math.abs(r2c0 - r2c1) > threshold
+ || Math.abs(r2c0 - r1c0) > threshold
+ || Math.abs(r2c1 - r2c0) > threshold
+ || Math.abs(r2c1 - r1c1) > threshold
+ || Math.abs(r2c1 - r2c2) > threshold
+ || Math.abs(r2c2 - r2c1) > threshold
+ || Math.abs(r2c2 - r1c2) > threshold) {
+ regionPossible = false;
+ }
+ if (regionPossible) {
+ regionSum /= 9;
+ for (int k = -1; k <= 1; k++) {
+ for (int l = -1; l <= 1; l++) {
+ intensity[i + k][j + l] += regionSum;
+ count[i + k][j + l]++;
+ }
+ }
+ }
+ }
+ }
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < m; j++) {
+ if (count[i][j] == 0) {
+ intensity[i][j] = image[i][j];
+ } else {
+ intensity[i][j] = intensity[i][j] / count[i][j];
+ }
+ }
+ }
+ return intensity;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/readme.md b/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/readme.md
new file mode 100644
index 000000000..08553737b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3030_find_the_grid_of_region_average/readme.md
@@ -0,0 +1,49 @@
+3030\. Find the Grid of Region Average
+
+Medium
+
+You are given a **0-indexed** `m x n` grid `image` which represents a grayscale image, where `image[i][j]` represents a pixel with intensity in the range`[0..255]`. You are also given a **non-negative** integer `threshold`.
+
+Two pixels `image[a][b]` and `image[c][d]` are said to be **adjacent** if `|a - c| + |b - d| == 1`.
+
+A **region** is a `3 x 3` subgrid where the **absolute difference** in intensity between any two **adjacent** pixels is **less than or equal to** `threshold`.
+
+All pixels in a **region** belong to that region, note that a pixel **can** belong to **multiple** regions.
+
+You need to calculate a **0-indexed** `m x n` grid `result`, where `result[i][j]` is the **average** intensity of the region to which `image[i][j]` belongs, **rounded down** to the nearest integer. If `image[i][j]` belongs to multiple regions, `result[i][j]` is the **average** of the **rounded down average** intensities of these regions, **rounded down** to the nearest integer. If `image[i][j]` does **not** belong to any region, `result[i][j]` is **equal to** `image[i][j]`.
+
+Return _the grid_ `result`.
+
+**Example 1:**
+
+
+
+**Input:** image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3
+
+**Output:** [[9,9,9,9],[9,9,9,9],[9,9,9,9]]
+
+**Explanation:** There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9. Please note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.
+
+**Example 2:**
+
+
+
+**Input:** image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12
+
+**Output:** [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]
+
+**Explanation:** There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27. All the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.
+
+**Example 3:**
+
+**Input:** image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1
+
+**Output:** [[5,6,7],[8,9,10],[11,12,13]]
+
+**Explanation:** There does not exist any region in image, hence result[i][j] == image[i][j] for all the pixels.
+
+**Constraints:**
+
+* `3 <= n, m <= 500`
+* `0 <= image[i][j] <= 255`
+* `0 <= threshold <= 255`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/Solution.java b/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/Solution.java
new file mode 100644
index 000000000..8fcd79b14
--- /dev/null
+++ b/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/Solution.java
@@ -0,0 +1,33 @@
+package g3001_3100.s3031_minimum_time_to_revert_word_to_initial_state_ii;
+
+// #Hard #String #Hash_Function #String_Matching #Rolling_Hash
+// #2024_03_01_Time_24_ms_(74.98%)_Space_55.1_MB_(14.85%)
+
+public class Solution {
+ public int minimumTimeToInitialState(String w, int q) {
+ char[] c = w.toCharArray();
+ int[] lps = new int[c.length];
+ int k;
+ for (int i = 1; i < lps.length; i++) {
+ if (c[i] == c[0]) {
+ lps[i] = 1;
+ }
+ k = lps[i - 1];
+ while (k > 0) {
+ if (c[k] == c[i]) {
+ lps[i] = k + 1;
+ break;
+ }
+ k = lps[k - 1];
+ }
+ }
+ k = lps[lps.length - 1];
+ while (k > 0) {
+ if ((c.length - k) % q == 0) {
+ return (c.length - k) / q;
+ }
+ k = lps[k - 1];
+ }
+ return (c.length + q - 1) / q;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/readme.md b/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/readme.md
new file mode 100644
index 000000000..23b25239d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3031_minimum_time_to_revert_word_to_initial_state_ii/readme.md
@@ -0,0 +1,50 @@
+3031\. Minimum Time to Revert Word to Initial State II
+
+Hard
+
+You are given a **0-indexed** string `word` and an integer `k`.
+
+At every second, you must perform the following operations:
+
+* Remove the first `k` characters of `word`.
+* Add any `k` characters to the end of `word`.
+
+**Note** that you do not necessarily need to add the same characters that you removed. However, you must perform **both** operations at every second.
+
+Return _the **minimum** time greater than zero required for_ `word` _to revert to its **initial** state_.
+
+**Example 1:**
+
+**Input:** word = "abacaba", k = 3
+
+**Output:** 2
+
+**Explanation:** At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac". At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
+
+It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.
+
+**Example 2:**
+
+**Input:** word = "abacaba", k = 4
+
+**Output:** 1
+
+**Explanation:** At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
+
+It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.
+
+**Example 3:**
+
+**Input:** word = "abcbabcd", k = 2
+
+**Output:** 4
+
+**Explanation:** At every second, we will remove the first 2 characters of word, and add the same characters to the end of word. After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state.
+
+It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.
+
+**Constraints:**
+
+* 1 <= word.length <= 106
+* `1 <= k <= word.length`
+* `word` consists only of lowercase English letters.
diff --git a/src/main/java/g3001_3100/s3033_modify_the_matrix/Solution.java b/src/main/java/g3001_3100/s3033_modify_the_matrix/Solution.java
new file mode 100644
index 000000000..a6ab0f6c8
--- /dev/null
+++ b/src/main/java/g3001_3100/s3033_modify_the_matrix/Solution.java
@@ -0,0 +1,22 @@
+package g3001_3100.s3033_modify_the_matrix;
+
+// #Easy #Array #Matrix #2024_03_01_Time_1_ms_(100.00%)_Space_45.4_MB_(77.37%)
+
+public class Solution {
+ public int[][] modifiedMatrix(int[][] matrix) {
+ for (int i = 0; i < matrix.length; i++) {
+ for (int j = 0; j < matrix[0].length; j++) {
+ if (matrix[i][j] == -1) {
+ int y = 0;
+ for (int[] ints : matrix) {
+ if (ints[j] > y) {
+ y = ints[j];
+ }
+ }
+ matrix[i][j] = y;
+ }
+ }
+ }
+ return matrix;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3033_modify_the_matrix/readme.md b/src/main/java/g3001_3100/s3033_modify_the_matrix/readme.md
new file mode 100644
index 000000000..7b40e52fd
--- /dev/null
+++ b/src/main/java/g3001_3100/s3033_modify_the_matrix/readme.md
@@ -0,0 +1,37 @@
+3033\. Modify the Matrix
+
+Easy
+
+Given a **0-indexed** `m x n` integer matrix `matrix`, create a new **0-indexed** matrix called `answer`. Make `answer` equal to `matrix`, then replace each element with the value `-1` with the **maximum** element in its respective column.
+
+Return _the matrix_ `answer`.
+
+**Example 1:**
+
+
+
+**Input:** matrix = [[1,2,-1],[4,-1,6],[7,8,9]]
+
+**Output:** [[1,2,9],[4,8,6],[7,8,9]]
+
+**Explanation:** The diagram above shows the elements that are changed (in blue).
+- We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8.
+- We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9.
+
+**Example 2:**
+
+
+
+**Input:** matrix = [[3,-1],[5,2]]
+
+**Output:** [[3,2],[5,2]]
+
+**Explanation:** The diagram above shows the elements that are changed (in blue).
+
+**Constraints:**
+
+* `m == matrix.length`
+* `n == matrix[i].length`
+* `2 <= m, n <= 50`
+* `-1 <= matrix[i][j] <= 100`
+* The input is generated such that each column contains at least one non-negative integer.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/Solution.java b/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/Solution.java
new file mode 100644
index 000000000..a26ad85e5
--- /dev/null
+++ b/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/Solution.java
@@ -0,0 +1,30 @@
+package g3001_3100.s3034_number_of_subarrays_that_match_a_pattern_i;
+
+// #Medium #Array #Hash_Function #String_Matching #Rolling_Hash
+// #2024_03_01_Time_1_ms_(100.00%)_Space_43.9_MB_(97.20%)
+
+public class Solution {
+ public int countMatchingSubarrays(int[] nums, int[] pattern) {
+ int n = nums.length;
+ int m = pattern.length;
+ int count = 0;
+ for (int i = 0; i <= n - m - 1; i++) {
+ int k = 0;
+ while (k < m) {
+ if (nums[i + k + 1] > nums[i + k] && pattern[k] == 1) {
+ k++;
+ } else if (nums[i + k + 1] == nums[i + k] && pattern[k] == 0) {
+ k++;
+ } else if (nums[i + k + 1] < nums[i + k] && pattern[k] == -1) {
+ k++;
+ } else {
+ break;
+ }
+ }
+ if (k == m) {
+ count++;
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/readme.md b/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/readme.md
new file mode 100644
index 000000000..0b4e7b8e3
--- /dev/null
+++ b/src/main/java/g3001_3100/s3034_number_of_subarrays_that_match_a_pattern_i/readme.md
@@ -0,0 +1,40 @@
+3034\. Number of Subarrays That Match a Pattern I
+
+Medium
+
+You are given a **0-indexed** integer array `nums` of size `n`, and a **0-indexed** integer array `pattern` of size `m` consisting of integers `-1`, `0`, and `1`.
+
+A subarray `nums[i..j]` of size `m + 1` is said to match the `pattern` if the following conditions hold for each element `pattern[k]`:
+
+* `nums[i + k + 1] > nums[i + k]` if `pattern[k] == 1`.
+* `nums[i + k + 1] == nums[i + k]` if `pattern[k] == 0`.
+* `nums[i + k + 1] < nums[i + k]` if `pattern[k] == -1`.
+
+Return _the **count** of subarrays in_ `nums` _that match the_ `pattern`.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5,6], pattern = [1,1]
+
+**Output:** 4
+
+**Explanation:** The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.
+
+Hence, there are 4 subarrays in nums that match the pattern.
+
+**Example 2:**
+
+**Input:** nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]
+
+**Output:** 2
+
+**Explanation:** Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.
+
+Hence, there are 2 subarrays in nums that match the pattern.
+
+**Constraints:**
+
+* `2 <= n == nums.length <= 100`
+* 1 <= nums[i] <= 109
+* `1 <= m == pattern.length < n`
+* `-1 <= pattern[i] <= 1`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/Solution.java b/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/Solution.java
new file mode 100644
index 000000000..0211d5e7b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/Solution.java
@@ -0,0 +1,51 @@
+package g3001_3100.s3035_maximum_palindromes_after_operations;
+
+// #Medium #Array #String #Hash_Table #Sorting #Greedy #Counting
+// #2024_03_01_Time_4_ms_(99.13%)_Space_44.9_MB_(90.28%)
+
+public class Solution {
+ public int maxPalindromesAfterOperations(String[] words) {
+ int[] ar = new int[26];
+ int[] dp = new int[101];
+ int s = 0;
+ int p = 0;
+ int ans = 0;
+ for (String str : words) {
+ for (char c : str.toCharArray()) {
+ ar[c - 'a']++;
+ }
+ dp[str.length()]++;
+ }
+ for (int j : ar) {
+ s += j % 2;
+ p += (j / 2);
+ }
+ for (int i = 1; i < dp.length; i++) {
+ if (dp[i] > 0) {
+ if (i % 2 == 0) {
+ while (dp[i] > 0 && p > 0) {
+ p -= i / 2;
+ if (p >= 0) {
+ ans++;
+ }
+ dp[i]--;
+ }
+ } else {
+ while (dp[i] > 0 && (i == 1 || p > 0)) {
+ if (s == 0) {
+ s += 2;
+ p--;
+ }
+ s--;
+ p -= (i - 1) / 2;
+ if (p >= 0) {
+ ans++;
+ }
+ dp[i]--;
+ }
+ }
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/readme.md b/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/readme.md
new file mode 100644
index 000000000..0fb8e076f
--- /dev/null
+++ b/src/main/java/g3001_3100/s3035_maximum_palindromes_after_operations/readme.md
@@ -0,0 +1,53 @@
+3035\. Maximum Palindromes After Operations
+
+Medium
+
+You are given a **0-indexed** string array `words` having length `n` and containing **0-indexed** strings.
+
+You are allowed to perform the following operation **any** number of times (**including** **zero**):
+
+* Choose integers `i`, `j`, `x`, and `y` such that `0 <= i, j < n`, `0 <= x < words[i].length`, `0 <= y < words[j].length`, and **swap** the characters `words[i][x]` and `words[j][y]`.
+
+Return _an integer denoting the **maximum** number of palindromes_ `words` _can contain, after performing some operations._
+
+**Note:** `i` and `j` may be equal during an operation.
+
+**Example 1:**
+
+**Input:** words = ["abbb","ba","aa"]
+
+**Output:** 3
+
+**Explanation:** In this example, one way to get the maximum number of palindromes is:
+
+Choose i = 0, j = 1, x = 0, y = 0, so we swap words[0][0] and words[1][0]. words becomes ["bbbb","aa","aa"].
+
+All strings in words are now palindromes. Hence, the maximum number of palindromes achievable is 3.
+
+**Example 2:**
+
+**Input:** words = ["abc","ab"]
+
+**Output:** 2
+
+**Explanation:** In this example, one way to get the maximum number of palindromes is:
+
+Choose i = 0, j = 1, x = 1, y = 0, so we swap words[0][1] and words[1][0]. words becomes ["aac","bb"].
+
+Choose i = 0, j = 0, x = 1, y = 2, so we swap words[0][1] and words[0][2]. words becomes ["aca","bb"].
+
+Both strings are now palindromes. Hence, the maximum number of palindromes achievable is 2.
+
+**Example 3:**
+
+**Input:** words = ["cd","ef","a"]
+
+**Output:** 1
+
+**Explanation:** In this example, there is no need to perform any operation. There is one palindrome in words "a". It can be shown that it is not possible to get more than one palindrome after any number of operations. Hence, the answer is 1.
+
+**Constraints:**
+
+* `1 <= words.length <= 1000`
+* `1 <= words[i].length <= 100`
+* `words[i]` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/Solution.java b/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/Solution.java
new file mode 100644
index 000000000..df24f8d37
--- /dev/null
+++ b/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/Solution.java
@@ -0,0 +1,38 @@
+package g3001_3100.s3036_number_of_subarrays_that_match_a_pattern_ii;
+
+// #Hard #Array #Hash_Function #String_Matching #Rolling_Hash
+// #2024_03_01_Time_5_ms_(98.27%)_Space_172.1_MB_(75.77%)
+
+public class Solution {
+ public int countMatchingSubarrays(int[] nums, int[] pattern) {
+ int n = nums.length;
+ int m = pattern.length;
+ int[] arr = new int[n - 1];
+ for (int i = 0; i < n - 1; i++) {
+ if (nums[i + 1] > nums[i]) {
+ arr[i] = 1;
+ } else if (nums[i + 1] < nums[i]) {
+ arr[i] = -1;
+ }
+ }
+ int hash = 0;
+ int pHash = 0;
+ int base = 1;
+ for (int i = 0; i < m; i++) {
+ hash = hash * 3 + arr[i] + 1;
+ pHash = pHash * 3 + pattern[i] + 1;
+ base *= 3;
+ }
+ int count = 0;
+ for (int i = 0; i <= n - 1 - m; i++) {
+ if (hash == pHash) {
+ count++;
+ }
+
+ if (i < n - 1 - m) {
+ hash = hash * 3 - base * (arr[i] + 1) + arr[i + m] + 1;
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/readme.md b/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/readme.md
new file mode 100644
index 000000000..f19200958
--- /dev/null
+++ b/src/main/java/g3001_3100/s3036_number_of_subarrays_that_match_a_pattern_ii/readme.md
@@ -0,0 +1,36 @@
+3036\. Number of Subarrays That Match a Pattern II
+
+Hard
+
+You are given a **0-indexed** integer array `nums` of size `n`, and a **0-indexed** integer array `pattern` of size `m` consisting of integers `-1`, `0`, and `1`.
+
+A subarray `nums[i..j]` of size `m + 1` is said to match the `pattern` if the following conditions hold for each element `pattern[k]`:
+
+* `nums[i + k + 1] > nums[i + k]` if `pattern[k] == 1`.
+* `nums[i + k + 1] == nums[i + k]` if `pattern[k] == 0`.
+* `nums[i + k + 1] < nums[i + k]` if `pattern[k] == -1`.
+
+Return _the **count** of subarrays in_ `nums` _that match the_ `pattern`.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5,6], pattern = [1,1]
+
+**Output:** 4
+
+**Explanation:** The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern. Hence, there are 4 subarrays in nums that match the pattern.
+
+**Example 2:**
+
+**Input:** nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]
+
+**Output:** 2
+
+**Explanation:** Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern. Hence, there are 2 subarrays in nums that match the pattern.
+
+**Constraints:**
+
+* 2 <= n == nums.length <= 106
+* 1 <= nums[i] <= 109
+* `1 <= m == pattern.length < n`
+* `-1 <= pattern[i] <= 1`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/Solution.java b/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/Solution.java
new file mode 100644
index 000000000..74e81585d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/Solution.java
@@ -0,0 +1,19 @@
+package g3001_3100.s3038_maximum_number_of_operations_with_the_same_score_i;
+
+// #Easy #Array #Simulation #2024_03_04_Time_0_ms_(100.00%)_Space_41.5_MB_(92.21%)
+
+public class Solution {
+ public int maxOperations(int[] nums) {
+ int c = 1;
+ for (int i = 2, s = nums[0] + nums[1], l = nums.length - (nums.length % 2 == 0 ? 0 : 1);
+ i < l;
+ i += 2) {
+ if (nums[i] + nums[i + 1] == s) {
+ c++;
+ } else {
+ break;
+ }
+ }
+ return c;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/readme.md b/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/readme.md
new file mode 100644
index 000000000..11b175c88
--- /dev/null
+++ b/src/main/java/g3001_3100/s3038_maximum_number_of_operations_with_the_same_score_i/readme.md
@@ -0,0 +1,41 @@
+3038\. Maximum Number of Operations With the Same Score I
+
+Easy
+
+Given an array of integers called `nums`, you can perform the following operation while `nums` contains **at least** `2` elements:
+
+* Choose the first two elements of `nums` and delete them.
+
+The **score** of the operation is the sum of the deleted elements.
+
+Your task is to find the **maximum** number of operations that can be performed, such that **all operations have the same score**.
+
+Return _the **maximum** number of operations possible that satisfy the condition mentioned above_.
+
+**Example 1:**
+
+**Input:** nums = [3,2,1,4,5]
+
+**Output:** 2
+
+**Explanation:** We perform the following operations:
+- Delete the first two elements, with score 3 + 2 = 5, nums = [1,4,5].
+- Delete the first two elements, with score 1 + 4 = 5, nums = [5].
+
+We are unable to perform any more operations as nums contain only 1 element.
+
+**Example 2:**
+
+**Input:** nums = [3,2,6,1,4]
+
+**Output:** 1
+
+**Explanation:** We perform the following operations:
+- Delete the first two elements, with score 3 + 2 = 5, nums = [6,1,4].
+
+We are unable to perform any more operations as the score of the next operation isn't the same as the previous one.
+
+**Constraints:**
+
+* `2 <= nums.length <= 100`
+* `1 <= nums[i] <= 1000`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.java b/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.java
new file mode 100644
index 000000000..4a521de37
--- /dev/null
+++ b/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.java
@@ -0,0 +1,25 @@
+package g3001_3100.s3039_apply_operations_to_make_string_empty;
+
+// #Medium #Array #Hash_Table #Sorting #Counting
+// #2024_03_04_Time_18_ms_(93.00%)_Space_48.3_MB_(94.05%)
+
+public class Solution {
+ public String lastNonEmptyString(String s) {
+ int[] freq = new int[26];
+ char[] ar = s.toCharArray();
+ int n = ar.length;
+ int max = 1;
+ StringBuilder sb = new StringBuilder();
+ for (char c : ar) {
+ freq[c - 'a']++;
+ max = Math.max(freq[c - 'a'], max);
+ }
+ for (int i = n - 1; i >= 0; i--) {
+ if (freq[ar[i] - 'a'] == max) {
+ sb.append(ar[i]);
+ freq[ar[i] - 'a'] = 0;
+ }
+ }
+ return sb.reverse().toString();
+ }
+}
diff --git a/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/readme.md b/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/readme.md
new file mode 100644
index 000000000..9d757a626
--- /dev/null
+++ b/src/main/java/g3001_3100/s3039_apply_operations_to_make_string_empty/readme.md
@@ -0,0 +1,41 @@
+3039\. Apply Operations to Make String Empty
+
+Medium
+
+You are given a string `s`.
+
+Consider performing the following operation until `s` becomes **empty**:
+
+* For **every** alphabet character from `'a'` to `'z'`, remove the **first** occurrence of that character in `s` (if it exists).
+
+For example, let initially `s = "aabcbbca"`. We do the following operations:
+
+* Remove the underlined characters s = "**a**a**bc**bbca". The resulting string is `s = "abbca"`.
+* Remove the underlined characters s = "**ab**b**c**a". The resulting string is `s = "ba"`.
+* Remove the underlined characters s = "**ba**". The resulting string is `s = ""`.
+
+Return _the value of the string_ `s` _right **before** applying the **last** operation_. In the example above, answer is `"ba"`.
+
+**Example 1:**
+
+**Input:** s = "aabcbbca"
+
+**Output:** "ba"
+
+**Explanation:** Explained in the statement.
+
+**Example 2:**
+
+**Input:** s = "abcd"
+
+**Output:** "abcd"
+
+**Explanation:** We do the following operation:
+- Remove the underlined characters s = "**abcd**". The resulting string is s = "".
+
+The string just before the last operation is "abcd".
+
+**Constraints:**
+
+* 1 <= s.length <= 5 * 105
+* `s` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/Solution.java b/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/Solution.java
new file mode 100644
index 000000000..232323c7d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/Solution.java
@@ -0,0 +1,84 @@
+package g3001_3100.s3040_maximum_number_of_operations_with_the_same_score_ii;
+
+// #Medium #Array #Dynamic_Programming #Memoization
+// #2024_03_04_Time_3_ms_(99.75%)_Space_44.6_MB_(99.29%)
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class Solution {
+ private int[] nums;
+
+ private int maxOps = 1;
+
+ private final Map dp = new HashMap<>();
+
+ private static class Pos {
+ int start;
+ int end;
+ int sum;
+
+ Pos(int start, int end, int sum) {
+ this.start = start;
+ this.end = end;
+ this.sum = sum;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+ if (!(o instanceof Pos)) {
+ return false;
+ }
+ return start == ((Pos) o).start && end == ((Pos) o).end && sum == ((Pos) o).sum;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(start, end, sum);
+ }
+ }
+
+ public int maxOperations(int[] nums) {
+ this.nums = nums;
+ var length = nums.length;
+
+ maxOperations(2, length - 1, nums[0] + nums[1], 1);
+ maxOperations(0, length - 3, nums[length - 2] + nums[length - 1], 1);
+ maxOperations(1, length - 2, nums[0] + nums[length - 1], 1);
+
+ return maxOps;
+ }
+
+ private void maxOperations(int start, int end, int sum, int nOps) {
+ if (start >= end) {
+ return;
+ }
+
+ if ((((end - start) / 2) + nOps) < maxOps) {
+ return;
+ }
+
+ Pos pos = new Pos(start, end, sum);
+ Integer posNops = dp.get(pos);
+ if (posNops != null && posNops >= nOps) {
+ return;
+ }
+ dp.put(pos, nOps);
+ if (nums[start] + nums[start + 1] == sum) {
+ maxOps = Math.max(maxOps, nOps + 1);
+ maxOperations(start + 2, end, sum, nOps + 1);
+ }
+ if (nums[end - 1] + nums[end] == sum) {
+ maxOps = Math.max(maxOps, nOps + 1);
+ maxOperations(start, end - 2, sum, nOps + 1);
+ }
+ if (nums[start] + nums[end] == sum) {
+ maxOps = Math.max(maxOps, nOps + 1);
+ maxOperations(start + 1, end - 1, sum, nOps + 1);
+ }
+ }
+}
diff --git a/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/readme.md b/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/readme.md
new file mode 100644
index 000000000..9efe7c931
--- /dev/null
+++ b/src/main/java/g3001_3100/s3040_maximum_number_of_operations_with_the_same_score_ii/readme.md
@@ -0,0 +1,45 @@
+3040\. Maximum Number of Operations With the Same Score II
+
+Medium
+
+Given an array of integers called `nums`, you can perform **any** of the following operation while `nums` contains **at least** `2` elements:
+
+* Choose the first two elements of `nums` and delete them.
+* Choose the last two elements of `nums` and delete them.
+* Choose the first and the last elements of `nums` and delete them.
+
+The **score** of the operation is the sum of the deleted elements.
+
+Your task is to find the **maximum** number of operations that can be performed, such that **all operations have the same score**.
+
+Return _the **maximum** number of operations possible that satisfy the condition mentioned above_.
+
+**Example 1:**
+
+**Input:** nums = [3,2,1,2,3,4]
+
+**Output:** 3
+
+**Explanation:** We perform the following operations:
+- Delete the first two elements, with score 3 + 2 = 5, nums = [1,2,3,4].
+- Delete the first and the last elements, with score 1 + 4 = 5, nums = [2,3].
+- Delete the first and the last elements, with score 2 + 3 = 5, nums = [].
+
+We are unable to perform any more operations as nums is empty.
+
+**Example 2:**
+
+**Input:** nums = [3,2,6,1,4]
+
+**Output:** 2
+
+**Explanation:** We perform the following operations:
+- Delete the first two elements, with score 3 + 2 = 5, nums = [6,1,4].
+- Delete the last two elements, with score 1 + 4 = 5, nums = [6].
+
+It can be proven that we can perform at most 2 operations.
+
+**Constraints:**
+
+* `2 <= nums.length <= 2000`
+* `1 <= nums[i] <= 1000`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/Solution.java b/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/Solution.java
new file mode 100644
index 000000000..1ab4dfb5a
--- /dev/null
+++ b/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/Solution.java
@@ -0,0 +1,37 @@
+package g3001_3100.s3041_maximize_consecutive_elements_in_an_array_after_modification;
+
+// #Hard #Array #Dynamic_Programming #Sorting
+// #2024_03_03_Time_13_ms_(100.00%)_Space_61.4_MB_(59.30%)
+
+public class Solution {
+ public int maxSelectedElements(int[] nums) {
+ int max = 0;
+ int min = Integer.MAX_VALUE;
+ for (int x : nums) {
+ max = Math.max(x, max);
+ min = Math.min(x, min);
+ }
+ int[] count = new int[max + 1];
+ for (int x : nums) {
+ ++count[x];
+ }
+ int[] dp = new int[max + 2];
+ int ans = 0;
+ for (int x = min; x <= max; ++x) {
+ if (count[x] == 0) {
+ continue;
+ }
+ int c = count[x];
+ if (c == 1) {
+ dp[x + 1] = dp[x] + 1;
+ dp[x] = dp[x - 1] + 1;
+ } else {
+ dp[x] = dp[x - 1] + 1;
+ dp[x + 1] = dp[x] + 1;
+ }
+ ans = Math.max(ans, dp[x]);
+ ans = Math.max(ans, dp[x + 1]);
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/readme.md b/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/readme.md
new file mode 100644
index 000000000..f8dccadd0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3041_maximize_consecutive_elements_in_an_array_after_modification/readme.md
@@ -0,0 +1,36 @@
+3041\. Maximize Consecutive Elements in an Array After Modification
+
+Hard
+
+You are given a **0-indexed** array `nums` consisting of **positive** integers.
+
+Initially, you can increase the value of **any** element in the array by **at most** `1`.
+
+After that, you need to select **one or more** elements from the final array such that those elements are **consecutive** when sorted in increasing order. For example, the elements `[3, 4, 5]` are consecutive while `[3, 4, 6]` and `[1, 1, 2, 3]` are not.
+
+Return _the **maximum** number of elements that you can select_.
+
+**Example 1:**
+
+**Input:** nums = [2,1,5,1,1]
+
+**Output:** 3
+
+**Explanation:** We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1].
+
+We select the elements [**3**,**1**,5,**2**,1] and we sort them to obtain [1,2,3], which are consecutive.
+
+It can be shown that we cannot select more than 3 consecutive elements.
+
+**Example 2:**
+
+**Input:** nums = [1,4,7,10]
+
+**Output:** 1
+
+**Explanation:** The maximum consecutive elements that we can select is 1.
+
+**Constraints:**
+
+* 1 <= nums.length <= 105
+* 1 <= nums[i] <= 106
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/Solution.java b/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/Solution.java
new file mode 100644
index 000000000..1f863d893
--- /dev/null
+++ b/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/Solution.java
@@ -0,0 +1,37 @@
+package g3001_3100.s3042_count_prefix_and_suffix_pairs_i;
+
+// #Easy #Array #String #Trie #Hash_Function #String_Matching #Rolling_Hash
+// #2024_02_29_Time_2_ms_(99.56%)_Space_42.3_MB_(49.99%)
+
+public class Solution {
+ public int countPrefixSuffixPairs(String[] words) {
+ int count = 0;
+ for (int i = 0; i < words.length; i++) {
+ for (int j = i + 1; j < words.length; j++) {
+ if (isPrefixAndSuffix(words[i], words[j])) {
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+
+ private boolean isPrefixAndSuffix(String str1, String str2) {
+ int m = str1.length();
+ int n = str2.length();
+ if (m > n) {
+ return false;
+ }
+ for (int i = 0; i < m; i++) {
+ if (str1.charAt(i) != str2.charAt(i)) {
+ return false;
+ }
+ }
+ for (int i = 0; i < m; i++) {
+ if (str1.charAt(i) != str2.charAt(n - m + i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/readme.md b/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/readme.md
new file mode 100644
index 000000000..40c60fbe0
--- /dev/null
+++ b/src/main/java/g3001_3100/s3042_count_prefix_and_suffix_pairs_i/readme.md
@@ -0,0 +1,61 @@
+3042\. Count Prefix and Suffix Pairs I
+
+Easy
+
+You are given a **0-indexed** string array `words`.
+
+Let's define a **boolean** function `isPrefixAndSuffix` that takes two strings, `str1` and `str2`:
+
+* `isPrefixAndSuffix(str1, str2)` returns `true` if `str1` is **both** a prefix and a suffix of `str2`, and `false` otherwise.
+
+For example, `isPrefixAndSuffix("aba", "ababa")` is `true` because `"aba"` is a prefix of `"ababa"` and also a suffix, but `isPrefixAndSuffix("abc", "abcd")` is `false`.
+
+Return _an integer denoting the **number** of index pairs_ `(i, j)` _such that_ `i < j`_, and_ `isPrefixAndSuffix(words[i], words[j])` _is_ `true`_._
+
+**Example 1:**
+
+**Input:** words = ["a","aba","ababa","aa"]
+
+**Output:** 4
+
+**Explanation:** In this example, the counted index pairs are:
+
+i = 0 and j = 1 because isPrefixAndSuffix("a", "aba") is true.
+
+i = 0 and j = 2 because isPrefixAndSuffix("a", "ababa") is true.
+
+i = 0 and j = 3 because isPrefixAndSuffix("a", "aa") is true.
+
+i = 1 and j = 2 because isPrefixAndSuffix("aba", "ababa") is true.
+
+Therefore, the answer is 4.
+
+**Example 2:**
+
+**Input:** words = ["pa","papa","ma","mama"]
+
+**Output:** 2
+
+**Explanation:** In this example, the counted index pairs are:
+
+i = 0 and j = 1 because isPrefixAndSuffix("pa", "papa") is true.
+
+i = 2 and j = 3 because isPrefixAndSuffix("ma", "mama") is true.
+
+Therefore, the answer is 2.
+
+**Example 3:**
+
+**Input:** words = ["abab","ab"]
+
+**Output:** 0
+
+**Explanation:** In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix("abab", "ab") is false.
+
+Therefore, the answer is 0.
+
+**Constraints:**
+
+* `1 <= words.length <= 50`
+* `1 <= words[i].length <= 10`
+* `words[i]` consists only of lowercase English letters.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/Solution.java b/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/Solution.java
new file mode 100644
index 000000000..d0cb5d1cd
--- /dev/null
+++ b/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/Solution.java
@@ -0,0 +1,64 @@
+package g3001_3100.s3043_find_the_length_of_the_longest_common_prefix;
+
+// #Medium #Array #String #Hash_Table #Trie #2024_02_29_Time_27_ms_(99.94%)_Space_55.6_MB_(78.30%)
+
+public class Solution {
+ public int longestCommonPrefix(int[] arr1, int[] arr2) {
+ Trie trie = new Trie();
+ for (int num : arr2) {
+ trie.addWord(String.valueOf(num));
+ }
+ int longest = 0;
+ String val;
+ for (int num : arr1) {
+ val = String.valueOf(num);
+ if (val.length() > longest) {
+ longest = Math.max(longest, trie.findLongestPrefix(val));
+ }
+ }
+ return longest;
+ }
+
+ private static class Trie {
+ TrieNode root;
+
+ public Trie() {
+ root = new TrieNode();
+ }
+
+ public void addWord(String word) {
+ TrieNode first = root;
+ int codePoint;
+ for (int i = 0; i < word.length(); i++) {
+ codePoint = word.charAt(i) - '0';
+ if (first.nodes[codePoint] == null) {
+ first.nodes[codePoint] = new TrieNode();
+ }
+ first = first.nodes[codePoint];
+ }
+ }
+
+ public int findLongestPrefix(String word) {
+ TrieNode first = root;
+ int i = 0;
+ int codePoint;
+ while (i < word.length()) {
+ codePoint = word.charAt(i) - '0';
+ if (first.nodes[codePoint] == null) {
+ return i;
+ }
+ first = first.nodes[codePoint];
+ i++;
+ }
+ return i;
+ }
+ }
+
+ private static class TrieNode {
+ TrieNode[] nodes;
+
+ public TrieNode() {
+ nodes = new TrieNode[10];
+ }
+ }
+}
diff --git a/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/readme.md b/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/readme.md
new file mode 100644
index 000000000..e65d9a4d3
--- /dev/null
+++ b/src/main/java/g3001_3100/s3043_find_the_length_of_the_longest_common_prefix/readme.md
@@ -0,0 +1,44 @@
+3043\. Find the Length of the Longest Common Prefix
+
+Medium
+
+You are given two arrays with **positive** integers `arr1` and `arr2`.
+
+A **prefix** of a positive integer is an integer formed by one or more of its digits, starting from its **leftmost** digit. For example, `123` is a prefix of the integer `12345`, while `234` is **not**.
+
+A **common prefix** of two integers `a` and `b` is an integer `c`, such that `c` is a prefix of both `a` and `b`. For example, `5655359` and `56554` have a common prefix `565` while `1223` and `43456` **do not** have a common prefix.
+
+You need to find the length of the **longest common prefix** between all pairs of integers `(x, y)` such that `x` belongs to `arr1` and `y` belongs to `arr2`.
+
+Return _the length of the **longest** common prefix among all pairs_. _If no common prefix exists among them_, _return_ `0`.
+
+**Example 1:**
+
+**Input:** arr1 = [1,10,100], arr2 = [1000]
+
+**Output:** 3
+
+**Explanation:** There are 3 pairs (arr1[i], arr2[j]):
+
+- The longest common prefix of (1, 1000) is 1.
+
+- The longest common prefix of (10, 1000) is 10.
+
+- The longest common prefix of (100, 1000) is 100.
+
+The longest common prefix is 100 with a length of 3.
+
+**Example 2:**
+
+**Input:** arr1 = [1,2,3], arr2 = [4,4,4]
+
+**Output:** 0
+
+**Explanation:** There exists no common prefix for any pair (arr1[i], arr2[j]), hence we return 0.
+
+Note that common prefixes between elements of the same array do not count.
+
+**Constraints:**
+
+* 1 <= arr1.length, arr2.length <= 5 * 104
+* 1 <= arr1[i], arr2[i] <= 108
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3044_most_frequent_prime/Solution.java b/src/main/java/g3001_3100/s3044_most_frequent_prime/Solution.java
new file mode 100644
index 000000000..434b5f45c
--- /dev/null
+++ b/src/main/java/g3001_3100/s3044_most_frequent_prime/Solution.java
@@ -0,0 +1,63 @@
+package g3001_3100.s3044_most_frequent_prime;
+
+// #Medium #Array #Hash_Table #Math #Matrix #Counting #Enumeration #Number_Theory
+// #2024_02_29_Time_6_ms_(100.00%)_Space_43.6_MB_(97.08%)
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Solution {
+ private int max = 0;
+ private int freqNum = -1;
+
+ public int mostFrequentPrime(int[][] mat) {
+ int[][] nexts =
+ new int[][] {{1, 1}, {-1, -1}, {1, -1}, {-1, 1}, {0, 1}, {0, -1}, {1, 0}, {-1, 0}};
+ int m = mat.length;
+ int n = mat[0].length;
+ Map primeFreq = new HashMap<>();
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ for (int[] next : nexts) {
+ getPrime(i, j, mat, 0, next, primeFreq);
+ }
+ }
+ }
+ return freqNum;
+ }
+
+ private void getPrime(
+ int i, int j, int[][] mat, int num, int[] next, Map primeFreq) {
+ int m = mat.length;
+ int n = mat[0].length;
+ if (i < 0 || j < 0 || i == m || j == n) {
+ return;
+ }
+ num = num * 10 + mat[i][j];
+ if (num > 10 && isPrime(num)) {
+ int count = primeFreq.getOrDefault(num, 0) + 1;
+ if ((count == max && freqNum < num) || count > max) {
+ freqNum = num;
+ }
+ max = Math.max(max, count);
+ primeFreq.put(num, count);
+ }
+ getPrime(i + next[0], j + next[1], mat, num, next, primeFreq);
+ }
+
+ private boolean isPrime(int num) {
+ if (num == 2) {
+ return true;
+ }
+ if (num == 1 || (num & 1) == 0) {
+ return false;
+ }
+ int n = (int) Math.sqrt(num);
+ for (int i = 3; i <= n; i += 2) {
+ if ((num % i) == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3044_most_frequent_prime/readme.md b/src/main/java/g3001_3100/s3044_most_frequent_prime/readme.md
new file mode 100644
index 000000000..accac0e0b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3044_most_frequent_prime/readme.md
@@ -0,0 +1,82 @@
+3044\. Most Frequent Prime
+
+Medium
+
+You are given a `m x n` **0-indexed** 2D matrix `mat`. From every cell, you can create numbers in the following way:
+
+* There could be at most `8` paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.
+* Select a path from them and append digits in this path to the number being formed by traveling in this direction.
+* Note that numbers are generated at every step, for example, if the digits along the path are `1, 9, 1`, then there will be three numbers generated along the way: `1, 19, 191`.
+
+Return _the most frequent prime number **greater** than_ `10` _out of all the numbers created by traversing the matrix or_ `-1` _if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the **largest** among them._
+
+**Note:** It is invalid to change the direction during the move.
+
+**Example 1:**
+
+ ****
+
+ **Input:** mat = [[1,1],[9,9],[1,1]]
+
+**Output:** 19
+
+**Explanation:**
+
+From cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are:
+
+East: [11], South-East: [19], South: [19,191].
+
+Numbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11].
+
+Numbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91].
+
+Numbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91].
+
+Numbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19].
+
+Numbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191].
+
+The most frequent prime number among all the created numbers is 19.
+
+**Example 2:**
+
+**Input:** mat = [[7]]
+
+**Output:** -1
+
+**Explanation:** The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1.
+
+**Example 3:**
+
+**Input:** mat = [[9,7,8],[4,6,5],[2,8,6]]
+
+**Output:** 97
+
+**Explanation:**
+
+Numbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942].
+
+Numbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79].
+
+Numbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879].
+
+Numbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47].
+
+Numbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68].
+
+Numbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58].
+
+Numbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268].
+
+Numbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85].
+
+Numbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658].
+
+The most frequent prime number among all the created numbers is 97.
+
+**Constraints:**
+
+* `m == mat.length`
+* `n == mat[i].length`
+* `1 <= m, n <= 6`
+* `1 <= mat[i][j] <= 9`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/Solution.java b/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/Solution.java
new file mode 100644
index 000000000..e8f8b9b38
--- /dev/null
+++ b/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/Solution.java
@@ -0,0 +1,28 @@
+package g3001_3100.s3045_count_prefix_and_suffix_pairs_ii;
+
+// #Hard #Array #String #Trie #Hash_Function #String_Matching #Rolling_Hash
+// #2024_02_29_Time_19_ms_(100.00%)_Space_55.7_MB_(94.24%)
+
+public class Solution {
+ public long countPrefixSuffixPairs(String[] words) {
+ long ans = 0;
+ boolean[] visited = new boolean[words.length];
+ for (int i = 0; i < words.length; i++) {
+ String p = words[i];
+ if (!visited[i]) {
+ int found = 1;
+ for (int j = i + 1; j < words.length; j++) {
+ String s = words[j];
+ if (s.length() >= p.length() && s.startsWith(p) && s.endsWith(p)) {
+ ans += found;
+ }
+ if (p.equals(s)) {
+ found++;
+ visited[j] = true;
+ }
+ }
+ }
+ }
+ return ans;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/readme.md b/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/readme.md
new file mode 100644
index 000000000..99d5adb1e
--- /dev/null
+++ b/src/main/java/g3001_3100/s3045_count_prefix_and_suffix_pairs_ii/readme.md
@@ -0,0 +1,62 @@
+3045\. Count Prefix and Suffix Pairs II
+
+Hard
+
+You are given a **0-indexed** string array `words`.
+
+Let's define a **boolean** function `isPrefixAndSuffix` that takes two strings, `str1` and `str2`:
+
+* `isPrefixAndSuffix(str1, str2)` returns `true` if `str1` is **both** a prefix and a suffix of `str2`, and `false` otherwise.
+
+For example, `isPrefixAndSuffix("aba", "ababa")` is `true` because `"aba"` is a prefix of `"ababa"` and also a suffix, but `isPrefixAndSuffix("abc", "abcd")` is `false`.
+
+Return _an integer denoting the **number** of index pairs_ `(i_,_ j)` _such that_ `i < j`_, and_ `isPrefixAndSuffix(words[i], words[j])` _is_ `true`_._
+
+**Example 1:**
+
+**Input:** words = ["a","aba","ababa","aa"]
+
+**Output:** 4
+
+**Explanation:** In this example, the counted index pairs are:
+
+i = 0 and j = 1 because isPrefixAndSuffix("a", "aba") is true.
+
+i = 0 and j = 2 because isPrefixAndSuffix("a", "ababa") is true.
+
+i = 0 and j = 3 because isPrefixAndSuffix("a", "aa") is true.
+
+i = 1 and j = 2 because isPrefixAndSuffix("aba", "ababa") is true.
+
+Therefore, the answer is 4.
+
+**Example 2:**
+
+**Input:** words = ["pa","papa","ma","mama"]
+
+**Output:** 2
+
+**Explanation:** In this example, the counted index pairs are:
+
+i = 0 and j = 1 because isPrefixAndSuffix("pa", "papa") is true.
+
+i = 2 and j = 3 because isPrefixAndSuffix("ma", "mama") is true.
+
+Therefore, the answer is 2.
+
+**Example 3:**
+
+**Input:** words = ["abab","ab"]
+
+**Output:** 0
+
+**Explanation:** In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix("abab", "ab") is false.
+
+Therefore, the answer is 0.
+
+**Constraints:**
+
+* 1 <= words.length <= 105
+* 1 <= words[i].length <= 105
+* `words[i]` consists only of lowercase English letters.
+* The sum of the lengths of all `words[i]` does not exceed 5 * 105.
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3046_split_the_array/Solution.java b/src/main/java/g3001_3100/s3046_split_the_array/Solution.java
new file mode 100644
index 000000000..39bcd153d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3046_split_the_array/Solution.java
@@ -0,0 +1,16 @@
+package g3001_3100.s3046_split_the_array;
+
+// #Easy #Array #Hash_Table #Counting #2024_02_29_Time_1_ms_(98.82%)_Space_42.8_MB_(63.55%)
+
+public class Solution {
+ public boolean isPossibleToSplit(int[] nums) {
+ int[] a = new int[101];
+ for (int n : nums) {
+ a[n]++;
+ if (a[n] > 2) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3046_split_the_array/readme.md b/src/main/java/g3001_3100/s3046_split_the_array/readme.md
new file mode 100644
index 000000000..64af2cd35
--- /dev/null
+++ b/src/main/java/g3001_3100/s3046_split_the_array/readme.md
@@ -0,0 +1,33 @@
+3046\. Split the Array
+
+Easy
+
+You are given an integer array `nums` of **even** length. You have to split the array into two parts `nums1` and `nums2` such that:
+
+* `nums1.length == nums2.length == nums.length / 2`.
+* `nums1` should contain **distinct** elements.
+* `nums2` should also contain **distinct** elements.
+
+Return `true` _if it is possible to split the array, and_ `false` _otherwise__._
+
+**Example 1:**
+
+**Input:** nums = [1,1,2,2,3,4]
+
+**Output:** true
+
+**Explanation:** One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].
+
+**Example 2:**
+
+**Input:** nums = [1,1,1,1]
+
+**Output:** false
+
+**Explanation:** The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.
+
+**Constraints:**
+
+* `1 <= nums.length <= 100`
+* `nums.length % 2 == 0`
+* `1 <= nums[i] <= 100`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/Solution.java b/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/Solution.java
new file mode 100644
index 000000000..eea7995a5
--- /dev/null
+++ b/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/Solution.java
@@ -0,0 +1,30 @@
+package g3001_3100.s3047_find_the_largest_area_of_square_inside_two_rectangles;
+
+// #Medium #Array #Math #Geometry #2024_03_04_Time_50_ms_(97.63%)_Space_44.7_MB_(98.11%)
+
+public class Solution {
+ public long largestSquareArea(int[][] bottomLeft, int[][] topRight) {
+ int n = bottomLeft.length;
+ long maxArea = 0;
+ for (int i = 0; i < n; i++) {
+ int ax = bottomLeft[i][0];
+ int ay = bottomLeft[i][1];
+ int bx = topRight[i][0];
+ int by = topRight[i][1];
+ for (int j = i + 1; j < n; j++) {
+ int cx = bottomLeft[j][0];
+ int cy = bottomLeft[j][1];
+ int dx = topRight[j][0];
+ int dy = topRight[j][1];
+ int x1 = Math.max(ax, cx);
+ int y1 = Math.max(ay, cy);
+ int x2 = Math.min(bx, dx);
+ int y2 = Math.min(by, dy);
+ int minSide = Math.min(x2 - x1, y2 - y1);
+ long area = (long) Math.pow(Math.max(minSide, 0), 2);
+ maxArea = Math.max(maxArea, area);
+ }
+ }
+ return maxArea;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/readme.md b/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/readme.md
new file mode 100644
index 000000000..b37d2a4a7
--- /dev/null
+++ b/src/main/java/g3001_3100/s3047_find_the_largest_area_of_square_inside_two_rectangles/readme.md
@@ -0,0 +1,53 @@
+3047\. Find the Largest Area of Square Inside Two Rectangles
+
+Medium
+
+There exist `n` rectangles in a 2D plane. You are given two **0-indexed** 2D integer arrays `bottomLeft` and `topRight`, both of size `n x 2`, where `bottomLeft[i]` and `topRight[i]` represent the **bottom-left** and **top-right** coordinates of the ith rectangle respectively.
+
+You can select a region formed from the **intersection** of two of the given rectangles. You need to find the **largest** area of a **square** that can fit **inside** this region if you select the region optimally.
+
+Return _the **largest** possible area of a square, or_ `0` _if there **do not** exist any intersecting regions between the rectangles_.
+
+**Example 1:**
+
+
+
+**Input:** bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]]
+
+**Output:** 1
+
+**Explanation:** A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, or the intersecting region of rectangle 1 and rectangle 2. Hence the largest area is side \* side which is 1 \* 1 == 1.
+
+It can be shown that a square with a greater side length can not fit inside any intersecting region.
+
+**Example 2:**
+
+
+
+**Input:** bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]]
+
+**Output:** 1
+
+**Explanation:** A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, the intersecting region of rectangle 1 and rectangle 2, or the intersection region of all 3 rectangles. Hence the largest area is side \* side which is 1 \* 1 == 1.
+
+It can be shown that a square with a greater side length can not fit inside any intersecting region. Note that the region can be formed by the intersection of more than 2 rectangles.
+
+**Example 3:**
+
+
+
+**Input:** bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]]
+
+**Output:** 0
+
+**Explanation:** No pair of rectangles intersect, hence, we return 0.
+
+**Constraints:**
+
+* `n == bottomLeft.length == topRight.length`
+* 2 <= n <= 103
+* `bottomLeft[i].length == topRight[i].length == 2`
+* 1 <= bottomLeft[i][0], bottomLeft[i][1] <= 107
+* 1 <= topRight[i][0], topRight[i][1] <= 107
+* `bottomLeft[i][0] < topRight[i][0]`
+* `bottomLeft[i][1] < topRight[i][1]`
diff --git a/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/Solution.java b/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/Solution.java
new file mode 100644
index 000000000..5c6abbd9d
--- /dev/null
+++ b/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/Solution.java
@@ -0,0 +1,52 @@
+package g3001_3100.s3048_earliest_second_to_mark_indices_i;
+
+// #Medium #Array #Binary_Search #2024_03_04_Time_2_ms_(91.18%)_Space_44.6_MB_(92.63%)
+
+import java.util.Arrays;
+
+public class Solution {
+ public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {
+ int n = nums.length;
+ if (nums.length == 0 || changeIndices.length == 0) {
+ return 0;
+ }
+ int[] last = new int[n];
+ Arrays.fill(last, -1);
+ for (int i = 0; i < changeIndices.length; i++) {
+ changeIndices[i] -= 1;
+ }
+ int low = 0;
+ int high = changeIndices.length - 1;
+ while (low < high) {
+ int mid = low + (high - low) / 2;
+ if (isPossible(mid, nums, changeIndices, last)) {
+ high = mid;
+ } else {
+ low = mid + 1;
+ }
+ }
+ return isPossible(low, nums, changeIndices, last) ? low + 1 : -1;
+ }
+
+ private boolean isPossible(int s, int[] nums, int[] changeIndices, int[] last) {
+ int n = nums.length;
+ Arrays.fill(last, -1);
+ for (int i = 0; i <= s; i++) {
+ last[changeIndices[i]] = i;
+ }
+ int marked = 0;
+ int operations = 0;
+ for (int i = 0; i <= s; i++) {
+ if (i == last[changeIndices[i]]) {
+ if (nums[changeIndices[i]] > operations) {
+ return false;
+ }
+ operations -= nums[changeIndices[i]];
+ marked++;
+ } else {
+ operations++;
+ }
+ }
+ return marked == n;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/readme.md b/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/readme.md
new file mode 100644
index 000000000..8727300be
--- /dev/null
+++ b/src/main/java/g3001_3100/s3048_earliest_second_to_mark_indices_i/readme.md
@@ -0,0 +1,86 @@
+3048\. Earliest Second to Mark Indices I
+
+Medium
+
+You are given two **1-indexed** integer arrays, `nums` and, `changeIndices`, having lengths `n` and `m`, respectively.
+
+Initially, all indices in `nums` are unmarked. Your task is to mark **all** indices in `nums`.
+
+In each second, `s`, in order from `1` to `m` (**inclusive**), you can perform **one** of the following operations:
+
+* Choose an index `i` in the range `[1, n]` and **decrement** `nums[i]` by `1`.
+* If `nums[changeIndices[s]]` is **equal** to `0`, **mark** the index `changeIndices[s]`.
+* Do nothing.
+
+Return _an integer denoting the **earliest second** in the range_ `[1, m]` _when **all** indices in_ `nums` _can be marked by choosing operations optimally, or_ `-1` _if it is impossible._
+
+**Example 1:**
+
+**Input:** nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]
+
+**Output:** 8
+
+**Explanation:** In this example, we have 8 seconds. The following operations can be performed to mark all indices:
+
+Second 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].
+
+Second 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].
+
+Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].
+
+Second 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].
+
+Second 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.
+
+Second 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.
+
+Second 7: Do nothing.
+
+Second 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] is equal to 0.
+
+Now all indices have been marked.
+
+It can be shown that it is not possible to mark all indices earlier than the 8th second.
+
+Hence, the answer is 8.
+
+**Example 2:**
+
+**Input:** nums = [1,3], changeIndices = [1,1,1,2,1,1,1]
+
+**Output:** 6
+
+**Explanation:** In this example, we have 7 seconds. The following operations can be performed to mark all indices:
+
+Second 1: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].
+
+Second 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].
+
+Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].
+
+Second 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.
+
+Second 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].
+
+Second 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] is equal to 0.
+
+Now all indices have been marked.
+
+It can be shown that it is not possible to mark all indices earlier than the 6th second.
+
+Hence, the answer is 6.
+
+**Example 3:**
+
+**Input:** nums = [0,1], changeIndices = [2,2,2]
+
+**Output:** -1
+
+**Explanation:** In this example, it is impossible to mark all indices because index 1 isn't in changeIndices. Hence, the answer is -1.
+
+**Constraints:**
+
+* `1 <= n == nums.length <= 2000`
+* 0 <= nums[i] <= 109
+* `1 <= m == changeIndices.length <= 2000`
+* `1 <= changeIndices[i] <= n`
\ No newline at end of file
diff --git a/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/Solution.java b/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/Solution.java
new file mode 100644
index 000000000..3b0bd885b
--- /dev/null
+++ b/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/Solution.java
@@ -0,0 +1,67 @@
+package g3001_3100.s3049_earliest_second_to_mark_indices_ii;
+
+// #Hard #Array #Greedy #Binary_Search #Heap_Priority_Queue
+// #2024_03_04_Time_5_ms_(92.03%)_Space_44.5_MB_(91.30%)
+
+import java.util.HashSet;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.Set;
+
+public class Solution {
+ private int[] nums;
+ private int[] changeIndices;
+ private boolean[] first;
+ private long sum;
+
+ public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {
+ int m = changeIndices.length;
+ int n = nums.length;
+ if (m < n) {
+ return -1;
+ }
+ this.nums = nums;
+ this.changeIndices = changeIndices;
+ Set set = new HashSet<>();
+ first = new boolean[m];
+ for (int i = 0; i < m; i++) {
+ if (nums[changeIndices[i] - 1] > 1 && set.add(changeIndices[i])) {
+ first[i] = true;
+ }
+ }
+ for (int num : nums) {
+ sum += num;
+ }
+ sum += n;
+ int l = n;
+ int r = ((int) Math.min(sum, m)) + 1;
+ while (l < r) {
+ int mid = (l + r) / 2;
+ if (check(mid)) {
+ r = mid;
+ } else {
+ l = mid + 1;
+ }
+ }
+ return l > Math.min(sum, m) ? -1 : l;
+ }
+
+ private boolean check(int idx) {
+ Queue pq = new PriorityQueue<>();
+ long need = sum;
+ int count = 0;
+ for (int i = idx - 1; i >= 0 && need > idx; i--) {
+ if (!first[i]) {
+ count++;
+ continue;
+ }
+ pq.add(nums[changeIndices[i] - 1]);
+ need -= nums[changeIndices[i] - 1] - 1;
+ if (pq.size() > count) {
+ need += pq.poll() - 1;
+ count++;
+ }
+ }
+ return need <= idx;
+ }
+}
diff --git a/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/readme.md b/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/readme.md
new file mode 100644
index 000000000..e70bf2481
--- /dev/null
+++ b/src/main/java/g3001_3100/s3049_earliest_second_to_mark_indices_ii/readme.md
@@ -0,0 +1,85 @@
+3049\. Earliest Second to Mark Indices II
+
+Hard
+
+You are given two **1-indexed** integer arrays, `nums` and, `changeIndices`, having lengths `n` and `m`, respectively.
+
+Initially, all indices in `nums` are unmarked. Your task is to mark **all** indices in `nums`.
+
+In each second, `s`, in order from `1` to `m` (**inclusive**), you can perform **one** of the following operations:
+
+* Choose an index `i` in the range `[1, n]` and **decrement** `nums[i]` by `1`.
+* Set `nums[changeIndices[s]]` to any **non-negative** value.
+* Choose an index `i` in the range `[1, n]`, where `nums[i]` is **equal** to `0`, and **mark** index `i`.
+* Do nothing.
+
+Return _an integer denoting the **earliest second** in the range_ `[1, m]` _when **all** indices in_ `nums` _can be marked by choosing operations optimally, or_ `-1` _if it is impossible._
+
+**Example 1:**
+
+**Input:** nums = [3,2,3], changeIndices = [1,3,2,2,2,2,3]
+
+**Output:** 6
+
+**Explanation:** In this example, we have 7 seconds. The following operations can be performed to mark all indices:
+
+Second 1: Set nums[changeIndices[1]] to 0. nums becomes [0,2,3].
+
+Second 2: Set nums[changeIndices[2]] to 0. nums becomes [0,2,0].
+
+Second 3: Set nums[changeIndices[3]] to 0. nums becomes [0,0,0].
+
+Second 4: Mark index 1, since nums[1] is equal to 0.
+
+Second 5: Mark index 2, since nums[2] is equal to 0.
+
+Second 6: Mark index 3, since nums[3] is equal to 0.
+
+Now all indices have been marked.
+
+It can be shown that it is not possible to mark all indices earlier than the 6th second.
+
+Hence, the answer is 6.
+
+**Example 2:**
+
+**Input:** nums = [0,0,1,2], changeIndices = [1,2,1,2,1,2,1,2]
+
+**Output:** 7
+
+**Explanation:** In this example, we have 8 seconds. The following operations can be performed to mark all indices:
+
+Second 1: Mark index 1, since nums[1] is equal to 0.
+
+Second 2: Mark index 2, since nums[2] is equal to 0.
+
+Second 3: Decrement index 4 by one. nums becomes [0,0,1,1].
+
+Second 4: Decrement index 4 by one. nums becomes [0,0,1,0].
+
+Second 5: Decrement index 3 by one. nums becomes [0,0,0,0].
+
+Second 6: Mark index 3, since nums[3] is equal to 0.
+
+Second 7: Mark index 4, since nums[4] is equal to 0.
+
+Now all indices have been marked.
+
+It can be shown that it is not possible to mark all indices earlier than the 7th second.
+
+Hence, the answer is 7.
+
+**Example 3:**
+
+**Input:** nums = [1,2,3], changeIndices = [1,2,3]
+
+**Output:** -1
+
+**Explanation:** In this example, it can be shown that it is impossible to mark all indices, as we don't have enough seconds. Hence, the answer is -1.
+
+**Constraints:**
+
+* `1 <= n == nums.length <= 5000`
+*